CVE-2022-49850: nilfs2: fix deadlock in nilfs_count_free_blocks()
In the Linux kernel, the following vulnerability has been resolved:
nilfs2: fix deadlock in nilfscountfreeblocks()
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() nilfscountfreeblocks() 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 nilfscountfreeblocks().
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 nilfscountfreeblocks().
Affected Software
Remediation
Event History
Frequently Asked Questions
What is the severity of CVE-2022-49850?
CVE-2022-49850 has a severity rating that indicates a moderate risk to systems using the affected Linux kernel versions.
How do I fix CVE-2022-49850?
To fix CVE-2022-49850, update your Linux kernel to a version that includes the patches addressing this vulnerability.
Which Linux kernel versions are affected by CVE-2022-49850?
CVE-2022-49850 affects multiple versions of the Linux kernel ranging from 2.6.38 to 6.1-rc4.
What type of vulnerability is CVE-2022-49850?
CVE-2022-49850 is a semaphore deadlock vulnerability that can result in system hangs under specific conditions.
Is CVE-2022-49850 a serious issue for my Linux system?
Yes, CVE-2022-49850 is considered a serious issue because it can lead to deadlock situations, affecting system availability.