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 A6B341553A7 for ; Mon, 29 Jul 2024 14:33: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=1722263605; cv=none; b=onbQMYUhb0RlodaLBN7HTTvLYZtdSnIMOng16wY4u4D66YYlZxjRmXLKFmkVOC19Dz5oAQR3oh2dtm0xAGCnLMMI3NV9Caj2CILtv6MPLjOPtp7Crsz3HFkJlZD8yUflYOgQsC6Jgc1SdriywwVsb8RC9PTka13PO365EjkjL8Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722263605; c=relaxed/simple; bh=UFVtwp5iuxX2xp1Ltp3VYde8D1jyVq/UKSU9gmxmjdQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=POicUq8aj4H4xIh5N5xNb7iqdOOij/8Gd1IbAeOvfDUk2bZdkxJYLJbrUN33IRfONn1MbYNGyUGDS/Ltut0bBZwUFgFewyWmuwf4Tj4bA97IglphCAike9iFeRFVJM+eqcfHepFqd423Iy8EHTZHnNV8y/4FDgugFINlnNzq6+I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jTEz7K1o; 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="jTEz7K1o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15AE6C32786; Mon, 29 Jul 2024 14:33:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1722263605; bh=UFVtwp5iuxX2xp1Ltp3VYde8D1jyVq/UKSU9gmxmjdQ=; h=From:To:Cc:Subject:Date:Reply-to:From; b=jTEz7K1of0DH6irhktkmOhsn/7raCJPQecQtx9kmGN+xhcD3oRUe+Dgk7UC0g/+sR bkvfZMjmuV2Ws5zpdLOrARNCH8ECI5NxM2Hh+WikVID7rV5te1yR2C7GTnad+Hf3g1 4kH15IaFKkuC+uYj7VHDbSXaetMNg69EutZlPNa4= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-41045: bpf: Defer work in bpf_timer_cancel_and_free Date: Mon, 29 Jul 2024 16:32:40 +0200 Message-ID: <2024072925-CVE-2024-41045-6cc1@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=3287; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=UFVtwp5iuxX2xp1Ltp3VYde8D1jyVq/UKSU9gmxmjdQ=; b=owGbwMvMwCRo6H6F97bub03G02pJDGnLl/90uhS1hm+q3Jo+5Ufp4h9Whmas2fHxeGzIcb/N7 4v+T97X1hHLwiDIxCArpsjyZRvP0f0VhxS9DG1Pw8xhZQIZwsDFKQATuTyfYcH5V0pfTG0aOrhe h6/mSb/3f8nMw6oM8wu2/1/IlGs0h3dyy0SdDLW6c9HTjgEA 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: Defer work in bpf_timer_cancel_and_free Currently, the same case as previous patch (two timer callbacks trying to cancel each other) can be invoked through bpf_map_update_elem as well, or more precisely, freeing map elements containing timers. Since this relies on hrtimer_cancel as well, it is prone to the same deadlock situation as the previous patch. It would be sufficient to use hrtimer_try_to_cancel to fix this problem, as the timer cannot be enqueued after async_cancel_and_free. Once async_cancel_and_free has been done, the timer must be reinitialized before it can be armed again. The callback running in parallel trying to arm the timer will fail, and freeing bpf_hrtimer without waiting is sufficient (given kfree_rcu), and bpf_timer_cb will return HRTIMER_NORESTART, preventing the timer from being rearmed again. However, there exists a UAF scenario where the callback arms the timer before entering this function, such that if cancellation fails (due to timer callback invoking this routine, or the target timer callback running concurrently). In such a case, if the timer expiration is significantly far in the future, the RCU grace period expiration happening before it will free the bpf_hrtimer state and along with it the struct hrtimer, that is enqueued. Hence, it is clear cancellation needs to occur after async_cancel_and_free, and yet it cannot be done inline due to deadlock issues. We thus modify bpf_timer_cancel_and_free to defer work to the global workqueue, adding a work_struct alongside rcu_head (both used at _different_ points of time, so can share space). Update existing code comments to reflect the new state of affairs. The Linux kernel CVE team has assigned CVE-2024-41045 to this issue. Affected and fixed versions =========================== Issue introduced in 5.15 with commit b00628b1c7d5 and fixed in 6.9.10 with commit 7aa5a19279c3 Issue introduced in 5.15 with commit b00628b1c7d5 and fixed in 6.10 with commit a6fcd19d7eac 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-41045 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: kernel/bpf/helpers.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/7aa5a19279c3639ae8b758b63f05d0c616a39fa1 https://git.kernel.org/stable/c/a6fcd19d7eac1335eb76bc16b6a66b7f574d1d69