Skip to content

Commit d3fa76e

Browse files
kaberDavid S. Miller
authored andcommitted
[NET_SCHED]: cls_basic: fix NULL pointer dereference
cls_basic doesn't allocate tp->root before it is linked into the active classifier list, resulting in a NULL pointer dereference when packets hit the classifier before its ->change function is called. Reported by Chris Madden <chris@reflexsecurity.com> Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c93a882 commit d3fa76e

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

‎net/sched/cls_basic.c‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ static void basic_put(struct tcf_proto *tp, unsigned long f)
8181

8282
static int basic_init(struct tcf_proto *tp)
8383
{
84+
struct basic_head *head;
85+
86+
head = kzalloc(sizeof(*head), GFP_KERNEL);
87+
if (head == NULL)
88+
return -ENOBUFS;
89+
INIT_LIST_HEAD(&head->flist);
90+
tp->root = head;
8491
return 0;
8592
}
8693

@@ -176,15 +183,6 @@ static int basic_change(struct tcf_proto *tp, unsigned long base, u32 handle,
176183
}
177184

178185
err = -ENOBUFS;
179-
if (head == NULL) {
180-
head = kzalloc(sizeof(*head), GFP_KERNEL);
181-
if (head == NULL)
182-
goto errout;
183-
184-
INIT_LIST_HEAD(&head->flist);
185-
tp->root = head;
186-
}
187-
188186
f = kzalloc(sizeof(*f), GFP_KERNEL);
189187
if (f == NULL)
190188
goto errout;

0 commit comments

Comments
 (0)