CVE-2023-54158

Source
https://cve.org/CVERecord?id=CVE-2023-54158
Import Source
https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2023-54158.json
JSON Data
https://api.osv.dev/v1/vulns/CVE-2023-54158
Downstream
Published
2025-12-24T13:07:07.438Z
Modified
2026-04-02T09:45:38.880483Z
Summary
btrfs: don't free qgroup space unless specified
Details

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

btrfs: don't free qgroup space unless specified

Boris noticed in his simple quotas testing that he was getting a leak with Sweet Tea's change to subvol create that stopped doing a transaction commit. This was just a side effect of that change.

In the delayed inode code we have an optimization that will free extra reservations if we think we can pack a dir item into an already modified leaf. Previously this wouldn't be triggered in the subvolume create case because we'd commit the transaction, it was still possible but much harder to trigger. It could actually be triggered if we did a mkdir && subvol create with qgroups enabled.

This occurs because in btrfsinsertdelayeddirindex(), which gets called when we're adding the dir item, we do the following:

btrfsblockrsvrelease(fsinfo, trans->block_rsv, bytes, NULL);

if we're able to skip reserving space.

The problem here is that trans->block_rsv points at the temporary block rsv for the subvolume create, which has qgroup reservations in the block rsv.

This is a problem because btrfsblockrsv_release() will do the following:

if (blockrsv->qgrouprsvreserved >= blockrsv->qgrouprsvsize) { qgrouptorelease = blockrsv->qgrouprsvreserved - blockrsv->qgrouprsvsize; blockrsv->qgrouprsvreserved = blockrsv->qgrouprsvsize; }

The temporary block rsv just has ->qgrouprsvreserved set, ->qgrouprsvsize == 0. The optimization in btrfsinsertdelayeddirindex() sets ->qgrouprsvreserved = 0. Then later on when we call btrfssubvolumerelease_metadata() which has

btrfsblockrsvrelease(fsinfo, rsv, (u64)-1, &qgrouptorelease); btrfsqgroupconvertreservedmeta(root, qgrouptorelease);

qgrouptorelease is set to 0, and we do not convert the reserved metadata space.

The problem here is that the block rsv code has been unconditionally messing with ->qgrouprsvreserved, because the main place this is used is delalloc, and any time we call btrfsblockrsvrelease() we do it with qgroupto_release set, and thus do the proper accounting.

The subvolume code is the only other code that uses the qgroup reservation stuff, but it's intermingled with the above optimization, and thus was getting its reservation freed out from underneath it and thus leaking the reserved space.

The solution is to simply not mess with the qgroup reservations if we don't have qgrouptorelease set. This works with the existing code as anything that messes with the delalloc reservations always have qgrouptorelease set. This fixes the leak that Boris was observing.

Database specific
{
    "cna_assigner": "Linux",
    "osv_generated_from": "https://github.com/CVEProject/cvelistV5/tree/main/cves/2023/54xxx/CVE-2023-54158.json"
}
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
ff6bc37eb7f6e7b052e50c13a480e1080b3ec07a
Fixed
1e05bf5e80bb1161b7294c9ce5292b26232ab853
Fixed
148b16cd30b202999ec5b534e3e5d8ab4b766f21
Fixed
f264be24146bee2d652010a18ae2517df5856261
Fixed
15e877e5923ec6d6caa5e447dcc4b79a8ff7cc53
Fixed
04ff6bd0317735791ef3e443c7c89f3c0dda548d
Fixed
478bd15f46b6e3aae78aac4f3788697f1546eea6
Fixed
d246331b78cbef86237f9c22389205bc9b4e1cc1

Database specific

source
"https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2023-54158.json"

Linux / Kernel

Package

Name
Kernel

Affected ranges

Type
ECOSYSTEM
Events
Introduced
4.17.0
Fixed
5.4.243
Type
ECOSYSTEM
Events
Introduced
5.5.0
Fixed
5.10.180
Type
ECOSYSTEM
Events
Introduced
5.11.0
Fixed
5.15.112
Type
ECOSYSTEM
Events
Introduced
5.16.0
Fixed
6.1.29
Type
ECOSYSTEM
Events
Introduced
6.2.0
Fixed
6.2.16
Type
ECOSYSTEM
Events
Introduced
6.3.0
Fixed
6.3.3

Database specific

source
"https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2023-54158.json"