CVE & CISA-KEV Catalog

CVE-2024-38306

MEDIUM
4.7
CVSS v3
NVD

Description

In the Linux kernel, the following vulnerability has been resolved: btrfs: protect folio::private when attaching extent buffer folios [BUG] Since v6.8 there are rare kernel crashes reported by various people, the common factor is bad page status error messages like this: BUG: Bad page state in process kswapd0 pfn:d6e840 page: refcount:0 mapcount:0 mapping:000000007512f4f2 index:0x2796c2c7c pfn:0xd6e840 aops:btree_aops ino:1 flags: 0x17ffffe0000008(uptodate|node=0|zone=2|lastcpupid=0x3fffff) page_type: 0xffffffff() raw: 0017ffffe0000008 dead000000000100 dead000000000122 ffff88826d0be4c0 raw: 00000002796c2c7c 0000000000000000 00000000ffffffff 0000000000000000 page dumped because: non-NULL mapping [CAUSE] Commit 09e6cef19c9f ("btrfs: refactor alloc_extent_buffer() to allocate-then-attach method") changes the sequence when allocating a new extent buffer. Previously we always called grab_extent_buffer() under mapping->i_private_lock, to ensure the safety on modification on folio::private (which is a pointer to extent buffer for regular sectorsize). This can lead to the following race: Thread A is trying to allocate an extent buffer at bytenr X, with 4 4K pages, meanwhile thread B is trying to release the page at X + 4K (the second page of the extent buffer at X). Thread A | Thread B -----------------------------------+------------------------------------- | btree_release_folio() | | This is for the page at X + 4K, | | Not page X. | | alloc_extent_buffer() | |- release_extent_buffer() |- filemap_add_folio() for the | | |- atomic_dec_and_test(eb->refs) | page at bytenr X (the first | | | | page). | | | | Which returned -EEXIST. | | | | | | | |- filemap_lock_folio() | | | | Returned the first page locked. | | | | | | | |- grab_extent_buffer() | | | | |- atomic_inc_not_zero() | | | | | Returned false | | | | |- folio_detach_private() | | |- folio_detach_private() for X | |- folio_test_private() | | |- folio_test_private() | Returned true | | | Returned true |- folio_put() | |- folio_put() Now there are two puts on the same folio at folio X, leading to refcount underflow of the folio X, and eventually causing the BUG_ON() on the page->mapping. The condition is not that easy to hit: - The release must be triggered for the middle page of an eb If the release is on the same first page of an eb, page lock would kick in and prevent the race. - folio_detach_private() has a very small race window It's only between folio_test_private() and folio_clear_private(). That's exactly when mapping->i_private_lock is used to prevent such race, and commit 09e6cef19c9f ("btrfs: refactor alloc_extent_buffer() to allocate-then-attach method") screwed that up. At that time, I thought the page lock would kick in as filemap_release_folio() also requires the page to be locked, but forgot the filemap_release_folio() only locks one page, not all pages of an extent buffer. [FIX] Move all the code requiring i_private_lock into attach_eb_folio_to_filemap(), so that everything is done with proper lock protection. Furthermore to prevent future problems, add an extra lockdep_assert_locked() to ensure we're holding the proper lock. To reproducer that is able to hit the race (takes a few minutes with instrumented code inserting delays to alloc_extent_buffer()): #!/bin/sh drop_caches () { while(true); do echo 3 > /proc/sys/vm/drop_caches echo 1 > /proc/sys/vm/compact_memory done } run_tar () { while(true); do for x in `seq 1 80` ; do tar cf /dev/zero /mnt > /dev/null & done wait done } mkfs.btrfs -f -d single -m single ---truncated---

How to fix

Remediation Available
linuxDebian
Fixed in:6.9.7-1CVE-2024-38306
Fixed in:6.9.7-1CVE-2024-38306
linuxUbuntu
Fixed in:6.8.0-44.44USN-6999-1
linux-awsUbuntu
Fixed in:6.8.0-1015.16USN-6999-1
linux-azureUbuntu
Fixed in:6.8.0-1014.16USN-7004-1
linux-gcpUbuntu
Fixed in:6.8.0-1014.16USN-6999-1
linux-gkeUbuntu
Fixed in:6.8.0-1010.13USN-6999-1
linux-hwe-6.8Ubuntu
Fixed in:6.8.0-45.45~22.04.1USN-7029-1
linux-ibmUbuntu
Fixed in:6.8.0-1012.12USN-6999-1
linux-image-6.8.0-1010-gkeUbuntu
Fixed in:6.8.0-1010.13USN-6999-1
linux-image-6.8.0-1011-raspiUbuntu
Fixed in:6.8.0-1011.12USN-6999-2
linux-image-6.8.0-1012-ibmUbuntu
Fixed in:6.8.0-1012.12USN-6999-1
linux-image-6.8.0-1012-oemUbuntu
Fixed in:6.8.0-1012.12USN-6999-1
linux-image-6.8.0-1012-oracleUbuntu
Fixed in:6.8.0-1012.12USN-6999-1
linux-image-6.8.0-1012-oracle-64kUbuntu
Fixed in:6.8.0-1012.12USN-6999-1
linux-image-6.8.0-1013-nvidiaUbuntu
Fixed in:6.8.0-1013.14~22.04.1USN-7005-2
Fixed in:6.8.0-1013.14USN-7005-1
linux-image-6.8.0-1013-nvidia-64kUbuntu
Fixed in:6.8.0-1013.14~22.04.1USN-7005-2
Fixed in:6.8.0-1013.14USN-7005-1
linux-image-6.8.0-1013-nvidia-lowlatencyUbuntu
Fixed in:6.8.0-1013.14.1USN-7005-1
linux-image-6.8.0-1013-nvidia-lowlatency-64kUbuntu
Fixed in:6.8.0-1013.14.1USN-7005-1
linux-image-6.8.0-1014-azureUbuntu
Fixed in:6.8.0-1014.16USN-7004-1
linux-image-6.8.0-1014-azure-fdeUbuntu
Fixed in:6.8.0-1014.16USN-7004-1
linux-image-6.8.0-1014-gcpUbuntu
Fixed in:6.8.0-1014.16USN-6999-1
linux-image-6.8.0-1015-awsUbuntu
Fixed in:6.8.0-1015.16USN-6999-1
linux-image-6.8.0-44-genericUbuntu
Fixed in:6.8.0-44.44USN-6999-1
linux-image-6.8.0-44-generic-64kUbuntu
Fixed in:6.8.0-44.44USN-6999-1
linux-image-6.8.0-44-lowlatencyUbuntu
Fixed in:6.8.0-44.44.1~22.04.1USN-7008-1
Fixed in:6.8.0-44.44.1USN-6999-1
linux-image-6.8.0-44-lowlatency-64kUbuntu
Fixed in:6.8.0-44.44.1~22.04.1USN-7008-1
Fixed in:6.8.0-44.44.1USN-6999-1
linux-image-6.8.0-45-genericUbuntu
Fixed in:6.8.0-45.45~22.04.1USN-7029-1
linux-image-6.8.0-45-generic-64kUbuntu
Fixed in:6.8.0-45.45~22.04.1USN-7029-1
linux-image-awsUbuntu
Fixed in:6.8.0-1015.16USN-6999-1
linux-image-azureUbuntu
Fixed in:6.8.0-1014.16USN-7004-1
linux-image-azure-fdeUbuntu
Fixed in:6.8.0-1014.16USN-7004-1
linux-image-gcpUbuntu
Fixed in:6.8.0-1014.16USN-6999-1
linux-image-genericUbuntu
Fixed in:6.8.0-44.44USN-6999-1
linux-image-generic-64kUbuntu
Fixed in:6.8.0-44.44USN-6999-1
linux-image-generic-64k-hwe-22.04Ubuntu
Fixed in:6.8.0-45.45~22.04.1USN-7029-1
linux-image-generic-64k-hwe-24.04Ubuntu
Fixed in:6.8.0-44.44USN-6999-1
linux-image-generic-hwe-22.04Ubuntu
Fixed in:6.8.0-45.45~22.04.1USN-7029-1
linux-image-generic-hwe-24.04Ubuntu
Fixed in:6.8.0-44.44USN-6999-1
linux-image-generic-lpaeUbuntu
Fixed in:6.8.0-44.44USN-6999-1
linux-image-gkeUbuntu
Fixed in:6.8.0-1010.13USN-6999-1
linux-image-ibmUbuntu
Fixed in:6.8.0-1012.12USN-6999-1
linux-image-ibm-classicUbuntu
Fixed in:6.8.0-1012.12USN-6999-1
linux-image-ibm-lts-24.04Ubuntu
Fixed in:6.8.0-1012.12USN-6999-1
linux-image-kvmUbuntu
Fixed in:6.8.0-44.44USN-6999-1
linux-image-lowlatencyUbuntu
Fixed in:6.8.0-44.44.1USN-6999-1
linux-image-lowlatency-64kUbuntu
Fixed in:6.8.0-44.44.1USN-6999-1
linux-image-lowlatency-64k-hwe-22.04Ubuntu
Fixed in:6.8.0-44.44.1~22.04.1USN-7008-1
linux-image-lowlatency-hwe-22.04Ubuntu
Fixed in:6.8.0-44.44.1~22.04.1USN-7008-1
linux-image-nvidiaUbuntu
Fixed in:6.8.0-1013.13USN-7005-1
linux-image-nvidia-6.8Ubuntu
Fixed in:6.8.0-1013.14~22.04.1USN-7005-2
linux-image-nvidia-64kUbuntu
Fixed in:6.8.0-1013.13USN-7005-1
linux-image-nvidia-64k-6.8Ubuntu
Fixed in:6.8.0-1013.14~22.04.1USN-7005-2
linux-image-nvidia-lowlatencyUbuntu
Fixed in:6.8.0-1013.14.1USN-7005-1
linux-image-nvidia-lowlatency-64kUbuntu
Fixed in:6.8.0-1013.14.1USN-7005-1
linux-image-oem-22.04Ubuntu
Fixed in:6.8.0-45.45~22.04.1USN-7029-1
linux-image-oem-22.04aUbuntu
Fixed in:6.8.0-45.45~22.04.1USN-7029-1
linux-image-oem-22.04bUbuntu
Fixed in:6.8.0-45.45~22.04.1USN-7029-1
linux-image-oem-22.04cUbuntu
Fixed in:6.8.0-45.45~22.04.1USN-7029-1
linux-image-oem-22.04dUbuntu
Fixed in:6.8.0-45.45~22.04.1USN-7029-1
linux-image-oracleUbuntu
Fixed in:6.8.0-1012.12USN-6999-1
linux-image-oracle-64kUbuntu
Fixed in:6.8.0-1012.12USN-6999-1
linux-image-raspiUbuntu
Fixed in:6.8.0-1011.12USN-6999-2
linux-image-virtualUbuntu
Fixed in:6.8.0-44.44USN-6999-1
linux-image-virtual-hwe-22.04Ubuntu
Fixed in:6.8.0-45.45~22.04.1USN-7029-1
linux-image-virtual-hwe-24.04Ubuntu
Fixed in:6.8.0-44.44USN-6999-1
linux-lowlatencyUbuntu
Fixed in:6.8.0-44.44.1USN-6999-1
linux-lowlatency-hwe-6.8Ubuntu
Fixed in:6.8.0-44.44.1~22.04.1USN-7008-1
linux-nvidiaUbuntu
Fixed in:6.8.0-1013.14USN-7005-1
linux-nvidia-6.8Ubuntu
Fixed in:6.8.0-1013.14~22.04.1USN-7005-2
linux-nvidia-lowlatencyUbuntu
Fixed in:6.8.0-1013.14.1USN-7005-1
linux-oem-6.8Ubuntu
Fixed in:6.8.0-1012.12USN-6999-1
linux-oracleUbuntu
Fixed in:6.8.0-1012.12USN-6999-1
linux-raspiUbuntu
Fixed in:6.8.0-1011.12USN-6999-2

Remediation is compiled from vendor and distribution security advisories. Always confirm against the linked source for your exact version and platform.

CVSS v3 Vector

Exploitability

Attack VectorLocal
Attack ComplexityHigh
Privileges RequiredLow
User InteractionNone
ScopeUnchanged

Impact

ConfidentialityNone
IntegrityNone
AvailabilityHigh

CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:N/A:H

Exploit Intelligence

0.14%probability of exploitation in 30 days
4thpercentile

Low risk: more likely to be exploited than 4% of all known CVEs.

References

Related Vulnerabilities

Other CWE-362 (Race Condition) vulnerabilities, ordered by exploit likelihood. View all

CVESeverityCVSSEPSSExploitedFix
CVE-2024-6387High8.1100%-Fix
CVE-2023-36884High7.599%KEV + RansomFix
CVE-2018-15473Medium5.399%-Fix
CVE-2024-27983High8.287%-Fix
CVE-2014-0226Medium6.886%-Fix
CVE-2016-5195High7.084%KEVFix
Embed a live status badge for CVE-2024-38306
CVE-2024-38306 severity badge

Markdown

[![CVE-2024-38306](https://tridentstack.com/cve/badge/CVE-2024-38306.svg)](https://tridentstack.com/cve/CVE-2024-38306)

HTML

<a href="https://tridentstack.com/cve/CVE-2024-38306"><img src="https://tridentstack.com/cve/badge/CVE-2024-38306.svg" alt="CVE-2024-38306"></a>

Find and fix vulnerabilities across your fleet

TridentStack Control continuously scans your Windows, macOS, and Linux fleet for known vulnerabilities, prioritizes them by severity and active exploitation, and patches them automatically.

Start free

This product uses NVD data but is not endorsed or certified by the NVD. EPSS scores courtesy of FIRST.org (https://www.first.org/epss). Source: CISA KEV Catalog. Data as of 2025-09-17.