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 4044512E48 for ; Wed, 17 Jul 2024 06:10:21 +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=1721196622; cv=none; b=DwG+Xb4gQ/OjIVAhq0dZ1pH9TyKMlKO++KFPWc/46ar9/aE+14pb7dQRDd2Sc4U/m8R2rQzpLx3deMSnnWAYiv6DyL62803OceE4FwCiDa3EPq5a490dnnylid8Lj21jGnqSB6uoHgaAx4u3wTtlonlj21efwJ3/JeB1BkZbz1A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721196622; c=relaxed/simple; bh=n6ARiZwNF4pW2eu6rIuEWNaSd46ilfd5wTcoS1RbYvY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=h+f+/U51XLgHZUSUwrJhZTViLr+OzdnFnIFqNNrku5cbjJ4bPNQf8ux319Vi/8K60OkJ0hshyRFw3CSBDJaizl3HlywhyzMvPe9jftUf2bzZWN8p5AJ2wdfbw0v9jGrrev5NhDKN6U8OTGrOgBElEaGSEEmWxehrEHciRI+jYnQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hpPbaRtU; 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="hpPbaRtU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EA07C32782; Wed, 17 Jul 2024 06:10:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1721196621; bh=n6ARiZwNF4pW2eu6rIuEWNaSd46ilfd5wTcoS1RbYvY=; h=From:To:Cc:Subject:Date:Reply-to:From; b=hpPbaRtUd6fj44hgDkgeavdz9854CDBugoz2/v56wSsd4g3S48x3lclhsX+sBgtPP /iWXIXxRr4CvEh/AKtMaQbYHwmfrC8vuC/HSuuijrSWG7IdCxIU/oHnlI75YU9bqPj B5uPE9H8Rjf0SD+as5yuJ7i10e+2CjzRN+fX2sjw= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-41010: bpf: Fix too early release of tcx_entry Date: Wed, 17 Jul 2024 08:10:17 +0200 Message-ID: <2024071718-CVE-2024-41010-9042@gregkh> X-Mailer: git-send-email 2.45.2 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=4480; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=n6ARiZwNF4pW2eu6rIuEWNaSd46ilfd5wTcoS1RbYvY=; b=owGbwMvMwCRo6H6F97bub03G02pJDGnTE7z6DVZxne2IX5koevd2Q9TpvxJP0k3qssNPdeqct b2S0mTaEcvCIMjEICumyPJlG8/R/RWHFL0MbU/DzGFlAhnCwMUpABPxrGeYp3Yh80rKmqkPLNqf dz5ZK90TfTrTCyjqJD8vxHqDoYj9ijfc0n3x/85y3gcA 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: bpf: Fix too early release of tcx_entry Pedro Pinto and later independently also Hyunwoo Kim and Wongi Lee reported an issue that the tcx_entry can be released too early leading to a use after free (UAF) when an active old-style ingress or clsact qdisc with a shared tc block is later replaced by another ingress or clsact instance. Essentially, the sequence to trigger the UAF (one example) can be as follows: 1. A network namespace is created 2. An ingress qdisc is created. This allocates a tcx_entry, and &tcx_entry->miniq is stored in the qdisc's miniqp->p_miniq. At the same time, a tcf block with index 1 is created. 3. chain0 is attached to the tcf block. chain0 must be connected to the block linked to the ingress qdisc to later reach the function tcf_chain0_head_change_cb_del() which triggers the UAF. 4. Create and graft a clsact qdisc. This causes the ingress qdisc created in step 1 to be removed, thus freeing the previously linked tcx_entry: rtnetlink_rcv_msg() => tc_modify_qdisc() => qdisc_create() => clsact_init() [a] => qdisc_graft() => qdisc_destroy() => __qdisc_destroy() => ingress_destroy() [b] => tcx_entry_free() => kfree_rcu() // tcx_entry freed 5. Finally, the network namespace is closed. This registers the cleanup_net worker, and during the process of releasing the remaining clsact qdisc, it accesses the tcx_entry that was already freed in step 4, causing the UAF to occur: cleanup_net() => ops_exit_list() => default_device_exit_batch() => unregister_netdevice_many() => unregister_netdevice_many_notify() => dev_shutdown() => qdisc_put() => clsact_destroy() [c] => tcf_block_put_ext() => tcf_chain0_head_change_cb_del() => tcf_chain_head_change_item() => clsact_chain_head_change() => mini_qdisc_pair_swap() // UAF There are also other variants, the gist is to add an ingress (or clsact) qdisc with a specific shared block, then to replace that qdisc, waiting for the tcx_entry kfree_rcu() to be executed and subsequently accessing the current active qdisc's miniq one way or another. The correct fix is to turn the miniq_active boolean into a counter. What can be observed, at step 2 above, the counter transitions from 0->1, at step [a] from 1->2 (in order for the miniq object to remain active during the replacement), then in [b] from 2->1 and finally [c] 1->0 with the eventual release. The reference counter in general ranges from [0,2] and it does not need to be atomic since all access to the counter is protected by the rtnl mutex. With this in place, there is no longer a UAF happening and the tcx_entry is freed at the correct time. The Linux kernel CVE team has assigned CVE-2024-41010 to this issue. Affected and fixed versions =========================== Issue introduced in 6.6 with commit e420bed02507 and fixed in 6.10 with commit 1cb6f0bae504 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-2024-41010 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: include/net/tcx.h net/sched/sch_ingress.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/1cb6f0bae50441f4b4b32a28315853b279c7404e