Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4521390pxb; Mon, 27 Sep 2021 20:12:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw79pHNGXXVv6RhCxuZEATn9toMgbJP799zI1iZ1x4RzFJJ9RQTmHU3gRbl0xN4JlFQDCZn X-Received: by 2002:a17:90a:b795:: with SMTP id m21mr2770639pjr.143.1632798772799; Mon, 27 Sep 2021 20:12:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632798772; cv=none; d=google.com; s=arc-20160816; b=Y6+QencG/CTv3HAYNSWKAE/1vfD3cwa2DmEFWb82Jgv7cLfBQH8/0hoT+CysufuEVM F3l0m5eIaLJKu5b5Fw7DSvD2OTyRkiITkrolctys5ulqKKTGiG+Ddv1TTackB+JTzdOD S2XFi2Cova+9mPSIfs0Zp33nT5ART2xtvvDpnp1yCypNgV9mtUMTr2VE4fWvt3RkEhat D3dqy3GRe+5sltq0XpIBCdMYGDuQ33LZBS9PzNE/soaRchuxom4GeNJNFwrNyP2r+NmA jScL0DZK5YhMZI6SkXxwhBbYgZsvELACTChsvKQdB0ZLw6uKKozPbJVW80MPKDeR9nTO X+cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:user-agent:date:message-id:subject:from:to; bh=n6pf+XFQsqFXcqtxXlrViLU2ELD/4jPkk9lXGVqWUs4=; b=EdyzVs37KUEfmCGVPlSWHDhaLsNTrnzgRudeyBRdSJ71j1lr9luxpcLz55/zRnSb+H vnRuO6fmpscKa+H8N3qUlmVOSNeDqlTCNI2GuI0APr92cewODsYrBlC3HXS8MjVPy75p Doj3TbIYhG4fBMZ1YHlYiqN+QUEjtLHLX+S9S9vdHCXTgeaOBeqf/f9vqNseIfsA2CKf pcPDXAAT8WUrxd0IXlCbxYrady52YhRhJHdpdtUFw0HR800qnsqH+DYkWe9DPSnJagvI Q2CF4NAEmsr93SKopPfWAlyVF5BPolx/Fl1n+T6piY5EipNJ5pOOlplkunZEBdAriV27 WFQg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x25si9195321pfp.13.2021.09.27.20.12.38; Mon, 27 Sep 2021 20:12:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238788AbhI1DNH (ORCPT + 99 others); Mon, 27 Sep 2021 23:13:07 -0400 Received: from out30-131.freemail.mail.aliyun.com ([115.124.30.131]:50923 "EHLO out30-131.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238762AbhI1DNG (ORCPT ); Mon, 27 Sep 2021 23:13:06 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R161e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04426;MF=yun.wang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0UptkUp0_1632798685; Received: from testdeMacBook-Pro.local(mailfrom:yun.wang@linux.alibaba.com fp:SMTPD_---0UptkUp0_1632798685) by smtp.aliyun-inc.com(127.0.0.1); Tue, 28 Sep 2021 11:11:25 +0800 To: Jamal Hadi Salim , Cong Wang , Jiri Pirko , "David S. Miller" , Jakub Kicinski , "open list:TC subsystem" , open list From: =?UTF-8?B?546L6LSH?= Subject: [RESEND PATCH v2] net: prevent user from passing illegal stab size Message-ID: Date: Tue, 28 Sep 2021 11:11:25 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Michael Wang --- include/net/pkt_sched.h | 1 + net/sched/sch_api.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/net/pkt_sched.h b/include/net/pkt_sched.h index 6d7b12c..bf79f3a 100644 --- a/include/net/pkt_sched.h +++ b/include/net/pkt_sched.h @@ -11,6 +11,7 @@ #include #define DEFAULT_TX_QUEUE_LEN 1000 +#define STAB_SIZE_LOG_MAX 30 struct qdisc_walker { int stop; diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index 5e90e9b..12f39a2 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c @@ -513,6 +513,12 @@ static struct qdisc_size_table *qdisc_get_stab(struct nlattr *opt, return stab; } + if (s->size_log > STAB_SIZE_LOG_MAX || + s->cell_log > STAB_SIZE_LOG_MAX) { + NL_SET_ERR_MSG(extack, "Invalid logarithmic size of size table"); + return ERR_PTR(-EINVAL); + } + stab = kmalloc(sizeof(*stab) + tsize * sizeof(u16), GFP_KERNEL); if (!stab) return ERR_PTR(-ENOMEM); -- 1.8.3.1