{"schemaVersion":1,"url":"https://cve.openhack.com/cve/CVE-2022-49850","id":"CVE-2022-49850","title":"nilfs2: fix deadlock in nilfs_count_free_blocks()","description":"In the Linux kernel, the following vulnerability has been resolved:\n\nnilfs2: fix deadlock in nilfs_count_free_blocks()\n\nA semaphore deadlock can occur if nilfs_get_block() detects metadata\ncorruption while locating data blocks and a superblock writeback occurs at\nthe same time:\n\ntask 1                               task 2\n------                               ------\n* A file operation *\nnilfs_trunc","descriptionLong":"In the Linux kernel, the following vulnerability has been resolved:\n\nnilfs2: fix deadlock in nilfs_count_free_blocks()\n\nA semaphore deadlock can occur if nilfs_get_block() detects metadata\ncorruption while locating data blocks and a superblock writeback occurs at\nthe same time:\n\ntask 1                               task 2\n------                               ------\n* A file operation *\nnilfs_truncate()\n  nilfs_get_block()\n    down_read(rwsem A) <--\n    nilfs_bmap_lookup_contig()\n      ...                            generic_shutdown_super()\n                                       nilfs_put_super()\n                                         * Prepare to write superblock *\n                                         down_write(rwsem B) <--\n                                         nilfs_cleanup_super()\n      * Detect b-tree corruption *         nilfs_set_log_cursor()\n      nilfs_bmap_convert_error()             nilfs_count_free_blocks()\n        __nilfs_error()                        down_read(rwsem A) <--\n          nilfs_set_error()\n            down_write(rwsem B) <--\n\n                           *** DEADLOCK ***\n\nHere, nilfs_get_block() readlocks rwsem A (= NILFS_MDT(dat_inode)->mi_sem)\nand then calls nilfs_bmap_lookup_contig(), but if it fails due to metadata\ncorruption, __nilfs_error() is called from nilfs_bmap_convert_error()\ninside the lock section.\n\nSince __nilfs_error() calls nilfs_set_error() unless the filesystem is\nread-only and nilfs_set_error() attempts to writelock rwsem B (=\nnilfs->ns_sem) to write back superblock exclusively, hierarchical lock\nacquisition occurs in the order rwsem A -> rwsem B.\n\nNow, if another task starts updating the superblock, it may writelock\nrwsem B during the lock sequence above, and can deadlock trying to\nreadlock rwsem A in nilfs_count_free_blocks().\n\nHowever, there is actually no need to take rwsem A in\nnilfs_count_free_blocks() because it, within the lock section, only reads\na single integer data on a shared struct with\nnilfs_sufile_get_ncleansegs().  This has been the case after commit\naa474a220180 (\"nilfs2: add local variable to cache the number of clean\nsegments\"), that is, even before this bug was introduced.\n\nSo, this resolves the deadlock problem by just not taking the semaphore in\nnilfs_count_free_blocks().","published":"2025-05-01T14:10:05.167Z","updated":"2026-10-28T02:30:55.801349824Z","reserved":"2025-05-01T14:05:17.230Z","status":"Modified","rejected":false,"assigner":"Linux","metric":{"version":"3.1","score":5.5,"vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H","rating":"medium","source":"NVD"},"metrics":[{"version":"3.1","score":5.5,"vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H","rating":"medium","source":"NVD"},{"version":"3.1","score":5.5,"vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H","rating":"medium","source":"CISA-ADP"},{"version":"3.1","score":5.5,"vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H","rating":"medium","source":"OSV"}],"rating":"medium","products":["Linux"],"affectedProducts":[{"vendor":"Linux","product":"Linux","defaultStatus":"unaffected","versions":[{"version":"e828949e5b42bfd234ee537cdb7c5e3a577958a3","lessThan":"3c89ca6d3dfa6c09c515807a7a97a521f5d5147e","status":"affected","versionType":"git"},{"version":"e828949e5b42bfd234ee537cdb7c5e3a577958a3","lessThan":"8b4506cff6630bb474bb46a2a75c31e533a756ba","status":"affected","versionType":"git"},{"version":"e828949e5b42bfd234ee537cdb7c5e3a577958a3","lessThan":"f0cc93080d4c09510b74ecba87fd778cca390bb1","status":"affected","versionType":"git"},{"version":"e828949e5b42bfd234ee537cdb7c5e3a577958a3","lessThan":"36ff974b0310771417c0be64b64aa221bd70d63d","status":"affected","versionType":"git"},{"version":"e828949e5b42bfd234ee537cdb7c5e3a577958a3","lessThan":"1d4ff73062096c21b47954d2996b4df259777bda","status":"affected","versionType":"git"},{"version":"e828949e5b42bfd234ee537cdb7c5e3a577958a3","lessThan":"abc082aac0d9b6b926038fc3adb7008306581be2","status":"affected","versionType":"git"},{"version":"e828949e5b42bfd234ee537cdb7c5e3a577958a3","lessThan":"cb029b54953420f7a2d65100f1c5107f14411bdc","status":"affected","versionType":"git"},{"version":"e828949e5b42bfd234ee537cdb7c5e3a577958a3","lessThan":"8ac932a4921a96ca52f61935dbba64ea87bbd5dc","status":"affected","versionType":"git"}],"platforms":[]},{"vendor":"Linux","product":"Linux","defaultStatus":"affected","versions":[{"version":"2.6.38","status":"affected"},{"version":"0","lessThan":"2.6.38","status":"unaffected","versionType":"semver"},{"version":"4.9.334","lessThanOrEqual":"4.9.*","status":"unaffected","versionType":"semver"},{"version":"4.14.300","lessThanOrEqual":"4.14.*","status":"unaffected","versionType":"semver"},{"version":"4.19.267","lessThanOrEqual":"4.19.*","status":"unaffected","versionType":"semver"},{"version":"5.4.225","lessThanOrEqual":"5.4.*","status":"unaffected","versionType":"semver"},{"version":"5.10.155","lessThanOrEqual":"5.10.*","status":"unaffected","versionType":"semver"},{"version":"5.15.79","lessThanOrEqual":"5.15.*","status":"unaffected","versionType":"semver"},{"version":"6.0.9","lessThanOrEqual":"6.0.*","status":"unaffected","versionType":"semver"},{"version":"6.1","lessThanOrEqual":"*","status":"unaffected","versionType":"original_commit_for_fix"}],"platforms":[]}],"packages":[],"cwes":["CWE-667"],"aliases":[],"references":[{"url":"https://git.kernel.org/stable/c/3c89ca6d3dfa6c09c515807a7a97a521f5d5147e","tags":["Patch","web"]},{"url":"https://git.kernel.org/stable/c/8b4506cff6630bb474bb46a2a75c31e533a756ba","tags":["Patch","web"]},{"url":"https://git.kernel.org/stable/c/f0cc93080d4c09510b74ecba87fd778cca390bb1","tags":["Patch","web"]},{"url":"https://git.kernel.org/stable/c/36ff974b0310771417c0be64b64aa221bd70d63d","tags":["Patch","web"]},{"url":"https://git.kernel.org/stable/c/1d4ff73062096c21b47954d2996b4df259777bda","tags":["Patch","web"]},{"url":"https://git.kernel.org/stable/c/abc082aac0d9b6b926038fc3adb7008306581be2","tags":["Patch","web"]},{"url":"https://git.kernel.org/stable/c/cb029b54953420f7a2d65100f1c5107f14411bdc","tags":["Patch","web"]},{"url":"https://git.kernel.org/stable/c/8ac932a4921a96ca52f61935dbba64ea87bbd5dc","tags":["Patch","web"]},{"url":"https://github.com/CVEProject/cvelistV5/tree/main/cves/2022/49xxx/CVE-2022-49850.json","tags":["advisory"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2022-49850","tags":["advisory"]},{"url":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","tags":["package"]}],"patchReferenced":true,"fixAvailable":true,"exploitReferenced":false,"kev":false,"kevAdded":null,"kevDue":null,"kevEntry":null,"ssvc":{"exploitation":"none","automatable":"no","technicalImpact":"partial"},"epss":0.00165,"epssPercentile":0.05826,"sources":[{"name":"CVE List","url":"https://www.cve.org/CVERecord?id=CVE-2022-49850","ok":true},{"name":"NVD","url":"https://nvd.nist.gov/vuln/detail/CVE-2022-49850","ok":true,"note":"Modified"},{"name":"OSV","url":"https://osv.dev/vulnerability/CVE-2022-49850","ok":true,"note":"0 packages"},{"name":"CISA KEV","url":"https://www.cisa.gov/known-exploited-vulnerabilities-catalog","ok":true,"note":"not listed"},{"name":"EPSS","url":"https://api.first.org/data/v1/epss?cve=CVE-2022-49850","ok":true,"note":"scored 2026-11-19"}],"aiTitle":false,"tech":[],"critical":[],"attention":null}