CVE-2024-46734

Source
https://nvd.nist.gov/vuln/detail/CVE-2024-46734
Import Source
https://storage.googleapis.com/osv-test-cve-osv-conversion/osv-output/CVE-2024-46734.json
JSON Data
https://api.test.osv.dev/v1/vulns/CVE-2024-46734
Downstream
Related
Published
2024-09-18T07:11:56Z
Modified
2025-10-14T23:15:43.084859Z
Summary
btrfs: fix race between direct IO write and fsync when using same fd
Details

In the Linux kernel, the following vulnerability has been resolved:

btrfs: fix race between direct IO write and fsync when using same fd

If we have 2 threads that are using the same file descriptor and one of them is doing direct IO writes while the other is doing fsync, we have a race where we can end up either:

1) Attempt a fsync without holding the inode's lock, triggering an assertion failures when assertions are enabled;

2) Do an invalid memory access from the fsync task because the file private points to memory allocated on stack by the direct IO task and it may be used by the fsync task after the stack was destroyed.

The race happens like this:

1) A user space program opens a file descriptor with O_DIRECT;

2) The program spawns 2 threads using libpthread for example;

3) One of the threads uses the file descriptor to do direct IO writes, while the other calls fsync using the same file descriptor.

4) Call task A the thread doing direct IO writes and task B the thread doing fsyncs;

5) Task A does a direct IO write, and at btrfsdirectwrite() sets the file's private to an on stack allocated private with the member 'fsyncskipinode_lock' set to true;

6) Task B enters btrfssyncfile() and sees that there's a private structure associated to the file which has 'fsyncskipinode_lock' set to true, so it skips locking the inode's VFS lock;

7) Task A completes the direct IO write, and resets the file's private to NULL since it had no prior private and our private was stack allocated. Then it unlocks the inode's VFS lock;

8) Task B enters btrfsgetorderedextentsfor_logging(), then the assertion that checks the inode's VFS lock is held fails, since task B never locked it and task A has already unlocked it.

The stack trace produced is the following:

assertion failed: inodeislocked(&inode->vfsinode), in fs/btrfs/ordered-data.c:983 ------------[ cut here ]------------ kernel BUG at fs/btrfs/ordered-data.c:983! Oops: invalid opcode: 0000 [#1] PREEMPT SMP PTI CPU: 9 PID: 5072 Comm: worker Tainted: G U OE 6.10.5-1-default #1 openSUSE Tumbleweed 69f48d427608e1c09e60ea24c6c55e2ca1b049e8 Hardware name: Acer Predator PH315-52/CoviniCFS, BIOS V1.12 07/28/2020 RIP: 0010:btrfsgetorderedextentsforlogging.cold+0x1f/0x42 [btrfs] Code: 50 d6 86 c0 e8 (...) RSP: 0018:ffff9e4a03dcfc78 EFLAGS: 00010246 RAX: 0000000000000054 RBX: ffff9078a9868e98 RCX: 0000000000000000 RDX: 0000000000000000 RSI: ffff907dce4a7800 RDI: ffff907dce4a7800 RBP: ffff907805518800 R08: 0000000000000000 R09: ffff9e4a03dcfb38 R10: ffff9e4a03dcfb30 R11: 0000000000000003 R12: ffff907684ae7800 R13: 0000000000000001 R14: ffff90774646b600 R15: 0000000000000000 FS: 00007f04b96006c0(0000) GS:ffff907dce480000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f32acbfc000 CR3: 00000001fd4fa005 CR4: 00000000003726f0 Call Trace: <TASK> ? _diebody.cold+0x14/0x24 ? die+0x2e/0x50 ? dotrap+0xca/0x110 ? doerrortrap+0x6a/0x90 ? btrfsgetorderedextentsforlogging.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] ? excinvalidop+0x50/0x70 ? btrfsgetorderedextentsforlogging.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] ? asmexcinvalidop+0x1a/0x20 ? btrfsgetorderedextentsforlogging.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] ? btrfsgetorderedextentsforlogging.cold+0x1f/0x42 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] btrfssyncfile+0x21a/0x4d0 [btrfs bb26272d49b4cdc847cf3f7faadd459b62caee9a] ? _seccompfilter+0x31d/0x4f0 _x64sysfdatasync+0x4f/0x90 dosyscall64+0x82/0x160 ? dofutex+0xcb/0x190 ? _x64sysfutex+0x10e/0x1d0 ? switchfpureturn+0x4f/0xd0 ? syscallexittousermode+0x72/0x220 ? dosyscall64+0x8e/0x160 ? syscallexittousermod ---truncated---

References

Affected packages

Git / git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git

Affected ranges

Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
4e17707035a65f6e5b2a4d987a308cf8ed8c5ad1
Fixed
d116a0b0e02f395cedfb8c725bd67480aa7c428c
Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
6cae8d04d8b3d1ecfadcaa989e673f6f73349ed5
Fixed
cd3087582e4fa36e89be4e6f859e75a4400292b4
Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
0a108bde616a7017653385b5a12111015051a294
Fixed
7b5595f33c3c273613b590892a578d78186bb400
Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
3831170f740685fddc8f6aa57a83ad0fef4711bf
Fixed
01681aa609b5f110502f56c4e3b2938efcf4a5bc
Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
939b656bc8ab203fdbde26ccac22bcb7f0985be5
Fixed
cd9253c23aedd61eb5ff11f37a36247cd46faf86

Affected versions

v5.*

v5.15.165
v5.15.166

v6.*

v6.1.105
v6.1.106
v6.1.107
v6.1.108
v6.1.109
v6.10
v6.10.5
v6.10.6
v6.10.7
v6.10.8
v6.10.9
v6.11-rc1
v6.11-rc2
v6.11-rc3
v6.6.46
v6.6.47
v6.6.48
v6.6.49
v6.6.50

Database specific

{
    "vanir_signatures": [
        {
            "signature_type": "Line",
            "target": {
                "file": "fs/btrfs/ctree.h"
            },
            "signature_version": "v1",
            "digest": {
                "threshold": 0.9,
                "line_hashes": [
                    "110129659056876723227335716936587208590",
                    "156963969675276727760225180313420632853",
                    "200888915436791118345828673396931967885",
                    "199650782599122212453647439145332365868"
                ]
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@01681aa609b5f110502f56c4e3b2938efcf4a5bc",
            "id": "CVE-2024-46734-0471ec64"
        },
        {
            "signature_type": "Function",
            "target": {
                "file": "fs/btrfs/file.c",
                "function": "btrfs_sync_file"
            },
            "signature_version": "v1",
            "digest": {
                "length": 2859.0,
                "function_hash": "249559693356618297604241919109123112874"
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@cd9253c23aedd61eb5ff11f37a36247cd46faf86",
            "id": "CVE-2024-46734-067df687"
        },
        {
            "signature_type": "Line",
            "target": {
                "file": "fs/btrfs/file.c"
            },
            "signature_version": "v1",
            "digest": {
                "threshold": 0.9,
                "line_hashes": [
                    "9840301257911408768406741591213870924",
                    "74627833271267030869524030499003934170",
                    "189518991434746553242000206329127867604",
                    "52959979559006093943266066622380873402",
                    "233368595162145607958376684160533872153",
                    "77995104677573993295658023107502916085",
                    "307850450116671281638414136423679396195",
                    "8364395971945898952780617422515327788",
                    "150873134872615516453877259967483958515",
                    "219476909934538392733615349856080414723",
                    "179364341176277854043415243742758295977",
                    "283113882106152744656800705176845652564",
                    "41274451616622245452559196514704414090",
                    "237066617892320884996366273356516012496",
                    "130739133666746953418053316862901794499",
                    "93043139078903101514868407356487631831",
                    "99726119056369719160693482521396628338",
                    "113329134150057255883922397639981218350",
                    "66770895118095499544486906338126894784",
                    "237375937440328348388971617912779548163",
                    "266750106174130222442013781100444301344",
                    "234095150338281701967058230613211505812"
                ]
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@7b5595f33c3c273613b590892a578d78186bb400",
            "id": "CVE-2024-46734-18cbe91a"
        },
        {
            "signature_type": "Line",
            "target": {
                "file": "fs/btrfs/file.c"
            },
            "signature_version": "v1",
            "digest": {
                "threshold": 0.9,
                "line_hashes": [
                    "9840301257911408768406741591213870924",
                    "74627833271267030869524030499003934170",
                    "189518991434746553242000206329127867604",
                    "52959979559006093943266066622380873402",
                    "233368595162145607958376684160533872153",
                    "77995104677573993295658023107502916085",
                    "307850450116671281638414136423679396195",
                    "8364395971945898952780617422515327788",
                    "150873134872615516453877259967483958515",
                    "219476909934538392733615349856080414723",
                    "179364341176277854043415243742758295977",
                    "283113882106152744656800705176845652564",
                    "41274451616622245452559196514704414090",
                    "237066617892320884996366273356516012496",
                    "130739133666746953418053316862901794499",
                    "93043139078903101514868407356487631831",
                    "99726119056369719160693482521396628338",
                    "113329134150057255883922397639981218350",
                    "66770895118095499544486906338126894784",
                    "237375937440328348388971617912779548163",
                    "266750106174130222442013781100444301344",
                    "234095150338281701967058230613211505812"
                ]
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@d116a0b0e02f395cedfb8c725bd67480aa7c428c",
            "id": "CVE-2024-46734-22effb50"
        },
        {
            "signature_type": "Function",
            "target": {
                "file": "fs/btrfs/direct-io.c",
                "function": "btrfs_direct_write"
            },
            "signature_version": "v1",
            "digest": {
                "length": 2484.0,
                "function_hash": "91103437176325583743710175119340888608"
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@cd9253c23aedd61eb5ff11f37a36247cd46faf86",
            "id": "CVE-2024-46734-33733add"
        },
        {
            "signature_type": "Line",
            "target": {
                "file": "fs/btrfs/file.c"
            },
            "signature_version": "v1",
            "digest": {
                "threshold": 0.9,
                "line_hashes": [
                    "9840301257911408768406741591213870924",
                    "74627833271267030869524030499003934170",
                    "189518991434746553242000206329127867604",
                    "52959979559006093943266066622380873402",
                    "233368595162145607958376684160533872153",
                    "77995104677573993295658023107502916085",
                    "307850450116671281638414136423679396195",
                    "8364395971945898952780617422515327788",
                    "150873134872615516453877259967483958515",
                    "219476909934538392733615349856080414723",
                    "179364341176277854043415243742758295977",
                    "283113882106152744656800705176845652564",
                    "41274451616622245452559196514704414090",
                    "237066617892320884996366273356516012496",
                    "130739133666746953418053316862901794499",
                    "93043139078903101514868407356487631831",
                    "99726119056369719160693482521396628338",
                    "113329134150057255883922397639981218350",
                    "66770895118095499544486906338126894784",
                    "237375937440328348388971617912779548163",
                    "266750106174130222442013781100444301344",
                    "234095150338281701967058230613211505812"
                ]
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@cd3087582e4fa36e89be4e6f859e75a4400292b4",
            "id": "CVE-2024-46734-3ab3a3a1"
        },
        {
            "signature_type": "Function",
            "target": {
                "file": "fs/btrfs/file.c",
                "function": "btrfs_direct_write"
            },
            "signature_version": "v1",
            "digest": {
                "length": 2486.0,
                "function_hash": "152525527919432733096961547265464565004"
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@7b5595f33c3c273613b590892a578d78186bb400",
            "id": "CVE-2024-46734-3f0c6849"
        },
        {
            "signature_type": "Line",
            "target": {
                "file": "fs/btrfs/direct-io.c"
            },
            "signature_version": "v1",
            "digest": {
                "threshold": 0.9,
                "line_hashes": [
                    "231831053205514467534829442833130274397",
                    "273709912568832748311073627703860695592",
                    "189518991434746553242000206329127867604",
                    "52959979559006093943266066622380873402",
                    "233368595162145607958376684160533872153",
                    "77995104677573993295658023107502916085",
                    "307850450116671281638414136423679396195",
                    "124746741141669588020304462583729388090",
                    "209901732240126457621593330747643336502",
                    "232006315061074662282062799069906444236",
                    "258730296419938631619238972468874828817",
                    "283113882106152744656800705176845652564",
                    "61010725429708706850571409456305938255",
                    "217794339283430077045544755519831693722"
                ]
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@cd9253c23aedd61eb5ff11f37a36247cd46faf86",
            "id": "CVE-2024-46734-42cf3d68"
        },
        {
            "signature_type": "Line",
            "target": {
                "file": "fs/btrfs/ctree.h"
            },
            "signature_version": "v1",
            "digest": {
                "threshold": 0.9,
                "line_hashes": [
                    "110129659056876723227335716936587208590",
                    "156963969675276727760225180313420632853",
                    "200888915436791118345828673396931967885",
                    "199650782599122212453647439145332365868"
                ]
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@cd9253c23aedd61eb5ff11f37a36247cd46faf86",
            "id": "CVE-2024-46734-432351c8"
        },
        {
            "signature_type": "Line",
            "target": {
                "file": "fs/btrfs/file.c"
            },
            "signature_version": "v1",
            "digest": {
                "threshold": 0.9,
                "line_hashes": [
                    "231831053205514467534829442833130274397",
                    "273709912568832748311073627703860695592",
                    "189518991434746553242000206329127867604",
                    "52959979559006093943266066622380873402",
                    "233368595162145607958376684160533872153",
                    "77995104677573993295658023107502916085",
                    "307850450116671281638414136423679396195",
                    "124746741141669588020304462583729388090",
                    "209901732240126457621593330747643336502",
                    "232006315061074662282062799069906444236",
                    "258730296419938631619238972468874828817",
                    "283113882106152744656800705176845652564",
                    "61010725429708706850571409456305938255",
                    "217794339283430077045544755519831693722",
                    "130739133666746953418053316862901794499",
                    "93043139078903101514868407356487631831",
                    "99726119056369719160693482521396628338",
                    "125503529794924800571932850200789090422",
                    "66770895118095499544486906338126894784",
                    "237375937440328348388971617912779548163",
                    "266750106174130222442013781100444301344",
                    "234095150338281701967058230613211505812"
                ]
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@01681aa609b5f110502f56c4e3b2938efcf4a5bc",
            "id": "CVE-2024-46734-5cba5607"
        },
        {
            "signature_type": "Function",
            "target": {
                "file": "fs/btrfs/file.c",
                "function": "btrfs_sync_file"
            },
            "signature_version": "v1",
            "digest": {
                "length": 2525.0,
                "function_hash": "65651563015318626190662847071764054259"
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@d116a0b0e02f395cedfb8c725bd67480aa7c428c",
            "id": "CVE-2024-46734-5d6e6059"
        },
        {
            "signature_type": "Function",
            "target": {
                "file": "fs/btrfs/file.c",
                "function": "btrfs_direct_write"
            },
            "signature_version": "v1",
            "digest": {
                "length": 2395.0,
                "function_hash": "104293837859862927433754932342948094021"
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@cd3087582e4fa36e89be4e6f859e75a4400292b4",
            "id": "CVE-2024-46734-8fcb14a7"
        },
        {
            "signature_type": "Line",
            "target": {
                "file": "fs/btrfs/ctree.h"
            },
            "signature_version": "v1",
            "digest": {
                "threshold": 0.9,
                "line_hashes": [
                    "70995258273178671382933728890352925449",
                    "223418351065993534149309116994911529076",
                    "9956050860181176286388218049539675910",
                    "199650782599122212453647439145332365868"
                ]
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@d116a0b0e02f395cedfb8c725bd67480aa7c428c",
            "id": "CVE-2024-46734-92adfc01"
        },
        {
            "signature_type": "Function",
            "target": {
                "file": "fs/btrfs/file.c",
                "function": "btrfs_sync_file"
            },
            "signature_version": "v1",
            "digest": {
                "length": 2598.0,
                "function_hash": "18688460180567917207894917614535731242"
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@cd3087582e4fa36e89be4e6f859e75a4400292b4",
            "id": "CVE-2024-46734-94933d00"
        },
        {
            "signature_type": "Function",
            "target": {
                "file": "fs/btrfs/file.c",
                "function": "btrfs_direct_write"
            },
            "signature_version": "v1",
            "digest": {
                "length": 2478.0,
                "function_hash": "217461713737428160871409960332583982442"
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@01681aa609b5f110502f56c4e3b2938efcf4a5bc",
            "id": "CVE-2024-46734-98ccbef7"
        },
        {
            "signature_type": "Line",
            "target": {
                "file": "fs/btrfs/ctree.h"
            },
            "signature_version": "v1",
            "digest": {
                "threshold": 0.9,
                "line_hashes": [
                    "70995258273178671382933728890352925449",
                    "223418351065993534149309116994911529076",
                    "9956050860181176286388218049539675910",
                    "199650782599122212453647439145332365868"
                ]
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@cd3087582e4fa36e89be4e6f859e75a4400292b4",
            "id": "CVE-2024-46734-9e5c26ab"
        },
        {
            "signature_type": "Function",
            "target": {
                "file": "fs/btrfs/file.c",
                "function": "btrfs_sync_file"
            },
            "signature_version": "v1",
            "digest": {
                "length": 2650.0,
                "function_hash": "242807470428598336711600070129263591777"
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@7b5595f33c3c273613b590892a578d78186bb400",
            "id": "CVE-2024-46734-9f16ee59"
        },
        {
            "signature_type": "Function",
            "target": {
                "file": "fs/btrfs/file.c",
                "function": "btrfs_sync_file"
            },
            "signature_version": "v1",
            "digest": {
                "length": 3010.0,
                "function_hash": "234024923989984537274278081594399205426"
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@01681aa609b5f110502f56c4e3b2938efcf4a5bc",
            "id": "CVE-2024-46734-c453818f"
        },
        {
            "signature_type": "Line",
            "target": {
                "file": "fs/btrfs/ctree.h"
            },
            "signature_version": "v1",
            "digest": {
                "threshold": 0.9,
                "line_hashes": [
                    "110129659056876723227335716936587208590",
                    "156963969675276727760225180313420632853",
                    "200888915436791118345828673396931967885",
                    "199650782599122212453647439145332365868"
                ]
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@7b5595f33c3c273613b590892a578d78186bb400",
            "id": "CVE-2024-46734-c5f3e13e"
        },
        {
            "signature_type": "Line",
            "target": {
                "file": "fs/btrfs/file.c"
            },
            "signature_version": "v1",
            "digest": {
                "threshold": 0.9,
                "line_hashes": [
                    "130739133666746953418053316862901794499",
                    "93043139078903101514868407356487631831",
                    "196133504522237528617280846254639016515",
                    "279972829002536691214077831633833952103",
                    "66770895118095499544486906338126894784",
                    "237375937440328348388971617912779548163",
                    "266750106174130222442013781100444301344",
                    "234095150338281701967058230613211505812"
                ]
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@cd9253c23aedd61eb5ff11f37a36247cd46faf86",
            "id": "CVE-2024-46734-e51d81bd"
        },
        {
            "signature_type": "Function",
            "target": {
                "file": "fs/btrfs/file.c",
                "function": "btrfs_direct_write"
            },
            "signature_version": "v1",
            "digest": {
                "length": 2236.0,
                "function_hash": "50212956216809781449165163047043991357"
            },
            "deprecated": false,
            "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@d116a0b0e02f395cedfb8c725bd67480aa7c428c",
            "id": "CVE-2024-46734-f0132efc"
        }
    ]
}

Linux / Kernel

Package

Name
Kernel

Affected ranges

Type
ECOSYSTEM
Events
Introduced
5.15.165
Fixed
5.15.167
Type
ECOSYSTEM
Events
Introduced
6.1.105
Fixed
6.1.110
Type
ECOSYSTEM
Events
Introduced
6.6.46
Fixed
6.6.51
Type
ECOSYSTEM
Events
Introduced
6.10.5
Fixed
6.10.10