Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4832083pxb; Thu, 14 Oct 2021 12:53:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxhajXDfJSDSqqxjQqy3ErU9glC3eR7IzvHtBJfhG7XYPA8vF9XyQel1M7zZ+gUOHOwkk1 X-Received: by 2002:a17:90b:4a81:: with SMTP id lp1mr8373548pjb.124.1634241237189; Thu, 14 Oct 2021 12:53:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634241237; cv=none; d=google.com; s=arc-20160816; b=uATfqtGRDcR3QfremOFclCc/JPvgJgUaMWzb8zljZNmIBvEUbwo+NTXGKS/w1yoR8S Np3Gi7ouIpVdw3nvKJ+Kczoa+61MiLvVenhaK/UpO72K5easxKAWPCPvzypbXzmT1bZj HxnLXcrsV04J1mW+6F9QC9oFFPMqMzob4PyVG4uFLARidMrA84uRwTf9JWth1Bn7afId 4YYJf3Zmwdgo4pNi7i6XTPJ1TLQZ5tuxyFWRrosrO4QBx6Szn3uHMjT4tkhWLqaKFMNE EHS2MUR9MOT3zWG2Kx9ccqGAuktGV69QlMiJ8bZCM8xtWidaPtVjN5h6GtxWMrINKMPe UuDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6KZinAwgG2RZKgqKZpeqYSaLNhHw5W5QsisklfqbBE4=; b=JW91ngri91HecaGXME+vnBYX1gyS3qsQ5gCSDd0gbWk0B88Hp8NKGr1hwJ/h5OeXKE Y0tURnfg5G6hvxgeoCqOrs9MXLg3+kKuPhEe5huiv8M3TQdWKFK0TbR9w8HJrILIIteQ U8RpPo0vTq8Kn2RD62Ej5hZaB1870iAbHhGopIBwImMmpa8EDMZuKw1kINXIJF6IavTT TMl79tNB9/SZ5R65a9GkrBCX6cuagcgGn6mujk1uibibVqkGjdh5nxDXpbi3WaWuRRKf atq0lQHWoqcU7rhjbrkLtykvBVP1GHvmJomNkwh8NJU9PY0zZErTkFFZydc0SZyR8ZDx XF1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EgVgNH3Q; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h193si4927249pgc.395.2021.10.14.12.53.20; Thu, 14 Oct 2021 12:53:57 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EgVgNH3Q; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233707AbhJNPGf (ORCPT + 99 others); Thu, 14 Oct 2021 11:06:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:50460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233709AbhJNPEw (ORCPT ); Thu, 14 Oct 2021 11:04:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A1FCB611C1; Thu, 14 Oct 2021 15:00:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634223659; bh=OTrccWwKPffRiq3S6lIt8TgRqj+9/RN0ax0h0LgFrls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EgVgNH3QHXz2gooycYsGA+Agq+86CRCwMpQhGP3bKF8gmAOryIip1kE1qdj6w17y1 xXf5JiV4UCBAEn1391nUE3Ppj6CVRGjK3o5bqP8+JgFo1XQOR3hXQenBIkJ/QC6XY4 4CngSQoSsSL3iXU77YuOq2r5jbVoWNaxg7owvClc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Abaci , Michael Wang , "David S. Miller" , Sasha Levin Subject: [PATCH 5.14 18/30] net: prevent user from passing illegal stab size Date: Thu, 14 Oct 2021 16:54:23 +0200 Message-Id: <20211014145210.126140061@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211014145209.520017940@linuxfoundation.org> References: <20211014145209.520017940@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: 王贇 [ Upstream commit b193e15ac69d56f35e1d8e2b5d16cbd47764d053 ] 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 Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- 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 6d7b12cba015..bf79f3a890af 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 f87d07736a14..148edd0e71e3 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); -- 2.33.0