Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6ECAE54BDA for ; Sun, 28 Apr 2024 13:05:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714309525; cv=none; b=Dt9QJot1dEpEPpGYMCbcL+eMpKMnF/TsFfgiGNGLHl0WB5sA3OAFegsq0c/BmwKRTRVlwjt8o7CUsIuGg9OiKsDRSMPEHJbLc0ooLOtERnljJt1VtkkwNX+xKGk1oAyoPUmdIq+5xy+TSkv65EMdQX3WRW6GpjB8W5RH7gg3qNE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714309525; c=relaxed/simple; bh=N/CQtKbGI+k3aoo2nuVTDDGqZjekYRHw6iaG9fx9peY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=dMaHKcW64TO0+FWV/l64gHfjDy/cACkgfFt6zmY7LRTfRwF/pueDYKBa1LO0xN/x0J97UdKrhNv/068livoxVUKMWQmYcNLgtaxnpaqRSa363S0EOGm8CmILfy0iu7c5LXyoGj+PjaZgWgPUmHmdo7Vj+8rCJmJb2UwdYKXOxS0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=L2KAdhWs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="L2KAdhWs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5168C113CC; Sun, 28 Apr 2024 13:05:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1714309525; bh=N/CQtKbGI+k3aoo2nuVTDDGqZjekYRHw6iaG9fx9peY=; h=From:To:Cc:Subject:Date:Reply-to:From; b=L2KAdhWs1n2QZuUwew+BWVBujz13AnaLk9cY+Zed8nrqW9TDuBXt4oCJBzcLNJ8p5 tDkuZ4FTvcm8a4Tomc5rUxTNdPHtgXIUmTzzapRxyCZ9KHILB1lkzaW0/0HLkg6Dhb OktkE3IOBDJ9eqiy6eoXlKMgf+clwOolyvbvmVuc= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2022-48644: net/sched: taprio: avoid disabling offload when it was never enabled Date: Sun, 28 Apr 2024 15:05:05 +0200 Message-ID: <2024042856-CVE-2022-48644-757e@gregkh> X-Mailer: git-send-email 2.44.0 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=5770; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=N/CQtKbGI+k3aoo2nuVTDDGqZjekYRHw6iaG9fx9peY=; b=owGbwMvMwCRo6H6F97bub03G02pJDGl6nhXffvvbHyiS59SwkMsrEdC+tmTDM+7UzKNKr/dlr utgWWrQEcvCIMjEICumyPJlG8/R/RWHFL0MbU/DzGFlAhnCwMUpABO55scwi0lAN9kwp/ig27MH fLo7FyWzLng2n2FB10cjNxM93shri3d2b6+413FAUGEaAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit Description =========== In the Linux kernel, the following vulnerability has been resolved: net/sched: taprio: avoid disabling offload when it was never enabled In an incredibly strange API design decision, qdisc->destroy() gets called even if qdisc->init() never succeeded, not exclusively since commit 87b60cfacf9f ("net_sched: fix error recovery at qdisc creation"), but apparently also earlier (in the case of qdisc_create_dflt()). The taprio qdisc does not fully acknowledge this when it attempts full offload, because it starts off with q->flags = TAPRIO_FLAGS_INVALID in taprio_init(), then it replaces q->flags with TCA_TAPRIO_ATTR_FLAGS parsed from netlink (in taprio_change(), tail called from taprio_init()). But in taprio_destroy(), we call taprio_disable_offload(), and this determines what to do based on FULL_OFFLOAD_IS_ENABLED(q->flags). But looking at the implementation of FULL_OFFLOAD_IS_ENABLED() (a bitwise check of bit 1 in q->flags), it is invalid to call this macro on q->flags when it contains TAPRIO_FLAGS_INVALID, because that is set to U32_MAX, and therefore FULL_OFFLOAD_IS_ENABLED() will return true on an invalid set of flags. As a result, it is possible to crash the kernel if user space forces an error between setting q->flags = TAPRIO_FLAGS_INVALID, and the calling of taprio_enable_offload(). This is because drivers do not expect the offload to be disabled when it was never enabled. The error that we force here is to attach taprio as a non-root qdisc, but instead as child of an mqprio root qdisc: $ tc qdisc add dev swp0 root handle 1: \ mqprio num_tc 8 map 0 1 2 3 4 5 6 7 \ queues 1@0 1@1 1@2 1@3 1@4 1@5 1@6 1@7 hw 0 $ tc qdisc replace dev swp0 parent 1:1 \ taprio num_tc 8 map 0 1 2 3 4 5 6 7 \ queues 1@0 1@1 1@2 1@3 1@4 1@5 1@6 1@7 base-time 0 \ sched-entry S 0x7f 990000 sched-entry S 0x80 100000 \ flags 0x0 clockid CLOCK_TAI Unable to handle kernel paging request at virtual address fffffffffffffff8 [fffffffffffffff8] pgd=0000000000000000, p4d=0000000000000000 Internal error: Oops: 96000004 [#1] PREEMPT SMP Call trace: taprio_dump+0x27c/0x310 vsc9959_port_setup_tc+0x1f4/0x460 felix_port_setup_tc+0x24/0x3c dsa_slave_setup_tc+0x54/0x27c taprio_disable_offload.isra.0+0x58/0xe0 taprio_destroy+0x80/0x104 qdisc_create+0x240/0x470 tc_modify_qdisc+0x1fc/0x6b0 rtnetlink_rcv_msg+0x12c/0x390 netlink_rcv_skb+0x5c/0x130 rtnetlink_rcv+0x1c/0x2c Fix this by keeping track of the operations we made, and undo the offload only if we actually did it. I've added "bool offloaded" inside a 4 byte hole between "int clockid" and "atomic64_t picos_per_byte". Now the first cache line looks like below: $ pahole -C taprio_sched net/sched/sch_taprio.o struct taprio_sched { struct Qdisc * * qdiscs; /* 0 8 */ struct Qdisc * root; /* 8 8 */ u32 flags; /* 16 4 */ enum tk_offsets tk_offset; /* 20 4 */ int clockid; /* 24 4 */ bool offloaded; /* 28 1 */ /* XXX 3 bytes hole, try to pack */ atomic64_t picos_per_byte; /* 32 0 */ /* XXX 8 bytes hole, try to pack */ spinlock_t current_entry_lock; /* 40 0 */ /* XXX 8 bytes hole, try to pack */ struct sched_entry * current_entry; /* 48 8 */ struct sched_gate_list * oper_sched; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ The Linux kernel CVE team has assigned CVE-2022-48644 to this issue. Affected and fixed versions =========================== Issue introduced in 5.4 with commit 9c66d1564676 and fixed in 5.4.215 with commit d12a1eb07003 Issue introduced in 5.4 with commit 9c66d1564676 and fixed in 5.10.146 with commit 586def6ebed1 Issue introduced in 5.4 with commit 9c66d1564676 and fixed in 5.15.71 with commit f58e43184226 Issue introduced in 5.4 with commit 9c66d1564676 and fixed in 5.19.12 with commit c7c9c7eb305a Issue introduced in 5.4 with commit 9c66d1564676 and fixed in 6.0 with commit db46e3a88a09 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2022-48644 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: net/sched/sch_taprio.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/d12a1eb07003e597077329767c6aa86a7e972c76 https://git.kernel.org/stable/c/586def6ebed195f3594a4884f7c5334d0e1ad1bb https://git.kernel.org/stable/c/f58e43184226e5e9662088ccf1389e424a3a4cbd https://git.kernel.org/stable/c/c7c9c7eb305ab8b4e93e4e4e1b78d8cfcbc26323 https://git.kernel.org/stable/c/db46e3a88a09c5cf7e505664d01da7238cd56c92