# CVE-2022-50304: mtd: core: fix possible resource leak in init_mtd()

- Severity: Medium 5.5 (CVSS:3.1, scored by NVD) `CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H`
- Known to be exploited: not in CISA's catalogue, which lists only what CISA has confirmed
- Likelihood of exploitation in the next 30 days (EPSS): 0.17%, higher than 6% of CVEs (2026-12-01)
- Published: 2025-09-15T14:45:59.614Z
- Modified: 2026-11-05T20:17:33.237Z
- Weaknesses: CWE-401
- SSVC (CISA-ADP): exploitation none, automatable no, technical impact partial
- Assigned by: Linux

## Description

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

mtd: core: fix possible resource leak in init_mtd()

I got the error report while inject fault in init_mtd():

sysfs: cannot create duplicate filename '/devices/virtual/bdi/mtd-0'
Call Trace:
 <TASK>
 dump_stack_lvl+0x67/0x83
 sysfs_warn_dup+0x60/0x70
 sysfs_create_dir_ns+0x109/0x120
 kobject_add_internal+0xce/0x2f0
 kobject_add+0x98/0x110
 device_add+0x179/0xc00
 device_create_groups_vargs+0xf4/0x100
 device_create+0x7b/0xb0
 bdi_register_va.part.13+0x58/0x2d0
 bdi_register+0x9b/0xb0
 init_mtd+0x62/0x171 [mtd]
 do_one_initcall+0x6c/0x3c0
 do_init_module+0x58/0x222
 load_module+0x268e/0x27d0
 __do_sys_finit_module+0xd5/0x140
 do_syscall_64+0x37/0x90
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
 </TASK>
kobject_add_internal failed for mtd-0 with -EEXIST, don't try to register
	things with the same name in the same directory.
Error registering mtd class or bdi: -17

If init_mtdchar() fails in init_mtd(), mtd_bdi will not be unregistered,
as a result, we can't load the mtd module again, to fix this by calling
bdi_unregister(mtd_bdi) after out_procfs label.

(As written by CVE List.)

## Affected

- Linux Linux: from 445caaa20c4d6da74f426464f90513b81157ad77 before 78816504100cbd8e6836df9f58cc4fbb8b262f1c; from 445caaa20c4d6da74f426464f90513b81157ad77 before 26c304a3f136009c5a2a04e2bf3ac6aa25aabcb4; from 445caaa20c4d6da74f426464f90513b81157ad77 before 1aadf01e5076b9ab6bf294b9622335c651314895; 4.10 (not affected: before 4.10; from 6.0.16 up to 6.0.*; from 6.1.2 up to 6.1.*; from 6.2 up to *)
- linux linux_kernel: from 4.10 before 6.0.16; from 6.1 before 6.1.2

## References

- <https://git.kernel.org/stable/c/78816504100cbd8e6836df9f58cc4fbb8b262f1c> (patch)
- <https://git.kernel.org/stable/c/26c304a3f136009c5a2a04e2bf3ac6aa25aabcb4> (patch)
- <https://git.kernel.org/stable/c/1aadf01e5076b9ab6bf294b9622335c651314895> (patch)

## Sources

- CVE List: [CVE-2022-50304](https://www.cve.org/CVERecord?id=CVE-2022-50304), CVE Terms of Use, modified 2026-11-05
- NVD: [CVE-2022-50304](https://nvd.nist.gov/vuln/detail/CVE-2022-50304), Public domain, modified 2026-11-05

---

Page: https://cve.day/CVE-2022-50304 · Whole record: https://cve.day/CVE-2022-50304.json · Rebuilt by cve.day 2026-11-25T22:58:21.156Z
