Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: prevent user from passing illegal stab size

We observed below report when playing with netlink sock:

UBSAN: shift-out-of-bounds in net/sched/sch_api.c:580:10
shift exponent 249 is too large for 32-bit type
CPU: 0 PID: 685 Comm: a.out Not tainted
Call Trace:
dump_stack_lvl+0x8d/0xcf
ubsan_epilogue+0xa/0x4e
__ubsan_handle_shift_out_of_bounds+0x161/0x182
__qdisc_calculate_pkt_len+0xf0/0x190
__dev_queue_xmit+0x2ed/0x15b0

it seems like kernel won't check the stab log value passing from
user, and will use the insane value later to calculate pkt_len.

This patch just add a check on the size/cell_log to avoid insane
calculation.

Reported-by: Abaci <abaci@linux.alibaba.com>
Signed-off-by: Michael Wang <yun.wang@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

王贇 and committed by
David S. Miller
b193e15a 7fe7f318

+7
+1
include/net/pkt_sched.h
··· 11 11 #include <uapi/linux/pkt_sched.h> 12 12 13 13 #define DEFAULT_TX_QUEUE_LEN 1000 14 + #define STAB_SIZE_LOG_MAX 30 14 15 15 16 struct qdisc_walker { 16 17 int stop;
+6
net/sched/sch_api.c
··· 513 513 return stab; 514 514 } 515 515 516 + if (s->size_log > STAB_SIZE_LOG_MAX || 517 + s->cell_log > STAB_SIZE_LOG_MAX) { 518 + NL_SET_ERR_MSG(extack, "Invalid logarithmic size of size table"); 519 + return ERR_PTR(-EINVAL); 520 + } 521 + 516 522 stab = kmalloc(sizeof(*stab) + tsize * sizeof(u16), GFP_KERNEL); 517 523 if (!stab) 518 524 return ERR_PTR(-ENOMEM);