linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Abaci <abaci@linux.alibaba.com>,
	Michael Wang <yun.wang@linux.alibaba.com>,
	"David S. Miller" <davem@davemloft.net>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.10 13/22] net: prevent user from passing illegal stab size
Date: Thu, 14 Oct 2021 16:54:19 +0200	[thread overview]
Message-ID: <20211014145208.419020014@linuxfoundation.org> (raw)
In-Reply-To: <20211014145207.979449962@linuxfoundation.org>

From: 王贇 <yun.wang@linux.alibaba.com>

[ 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 <abaci@linux.alibaba.com>
Signed-off-by: Michael Wang <yun.wang@linux.alibaba.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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 2be90a54a404..7e58b4470570 100644
--- a/include/net/pkt_sched.h
+++ b/include/net/pkt_sched.h
@@ -11,6 +11,7 @@
 #include <uapi/linux/pkt_sched.h>
 
 #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 54a8c363bcdd..7b24582a8a16 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




  parent reply	other threads:[~2021-10-14 15:02 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-14 14:54 [PATCH 5.10 00/22] 5.10.74-rc1 review Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 01/22] ext4: check and update i_disksize properly Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 02/22] ext4: correct the error path of ext4_write_inline_data_end() Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 03/22] ASoC: Intel: sof_sdw: tag SoundWire BEs as non-atomic Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 04/22] HID: apple: Fix logical maximum and usage maximum of Magic Keyboard JIS Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 05/22] netfilter: ip6_tables: zero-initialize fragment offset Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 06/22] HID: wacom: Add new Intuos BT (CTL-4100WL/CTL-6100WL) device IDs Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 07/22] ASoC: SOF: loader: release_firmware() on load failure to avoid batching Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 08/22] netfilter: nf_nat_masquerade: make async masq_inet6_event handling generic Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 09/22] netfilter: nf_nat_masquerade: defer conntrack walk to work queue Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 10/22] mac80211: Drop frames from invalid MAC address in ad-hoc mode Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 11/22] m68k: Handle arrivals of multiple signals correctly Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 12/22] hwmon: (ltc2947) Properly handle errors when looking for the external clock Greg Kroah-Hartman
2021-10-14 14:54 ` Greg Kroah-Hartman [this message]
2021-10-14 14:54 ` [PATCH 5.10 14/22] mac80211: check return value of rhashtable_init Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 15/22] vboxfs: fix broken legacy mount signature checking Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 16/22] net: sun: SUNVNET_COMMON should depend on INET Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 17/22] drm/amdgpu: fix gart.bo pin_count leak Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 18/22] scsi: ses: Fix unsigned comparison with less than zero Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 19/22] scsi: virtio_scsi: Fix spelling mistake "Unsupport" -> "Unsupported" Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 20/22] perf/core: fix userpage->time_enabled of inactive events Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 21/22] sched: Always inline is_percpu_thread() Greg Kroah-Hartman
2021-10-14 14:54 ` [PATCH 5.10 22/22] hwmon: (pmbus/ibm-cffps) max_power_out swap changes Greg Kroah-Hartman
2021-10-14 18:20 ` [PATCH 5.10 00/22] 5.10.74-rc1 review Fox Chen
2021-10-14 21:08 ` Pavel Machek
2021-10-14 22:04 ` Florian Fainelli
2021-10-14 22:38 ` Shuah Khan
2021-10-15  7:21 ` Samuel Zou
2021-10-15 14:30 ` Sudip Mukherjee
2021-10-15 16:28 ` Daniel Díaz
2021-10-15 22:07 ` Guenter Roeck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211014145208.419020014@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=abaci@linux.alibaba.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=yun.wang@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).