Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp384726pxb; Thu, 23 Sep 2021 02:10:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZoZ0Se5SVFIH5Yd2vF0J2+9XBgTMWLIsQ+B/qdLQPotj/XqhKmaNkjr1Jt/HHt/OAxbQU X-Received: by 2002:a6b:7c45:: with SMTP id b5mr2982158ioq.191.1632388244850; Thu, 23 Sep 2021 02:10:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632388244; cv=none; d=google.com; s=arc-20160816; b=r4T2e/nN+xU2YAeIOwBXEgrDPtg7FGQF1TW1izvOULlg9PRFpfC/FGDxZmIrWnpFib E8ZOQjJ671pyy43uTrCkmPxjnIM5QUf0MmTnnQBgWMygGxzH7Mchq31CLUypbE8sJw5F hcWZUr/vfemAt4zF6nxyaDoiAO4PjDvBREEvZId0iNJnsEblRPSqK011iNmAfrTrrIxZ xO4KJx3MTWB2ak3fy3yItWBR3A7PG4ibkoFLrB0oRaaTv82hz5ENpgMPdbVTVlfbZOT8 Pj4HbupHAikB8RzoYrkq0T0231UcyfIOh2RRuM0Pazh/OKqvzszYSXRcpZhj2U0sN3Nh KCeg== 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=RalLvuABP1r+88QazwmkBFrMw/iB1XuAsWPeWu+USzY=; b=QRKBuVwO1NiYazHRgoGwBf/mJ5hM7Sbd/GTrhikxdJp9+5XV25rf40P5jUTkeSpuvA y7V0a5oMMAumg1KZkwba6acAs6yNbxh0cMS1rokCE8tqvkIGy+CpYTF6bN/FIRt5/4ZB 1do7EzI2YBr9jm10FNa9t8Gq/YO3H96akwPTWrSgzJLN8w2SsXJQ32gh2Alx0oOR19xu omiuZqUf9gfaKFpTInPJZzcA3Zt+feL0gp94P3e/sk+aiKmhroHkFCa1fuU8WFmDQm20 aW14k4sxl1snZzqABrTarVIqVzPD+Jvnmgl/Ukwt0CkF4iqxjXqZJzKkHAsBruksZcup 3Rdw== 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 a1si5272233jaa.131.2021.09.23.02.10.33; Thu, 23 Sep 2021 02:10:44 -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 S240091AbhIWJJr (ORCPT + 99 others); Thu, 23 Sep 2021 05:09:47 -0400 Received: from out30-42.freemail.mail.aliyun.com ([115.124.30.42]:36872 "EHLO out30-42.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239985AbhIWJJr (ORCPT ); Thu, 23 Sep 2021 05:09:47 -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=e01e01424;MF=yun.wang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0UpJU6BM_1632388093; Received: from testdeMacBook-Pro.local(mailfrom:yun.wang@linux.alibaba.com fp:SMTPD_---0UpJU6BM_1632388093) by smtp.aliyun-inc.com(127.0.0.1); Thu, 23 Sep 2021 17:08:14 +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: [PATCH] net: prevent user from passing illegal stab size Message-ID: Date: Thu, 23 Sep 2021 17:08:13 +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 size_log passing from user, and will use the insane value later to calculate pkt_len. This patch just add a check on the size_log to avoid insane calculation. Reported-by: Abaci Signed-off-by: Michael Wang --- include/uapi/linux/pkt_sched.h | 1 + net/sched/sch_api.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/include/uapi/linux/pkt_sched.h b/include/uapi/linux/pkt_sched.h index ec88590..fa194a0 100644 --- a/include/uapi/linux/pkt_sched.h +++ b/include/uapi/linux/pkt_sched.h @@ -98,6 +98,7 @@ struct tc_ratespec { }; #define TC_RTAB_SIZE 1024 +#define TC_LOG_MAX 30 struct tc_sizespec { unsigned char cell_log; diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index 5e90e9b..1b6b8f8 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c @@ -513,6 +513,9 @@ static struct qdisc_size_table *qdisc_get_stab(struct nlattr *opt, return stab; } + if (s->size_log > TC_LOG_MAX) + return ERR_PTR(-EINVAL); + stab = kmalloc(sizeof(*stab) + tsize * sizeof(u16), GFP_KERNEL); if (!stab) return ERR_PTR(-ENOMEM); -- 1.8.3.1