CVE-2022-49898

Source
https://nvd.nist.gov/vuln/detail/CVE-2022-49898
Import Source
https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2022-49898.json
JSON Data
https://api.osv.dev/v1/vulns/CVE-2022-49898
Downstream
Related
Published
2025-05-01T14:10:44Z
Modified
2025-10-21T11:42:29.081342Z
Summary
btrfs: fix tree mod log mishandling of reallocated nodes
Details

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

btrfs: fix tree mod log mishandling of reallocated nodes

We have been seeing the following panic in production

kernel BUG at fs/btrfs/tree-mod-log.c:677! invalid opcode: 0000 [#1] SMP RIP: 0010:treemodlogrewind+0x1b4/0x200 RSP: 0000:ffffc9002c02f890 EFLAGS: 00010293 RAX: 0000000000000003 RBX: ffff8882b448c700 RCX: 0000000000000000 RDX: 0000000000008000 RSI: 00000000000000a7 RDI: ffff88877d831c00 RBP: 0000000000000002 R08: 000000000000009f R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000100c40 R12: 0000000000000001 R13: ffff8886c26d6a00 R14: ffff88829f5424f8 R15: ffff88877d831a00 FS: 00007fee1d80c780(0000) GS:ffff8890400c0000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007fee1963a020 CR3: 0000000434f33002 CR4: 00000000007706e0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 PKRU: 55555554 Call Trace: btrfsgetoldroot+0x12b/0x420 btrfssearcholdslot+0x64/0x2f0 ? treemodlogoldestroot+0x3d/0xf0 resolveindirectref+0xfd/0x660 ? ulistalloc+0x31/0x60 ? kmemcachealloctrace+0x114/0x2c0 findparentnodes+0x97a/0x17e0 ? ulistalloc+0x30/0x60 btrfsfindallrootssafe+0x97/0x150 iterateextentinodes+0x154/0x370 ? btrfssearchpathintree+0x240/0x240 iterateinodesfromlogical+0x98/0xd0 ? btrfssearchpathintree+0x240/0x240 btrfsioctllogicaltoino+0xd9/0x180 btrfsioctl+0xe2/0x2ec0 ? _modmemcglruvecstate+0x3d/0x280 ? dosysopenat2+0x6d/0x140 ? kretprobedispatcher+0x47/0x70 ? kretproberethookhandler+0x38/0x50 ? rethooktrampolinehandler+0x82/0x140 ? archrethooktrampolinecallback+0x3b/0x50 ? kmemcachefree+0xfb/0x270 ? dosysopenat2+0xd5/0x140 _x64sysioctl+0x71/0xb0 dosyscall_64+0x2d/0x40

Which is this code in treemodlog_rewind()

switch (tm->op) {
    case BTRFS_MOD_LOG_KEY_REMOVE_WHILE_FREEING:
    BUG_ON(tm->slot < n);

This occurs because we replay the nodes in order that they happened, and when we do a REPLACE we will log a REMOVEWHILEFREEING for every slot, starting at 0. 'n' here is the number of items in this block, which in this case was 1, but we had 2 REMOVEWHILEFREEING operations.

The actual root cause of this was that we were replaying operations for a block that shouldn't have been replayed. Consider the following sequence of events

  1. We have an already modified root, and we do a btrfsgettreemodseq().
  2. We begin removing items from this root, triggering KEY_REPLACE for it's child slots.
  3. We remove one of the 2 children this root node points to, thus triggering the root node promotion of the remaining child, and freeing this node.
  4. We modify a new root, and re-allocate the above node to the root node of this other root.

The tree mod log looks something like this

logical 0   op KEY_REPLACE (slot 1)         seq 2
logical 0   op KEY_REMOVE (slot 1)          seq 3
logical 0   op KEY_REMOVE_WHILE_FREEING (slot 0)    seq 4
logical 4096    op LOG_ROOT_REPLACE (old logical 0) seq 5
logical 8192    op KEY_REMOVE_WHILE_FREEING (slot 1)    seq 6
logical 8192    op KEY_REMOVE_WHILE_FREEING (slot 0)    seq 7
logical 0   op LOG_ROOT_REPLACE (old logical 8192)  seq 8

From here the bug is triggered by the following steps

  1. Call btrfsgetoldroot() on the newroot.
  2. We call treemodlogoldestroot(btrfsrootnode(new_root)), which is currently logical 0.
  3. treemodlogoldestroot() calls treemodlogsearcholdest(), which gives us the KEYREPLACE seq 2, and since that's not a LOGROOTREPLACE we incorrectly believe that we don't have an old root, because we expect that the most recent change should be a LOGROOT_REPLACE.
  4. Back in treemodlogoldestroot() we don't have a LOGROOTREPLACE, so we don't set old_root, we simply use our e ---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
bd989ba359f2acb8bc5f5490e19010fc0a6f8356
Fixed
007058eb8292efc4c88f921752194b83269da085
Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
bd989ba359f2acb8bc5f5490e19010fc0a6f8356
Fixed
52b2b65c9eb56fd829dda323786db828627ff7e6
Type
GIT
Repo
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
Events
Introduced
bd989ba359f2acb8bc5f5490e19010fc0a6f8356
Fixed
968b71583130b6104c9f33ba60446d598e327a8b

Affected versions

v3.*

v3.10
v3.10-rc1
v3.10-rc2
v3.10-rc3
v3.10-rc4
v3.10-rc5
v3.10-rc6
v3.10-rc7
v3.11
v3.11-rc1
v3.11-rc2
v3.11-rc3
v3.11-rc4
v3.11-rc5
v3.11-rc6
v3.11-rc7
v3.12
v3.12-rc1
v3.12-rc2
v3.12-rc3
v3.12-rc4
v3.12-rc5
v3.12-rc6
v3.12-rc7
v3.13
v3.13-rc1
v3.13-rc2
v3.13-rc3
v3.13-rc4
v3.13-rc5
v3.13-rc6
v3.13-rc7
v3.13-rc8
v3.14
v3.14-rc1
v3.14-rc2
v3.14-rc3
v3.14-rc4
v3.14-rc5
v3.14-rc6
v3.14-rc7
v3.14-rc8
v3.15
v3.15-rc1
v3.15-rc2
v3.15-rc3
v3.15-rc4
v3.15-rc5
v3.15-rc6
v3.15-rc7
v3.15-rc8
v3.16
v3.16-rc1
v3.16-rc2
v3.16-rc3
v3.16-rc4
v3.16-rc5
v3.16-rc6
v3.16-rc7
v3.17
v3.17-rc1
v3.17-rc2
v3.17-rc3
v3.17-rc4
v3.17-rc5
v3.17-rc6
v3.17-rc7
v3.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.9-rc3
v4.9-rc4
v4.9-rc5
v4.9-rc6
v4.9-rc7
v4.9-rc8

v5.*

v5.0
v5.0-rc1
v5.0-rc2
v5.0-rc3
v5.0-rc4
v5.0-rc5
v5.0-rc6
v5.0-rc7
v5.0-rc8
v5.1
v5.1-rc1
v5.1-rc2
v5.1-rc3
v5.1-rc4
v5.1-rc5
v5.1-rc6
v5.1-rc7
v5.10
v5.10-rc1
v5.10-rc2
v5.10-rc3
v5.10-rc4
v5.10-rc5
v5.10-rc6
v5.10-rc7
v5.11
v5.11-rc1
v5.11-rc2
v5.11-rc3
v5.11-rc4
v5.11-rc5
v5.11-rc6
v5.11-rc7
v5.12
v5.12-rc1
v5.12-rc1-dontuse
v5.12-rc2
v5.12-rc3
v5.12-rc4
v5.12-rc5
v5.12-rc6
v5.12-rc7
v5.12-rc8
v5.13
v5.13-rc1
v5.13-rc2
v5.13-rc3
v5.13-rc4
v5.13-rc5
v5.13-rc6
v5.13-rc7
v5.14
v5.14-rc1
v5.14-rc2
v5.14-rc3
v5.14-rc4
v5.14-rc5
v5.14-rc6
v5.14-rc7
v5.15
v5.15-rc1
v5.15-rc2
v5.15-rc3
v5.15-rc4
v5.15-rc5
v5.15-rc6
v5.15-rc7
v5.15.1
v5.15.10
v5.15.11
v5.15.12
v5.15.13
v5.15.14
v5.15.15
v5.15.16
v5.15.17
v5.15.18
v5.15.19
v5.15.2
v5.15.20
v5.15.21
v5.15.22
v5.15.23
v5.15.24
v5.15.25
v5.15.26
v5.15.27
v5.15.28
v5.15.29
v5.15.3
v5.15.30
v5.15.31
v5.15.32
v5.15.33
v5.15.34
v5.15.35
v5.15.36
v5.15.37
v5.15.38
v5.15.39
v5.15.4
v5.15.40
v5.15.41
v5.15.42
v5.15.43
v5.15.44
v5.15.45
v5.15.46
v5.15.47
v5.15.48
v5.15.49
v5.15.5
v5.15.50
v5.15.51
v5.15.52
v5.15.53
v5.15.54
v5.15.55
v5.15.56
v5.15.57
v5.15.58
v5.15.59
v5.15.6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6.0
v6.0-rc1
v6.0-rc2
v6.0-rc3
v6.0-rc4
v6.0-rc5
v6.0-rc6
v6.0-rc7
v6.0.1
v6.0.2
v6.0.3
v6.0.4
v6.0.5
v6.0.6
v6.0.7

Database specific

vanir_signatures

[
    {
        "signature_type": "Function",
        "digest": {
            "function_hash": "60837229017278797549711257550944049445",
            "length": 1465.0
        },
        "target": {
            "file": "fs/btrfs/extent-tree.c",
            "function": "btrfs_free_tree_block"
        },
        "signature_version": "v1",
        "id": "CVE-2022-49898-10e0ede0",
        "deprecated": false,
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@52b2b65c9eb56fd829dda323786db828627ff7e6"
    },
    {
        "signature_type": "Function",
        "digest": {
            "function_hash": "60837229017278797549711257550944049445",
            "length": 1465.0
        },
        "target": {
            "file": "fs/btrfs/extent-tree.c",
            "function": "btrfs_free_tree_block"
        },
        "signature_version": "v1",
        "id": "CVE-2022-49898-1b6644f2",
        "deprecated": false,
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@968b71583130b6104c9f33ba60446d598e327a8b"
    },
    {
        "signature_type": "Function",
        "digest": {
            "function_hash": "60837229017278797549711257550944049445",
            "length": 1465.0
        },
        "target": {
            "file": "fs/btrfs/extent-tree.c",
            "function": "btrfs_free_tree_block"
        },
        "signature_version": "v1",
        "id": "CVE-2022-49898-6c8ffa3f",
        "deprecated": false,
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@007058eb8292efc4c88f921752194b83269da085"
    },
    {
        "signature_type": "Line",
        "digest": {
            "threshold": 0.9,
            "line_hashes": [
                "219203772173580669874765262363104896266",
                "139771473168680060125431246535267569859",
                "156801867415486688925045571838867169863",
                "230733125820538243050179549115018792878",
                "138376130846992393350017815435887225677"
            ]
        },
        "target": {
            "file": "fs/btrfs/extent-tree.c"
        },
        "signature_version": "v1",
        "id": "CVE-2022-49898-c9523de8",
        "deprecated": false,
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@968b71583130b6104c9f33ba60446d598e327a8b"
    },
    {
        "signature_type": "Line",
        "digest": {
            "threshold": 0.9,
            "line_hashes": [
                "219203772173580669874765262363104896266",
                "139771473168680060125431246535267569859",
                "156801867415486688925045571838867169863",
                "230733125820538243050179549115018792878",
                "138376130846992393350017815435887225677"
            ]
        },
        "target": {
            "file": "fs/btrfs/extent-tree.c"
        },
        "signature_version": "v1",
        "id": "CVE-2022-49898-dfea40d6",
        "deprecated": false,
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@52b2b65c9eb56fd829dda323786db828627ff7e6"
    },
    {
        "signature_type": "Line",
        "digest": {
            "threshold": 0.9,
            "line_hashes": [
                "219203772173580669874765262363104896266",
                "139771473168680060125431246535267569859",
                "156801867415486688925045571838867169863",
                "230733125820538243050179549115018792878",
                "138376130846992393350017815435887225677"
            ]
        },
        "target": {
            "file": "fs/btrfs/extent-tree.c"
        },
        "signature_version": "v1",
        "id": "CVE-2022-49898-fa925888",
        "deprecated": false,
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@007058eb8292efc4c88f921752194b83269da085"
    }
]

Linux / Kernel

Package

Name
Kernel

Affected ranges

Type
ECOSYSTEM
Events
Introduced
3.5.0
Fixed
5.15.78
Type
ECOSYSTEM
Events
Introduced
5.16.0
Fixed
6.0.8