The meta ematch stores the shift values from the userspace-supplied header without any validation. When a packet is classified, meta_int_apply_extras() shifts an unsigned long by that value, so a shift of 64 or more is undefined behaviour and triggers a UBSAN shift-out-of-bounds splat. Reject such configurations in em_meta_change(): if either value is of INT type and its shift is >= BITS_PER_LONG, fail with -EINVAL so the invalid filter is never created. Reproduced with the syzbot C reproducer: UBSAN splat before this change, clean run after. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: syzbot+7721fa414292e0f5af61@syzkaller.appspotmail.com Cc: stable@vger.kernel.org Signed-off-by: yealux --- net/sched/em_meta.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/sched/em_meta.c b/net/sched/em_meta.c index 48bdd77df..608b78c9a 100644 --- a/net/sched/em_meta.c +++ b/net/sched/em_meta.c @@ -936,6 +936,11 @@ static int em_meta_change(struct net *net, void *data, int len, memcpy(&meta->lvalue.hdr, &hdr->left, sizeof(hdr->left)); memcpy(&meta->rvalue.hdr, &hdr->right, sizeof(hdr->right)); + if (meta_type(&meta->lvalue) == TCF_META_TYPE_INT && + (meta->lvalue.hdr.shift >= BITS_PER_LONG || + meta->rvalue.hdr.shift >= BITS_PER_LONG)) + goto errout; + if (!meta_is_supported(&meta->lvalue) || !meta_is_supported(&meta->rvalue)) { err = -EOPNOTSUPP; -- 2.56.0