Commit eec73289 authored by Eric Dumazet's avatar Eric Dumazet Committed by Liu Jian
Browse files

net/sched: taprio: always validate TCA_TAPRIO_ATTR_PRIOMAP

stable inclusion
from stable-v6.6.35
commit 724050ae4b76e4fae05a923cb54101d792cf4404
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IA6H2M
CVE: CVE-2024-36974

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=724050ae4b76e4fae05a923cb54101d792cf4404



---------------------------

[ Upstream commit f921a58ae20852d188f70842431ce6519c4fdc36 ]

If one TCA_TAPRIO_ATTR_PRIOMAP attribute has been provided,
taprio_parse_mqprio_opt() must validate it, or userspace
can inject arbitrary data to the kernel, the second time
taprio_change() is called.

First call (with valid attributes) sets dev->num_tc
to a non zero value.

Second call (with arbitrary mqprio attributes)
returns early from taprio_parse_mqprio_opt()
and bad things can happen.

Fixes: a3d43c0d ("taprio: Add support adding an admin schedule")
Reported-by: default avatarNoam Rathaus <noamr@ssd-disclosure.com>
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Acked-by: default avatarVinicius Costa Gomes <vinicius.gomes@intel.com>
Reviewed-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20240604181511.769870-1-edumazet@google.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarLiu Jian <liujian56@huawei.com>
parent dc011b0f
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -1186,16 +1186,13 @@ static int taprio_parse_mqprio_opt(struct net_device *dev,
{
	bool allow_overlapping_txqs = TXTIME_ASSIST_IS_ENABLED(taprio_flags);

	if (!qopt && !dev->num_tc) {
	if (!qopt) {
		if (!dev->num_tc) {
			NL_SET_ERR_MSG(extack, "'mqprio' configuration is necessary");
			return -EINVAL;
		}

	/* If num_tc is already set, it means that the user already
	 * configured the mqprio part
	 */
	if (dev->num_tc)
		return 0;
	}

	/* taprio imposes that traffic classes map 1:n to tx queues */
	if (qopt->num_tc > dev->num_tx_queues) {