{"id":"CVE-2022-50457","state":"PUBLISHED","title":"mtd: core: Fix refcount error in del_mtd_device()","description":"In the Linux kernel, the following vulnerability has been resolved:\n\nmtd: core: Fix refcount error in del_mtd_device()\n\ndel_mtd_device() will call of_node_put() to mtd_get_of_node(mtd), which\nis mtd->dev.of_node. However, memset(&mtd->dev, 0) is called before\nof_node_put(). As the result, of_node_put() won't do anything in\ndel_mtd_device(), and causes the refcount leak.\n\ndel_mtd_device()\n    memset(&mtd->dev, 0, sizeof(mtd->dev) # clear mtd->dev\n    of_node_put()\n        mtd_get_of_node(mtd) # mtd->dev is cleared, can't locate of_node\n                             # of_node_put(NULL) won't do anything\n\nFix the error by caching the pointer of the device_node.\n\nOF: ERROR: memory leak, expected refcount 1 instead of 2,\nof_node_get()/of_node_put() unbalanced - destroy cset entry: attach\noverlay node /spi/spi-sram@0\nCPU: 3 PID: 275 Comm: python3 Tainted: G N 6.1.0-rc3+ #54\n    0d8a1edddf51f172ff5226989a7565c6313b08e2\nHardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS\nrel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org 04/01/2014\nCall Trace:\n<TASK>\n    dump_stack_lvl+0x67/0x83\n    kobject_get+0x155/0x160\n    of_node_get+0x1f/0x30\n    of_fwnode_get+0x43/0x70\n    fwnode_handle_get+0x54/0x80\n    fwnode_get_nth_parent+0xc9/0xe0\n    fwnode_full_name_string+0x3f/0xa0\n    device_node_string+0x30f/0x750\n    pointer+0x598/0x7a0\n    vsnprintf+0x62d/0x9b0\n    ...\n    cfs_overlay_release+0x30/0x90\n    config_item_release+0xbe/0x1a0\n    config_item_put+0x5e/0x80\n    configfs_rmdir+0x3bd/0x540\n    vfs_rmdir+0x18c/0x320\n    do_rmdir+0x198/0x330\n    __x64_sys_rmdir+0x2c/0x40\n    do_syscall_64+0x37/0x90\n    entry_SYSCALL_64_after_hwframe+0x63/0xcd\n\n[<miquel.raynal@bootlin.com>: Light reword of the commit log]","publishedAt":"2025-10-01T11:45:30.263Z","updatedAt":"2026-10-30T12:17:10.412Z","severity":null,"assigner":"Linux","products":["Linux Linux"],"affected":[{"vendor":"Linux","product":"Linux","defaultStatus":"unaffected","versions":[{"version":"63aff1411fc609d737830b79c6b06ce62348c582","status":"affected","lessThan":"0de86087b20675c53fda2bc903dfc26a7ec99856","versionType":"git"},{"version":"00596576a05145a1b5672897a82ef87af00becf4","status":"affected","lessThan":"f6016557f1ef7735963bd8691592d2797bbf91d2","versionType":"git"},{"version":"00596576a05145a1b5672897a82ef87af00becf4","status":"affected","lessThan":"616dc895d982026f41f500c88d1bfea004938cc8","versionType":"git"},{"version":"00596576a05145a1b5672897a82ef87af00becf4","status":"affected","lessThan":"56570bdad5e31c5c538cd6efff5c4510256e1bb4","versionType":"git"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["drivers/mtd/mtdcore.c"]},{"vendor":"Linux","product":"Linux","defaultStatus":"affected","versions":[{"version":"5.17","status":"affected"},{"version":"0","status":"unaffected","lessThan":"5.17","versionType":"semver"},{"version":"6.0.16","status":"unaffected","lessThanOrEqual":"6.0.*","versionType":"semver"},{"version":"6.1.2","status":"unaffected","lessThanOrEqual":"6.1.*","versionType":"semver"},{"version":"6.2","status":"unaffected","lessThanOrEqual":"*","versionType":"original_commit_for_fix"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["drivers/mtd/mtdcore.c"]}],"references":["https://git.kernel.org/stable/c/0de86087b20675c53fda2bc903dfc26a7ec99856","https://git.kernel.org/stable/c/f6016557f1ef7735963bd8691592d2797bbf91d2","https://git.kernel.org/stable/c/616dc895d982026f41f500c88d1bfea004938cc8","https://git.kernel.org/stable/c/56570bdad5e31c5c538cd6efff5c4510256e1bb4"],"weaknesses":[],"ingestedAt":"2026-10-30T12:34:06.950Z","source":{"repository":"CVEProject/cvelistV5","path":"cves/2022/50xxx/CVE-2022-50457.json","commit":"db8103c5921aac81d5d90efcf3745980dafabf49","baselineCommit":"556c9d3a8cd17e218bb8e452ba7cd619a384ff47"},"raw":{"dataType":"CVE_RECORD","dataVersion":"5.2","cveMetadata":{"cveId":"CVE-2022-50457","state":"PUBLISHED","datePublished":"2025-10-01T11:45:30.263Z","dateUpdated":"2026-10-30T12:17:10.412Z","assignerShortName":"Linux","assignerOrgId":"416baaa9-dc9f-4396-8d5f-8c081fb06d67","dateReserved":"2025-10-01T11:38:45.640Z"},"containers":{"cna":{"title":"mtd: core: Fix refcount error in del_mtd_device()","descriptions":[{"lang":"en","value":"In the Linux kernel, the following vulnerability has been resolved:\n\nmtd: core: Fix refcount error in del_mtd_device()\n\ndel_mtd_device() will call of_node_put() to mtd_get_of_node(mtd), which\nis mtd->dev.of_node. However, memset(&mtd->dev, 0) is called before\nof_node_put(). As the result, of_node_put() won't do anything in\ndel_mtd_device(), and causes the refcount leak.\n\ndel_mtd_device()\n    memset(&mtd->dev, 0, sizeof(mtd->dev) # clear mtd->dev\n    of_node_put()\n        mtd_get_of_node(mtd) # mtd->dev is cleared, can't locate of_node\n                             # of_node_put(NULL) won't do anything\n\nFix the error by caching the pointer of the device_node.\n\nOF: ERROR: memory leak, expected refcount 1 instead of 2,\nof_node_get()/of_node_put() unbalanced - destroy cset entry: attach\noverlay node /spi/spi-sram@0\nCPU: 3 PID: 275 Comm: python3 Tainted: G N 6.1.0-rc3+ #54\n    0d8a1edddf51f172ff5226989a7565c6313b08e2\nHardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS\nrel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org 04/01/2014\nCall Trace:\n<TASK>\n    dump_stack_lvl+0x67/0x83\n    kobject_get+0x155/0x160\n    of_node_get+0x1f/0x30\n    of_fwnode_get+0x43/0x70\n    fwnode_handle_get+0x54/0x80\n    fwnode_get_nth_parent+0xc9/0xe0\n    fwnode_full_name_string+0x3f/0xa0\n    device_node_string+0x30f/0x750\n    pointer+0x598/0x7a0\n    vsnprintf+0x62d/0x9b0\n    ...\n    cfs_overlay_release+0x30/0x90\n    config_item_release+0xbe/0x1a0\n    config_item_put+0x5e/0x80\n    configfs_rmdir+0x3bd/0x540\n    vfs_rmdir+0x18c/0x320\n    do_rmdir+0x198/0x330\n    __x64_sys_rmdir+0x2c/0x40\n    do_syscall_64+0x37/0x90\n    entry_SYSCALL_64_after_hwframe+0x63/0xcd\n\n[<miquel.raynal@bootlin.com>: Light reword of the commit log]"}],"affected":[{"vendor":"Linux","product":"Linux","defaultStatus":"unaffected","versions":[{"version":"63aff1411fc609d737830b79c6b06ce62348c582","status":"affected","lessThan":"0de86087b20675c53fda2bc903dfc26a7ec99856","versionType":"git"},{"version":"00596576a05145a1b5672897a82ef87af00becf4","status":"affected","lessThan":"f6016557f1ef7735963bd8691592d2797bbf91d2","versionType":"git"},{"version":"00596576a05145a1b5672897a82ef87af00becf4","status":"affected","lessThan":"616dc895d982026f41f500c88d1bfea004938cc8","versionType":"git"},{"version":"00596576a05145a1b5672897a82ef87af00becf4","status":"affected","lessThan":"56570bdad5e31c5c538cd6efff5c4510256e1bb4","versionType":"git"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["drivers/mtd/mtdcore.c"]},{"vendor":"Linux","product":"Linux","defaultStatus":"affected","versions":[{"version":"5.17","status":"affected"},{"version":"0","status":"unaffected","lessThan":"5.17","versionType":"semver"},{"version":"6.0.16","status":"unaffected","lessThanOrEqual":"6.0.*","versionType":"semver"},{"version":"6.1.2","status":"unaffected","lessThanOrEqual":"6.1.*","versionType":"semver"},{"version":"6.2","status":"unaffected","lessThanOrEqual":"*","versionType":"original_commit_for_fix"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["drivers/mtd/mtdcore.c"]}],"references":[{"url":"https://git.kernel.org/stable/c/0de86087b20675c53fda2bc903dfc26a7ec99856"},{"url":"https://git.kernel.org/stable/c/f6016557f1ef7735963bd8691592d2797bbf91d2"},{"url":"https://git.kernel.org/stable/c/616dc895d982026f41f500c88d1bfea004938cc8"},{"url":"https://git.kernel.org/stable/c/56570bdad5e31c5c538cd6efff5c4510256e1bb4"}],"providerMetadata":{"shortName":"Linux","orgId":"416baaa9-dc9f-4396-8d5f-8c081fb06d67","dateUpdated":"2026-10-30T12:17:10.412Z"},"cpeApplicability":[{"nodes":[{"operator":"OR","negate":false,"cpeMatch":[{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"5.17","versionEndExcluding":"6.0.16"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"5.17","versionEndExcluding":"6.1.2"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"5.17","versionEndExcluding":"6.2"}]}]}],"x_generator":{"engine":"bippy-1.2.0"}}}}}