Skip to content

Commit 1a280dd

Browse files
n132Paolo Abeni
authored andcommitted
net/sched: cls_flow: fix NULL pointer dereference on shared blocks
flow_change() calls tcf_block_q() and dereferences q->handle to derive a default baseclass. Shared blocks leave block->q NULL, causing a NULL deref when a flow filter without a fully qualified baseclass is created on a shared block. Check tcf_block_shared() before accessing block->q and return -EINVAL for shared blocks. This avoids the null-deref shown below: ======================================================================= KASAN: null-ptr-deref in range [0x0000000000000038-0x000000000000003f] RIP: 0010:flow_change (net/sched/cls_flow.c:508) Call Trace: tc_new_tfilter (net/sched/cls_api.c:2432) rtnetlink_rcv_msg (net/core/rtnetlink.c:6980) [...] ======================================================================= Fixes: 1abf272 ("net: sched: tcindex, fw, flow: use tcf_block_q helper to get struct Qdisc") Reported-by: Weiming Shi <[email protected]> Signed-off-by: Xiang Mei <[email protected]> Acked-by: Jamal Hadi Salim <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent faeea8b commit 1a280dd

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

net/sched/cls_flow.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,16 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
503503
}
504504

505505
if (TC_H_MAJ(baseclass) == 0) {
506-
struct Qdisc *q = tcf_block_q(tp->chain->block);
506+
struct tcf_block *block = tp->chain->block;
507+
struct Qdisc *q;
507508

509+
if (tcf_block_shared(block)) {
510+
NL_SET_ERR_MSG(extack,
511+
"Must specify baseclass when attaching flow filter to block");
512+
goto err2;
513+
}
514+
515+
q = tcf_block_q(block);
508516
baseclass = TC_H_MAKE(q->handle, baseclass);
509517
}
510518
if (TC_H_MIN(baseclass) == 0)

0 commit comments

Comments
 (0)