Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1135318pxb; Thu, 23 Sep 2021 19:39:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIYcP6fPYSePSfjKEqjafCD1pW1MwkEB71SEdGqcfP1ern/y2ZA2cTWlIBsMITp4EofeoB X-Received: by 2002:aa7:df8b:: with SMTP id b11mr2389036edy.61.1632451177948; Thu, 23 Sep 2021 19:39:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632451177; cv=none; d=google.com; s=arc-20160816; b=PkRhQNBEX+9J/GNOZCXf3/ap9in9F0OpHgGwEPiBVXlSa8IBWP9DogyqVxqJzDuSy9 /DNG2Efb19quA3nGCj8bICPy5M0bOfa2KSRlsunR3JLqX+Din4OGHmBPFEqqsRomi7vO iKTab/Ds/SS+63E/BJ9T3A3pLK2C8vMXe5IlOGc0TC3H6g9AhkLc/t7sYE/Yo9bKDzIi xYPZqmstrfAPXc/hr6HcQMGfCyEgRoWBBa/uAzqZD0FPLUVDl0cWiFdgO3zUaNQxC2MT u/l7GfkcKjk1l2w7FCfAFAzS80/4+WEIJmRM3mVmAkwkYjo+u43+THWyzQxhZfUXHxE9 jY3Q== 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 :in-reply-to:mime-version:user-agent:date:message-id:references:to :from:subject; bh=pjhB4ZCE2vwapbhutLA+0jMgiyk7FjGuunv2fK66VcY=; b=wRJUriVqKmqRDtB7oDU1qBDtuLtsZfQDr5sHsttO6FwVrZi47Gd6TMyzWvCbs9FTc+ SRARyxFZp75sFPuhKQ+30yEiT3mbwWGfl82AoSOndxkp1C1HsfIQfy0YWH3YOO/G95Zm /w9KtketdB0hF5IcKY24qTpd4atleekt2YiDnaGWUbowHFXTa6vwG5Ro0kSw1FXdWXTt OHdqfc+Iq99ThFLZpYqp6K9iX4lp+giyBESFl9od3hKcyd8XmvXoZeccK5RGw/mb1pn5 QaCumtCydrTk2NnVrICYycuobdwvGXkSSOheYEnTkFykenVrX81XNJ66iyeCirzdh3IJ cmAA== 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 de41si7741516ejc.244.2021.09.23.19.39.14; Thu, 23 Sep 2021 19:39:37 -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 S243914AbhIXChf (ORCPT + 99 others); Thu, 23 Sep 2021 22:37:35 -0400 Received: from out30-44.freemail.mail.aliyun.com ([115.124.30.44]:59721 "EHLO out30-44.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233314AbhIXChe (ORCPT ); Thu, 23 Sep 2021 22:37:34 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=yun.wang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0UpOL48y_1632450958; Received: from testdeMacBook-Pro.local(mailfrom:yun.wang@linux.alibaba.com fp:SMTPD_---0UpOL48y_1632450958) by smtp.aliyun-inc.com(127.0.0.1); Fri, 24 Sep 2021 10:35:59 +0800 Subject: [PATCH v2] net: prevent user from passing illegal stab size From: =?UTF-8?B?546L6LSH?= To: Jamal Hadi Salim , Cong Wang , Jiri Pirko , "David S. Miller" , Jakub Kicinski , "open list:TC subsystem" , open list References: Message-ID: Date: Fri, 24 Sep 2021 10:35:58 +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 In-Reply-To: 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