Skip to content

Commit d64cb81

Browse files
sparkfadekuba-moo
authored andcommitted
net/sched: sch_netem: fix out-of-bounds access in packet corruption
In netem_enqueue(), the packet corruption logic uses get_random_u32_below(skb_headlen(skb)) to select an index for modifying skb->data. When an AF_PACKET TX_RING sends fully non-linear packets over an IPIP tunnel, skb_headlen(skb) evaluates to 0. Passing 0 to get_random_u32_below() takes the variable-ceil slow path which returns an unconstrained 32-bit random integer. Using this unconstrained value as an offset into skb->data results in an out-of-bounds memory access. Fix this by verifying skb_headlen(skb) is non-zero before attempting to corrupt the linear data area. Fully non-linear packets will silently bypass the corruption logic. Fixes: c865e5d ("[PKT_SCHED] netem: packet corruption option") Reported-by: Yifan Wu <[email protected]> Reported-by: Juefei Pu <[email protected]> Signed-off-by: Yuan Tan <[email protected]> Signed-off-by: Xin Liu <[email protected]> Signed-off-by: Yuhang Zheng <[email protected]> Signed-off-by: Yucheng Lu <[email protected]> Reviewed-by: Stephen Hemminger <[email protected]> Link: https://patch.msgid.link/45435c0935df877853a81e6d06205ac738ec65fa.1774941614.git.kanolyc@gmail.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent aba53cc commit d64cb81

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

net/sched/sch_netem.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,9 @@ static int netem_enqueue(struct sk_buff *skb, struct Qdisc *sch,
519519
goto finish_segs;
520520
}
521521

522-
skb->data[get_random_u32_below(skb_headlen(skb))] ^=
523-
1<<get_random_u32_below(8);
522+
if (skb_headlen(skb))
523+
skb->data[get_random_u32_below(skb_headlen(skb))] ^=
524+
1 << get_random_u32_below(8);
524525
}
525526

526527
if (unlikely(q->t_len >= sch->limit)) {

0 commit comments

Comments
 (0)