CVE-2022-49850

Source
https://cve.org/CVERecord?id=CVE-2022-49850
Import Source
https://storage.googleapis.com/osv-test-cve-osv-conversion/osv-output/CVE-2022-49850.json
JSON Data
https://api.test.osv.dev/v1/vulns/CVE-2022-49850
Downstream
Related
Published
2025-05-01T14:10:05.167Z
Modified
2026-04-03T13:14:21.382932694Z
Severity
  • 5.5 (Medium) CVSS_V3 - CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H CVSS Calculator
Summary
nilfs2: fix deadlock in nilfs_count_free_blocks()
Details

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

nilfs2: fix deadlock in nilfscountfree_blocks()

A semaphore deadlock can occur if nilfsgetblock() detects metadata corruption while locating data blocks and a superblock writeback occurs at the same time:

task 1 task 2 ------ ------ * A file operation * nilfstruncate() nilfsgetblock() downread(rwsem A) <-- nilfsbmaplookupcontig() ... genericshutdownsuper() nilfsputsuper() * Prepare to write superblock * downwrite(rwsem B) <-- nilfscleanupsuper() * Detect b-tree corruption * nilfssetlogcursor() nilfsbmapconverterror() nilfscountfree_blocks() _nilfserror() downread(rwsem A) <-- nilfsseterror() downwrite(rwsem B) <--

                       *** DEADLOCK ***

Here, nilfsgetblock() readlocks rwsem A (= NILFSMDT(datinode)->misem) and then calls nilfsbmaplookupcontig(), but if it fails due to metadata corruption, __nilfserror() is called from nilfsbmapconverterror() inside the lock section.

Since __nilfserror() calls nilfsseterror() unless the filesystem is read-only and nilfsseterror() attempts to writelock rwsem B (= nilfs->nssem) to write back superblock exclusively, hierarchical lock acquisition occurs in the order rwsem A -> rwsem B.

Now, if another task starts updating the superblock, it may writelock rwsem B during the lock sequence above, and can deadlock trying to readlock rwsem A in nilfscountfree_blocks().

However, there is actually no need to take rwsem A in nilfscountfreeblocks() because it, within the lock section, only reads a single integer data on a shared struct with nilfssufilegetncleansegs(). This has been the case after commit aa474a220180 ("nilfs2: add local variable to cache the number of clean segments"), that is, even before this bug was introduced.

So, this resolves the deadlock problem by just not taking the semaphore in nilfscountfree_blocks().

Database specific
{
    "osv_generated_from": "https://github.com/CVEProject/cvelistV5/tree/main/cves/2022/49xxx/CVE-2022-49850.json",
    "cna_assigner": "Linux"
}
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
e828949e5b42bfd234ee537cdb7c5e3a577958a3
Fixed
3c89ca6d3dfa6c09c515807a7a97a521f5d5147e
Fixed
8b4506cff6630bb474bb46a2a75c31e533a756ba
Fixed
f0cc93080d4c09510b74ecba87fd778cca390bb1
Fixed
36ff974b0310771417c0be64b64aa221bd70d63d
Fixed
1d4ff73062096c21b47954d2996b4df259777bda
Fixed
abc082aac0d9b6b926038fc3adb7008306581be2
Fixed
cb029b54953420f7a2d65100f1c5107f14411bdc
Fixed
8ac932a4921a96ca52f61935dbba64ea87bbd5dc

Database specific

source
"https://storage.googleapis.com/osv-test-cve-osv-conversion/osv-output/CVE-2022-49850.json"