No description
Find a file
Chen Zhongjin 89d1df2c71 configfs: fix possible memory leak in configfs_create_dir()
[ Upstream commit c65234b283 ]

kmemleak reported memory leaks in configfs_create_dir():

unreferenced object 0xffff888009f6af00 (size 192):
  comm "modprobe", pid 3777, jiffies 4295537735 (age 233.784s)
  backtrace:
    kmem_cache_alloc (mm/slub.c:3250 mm/slub.c:3256 mm/slub.c:3263 mm/slub.c:3273)
    new_fragment (./include/linux/slab.h:600 fs/configfs/dir.c:163)
    configfs_register_subsystem (fs/configfs/dir.c:1857)
    basic_write (drivers/hwtracing/stm/p_basic.c:14) stm_p_basic
    do_one_initcall (init/main.c:1296)
    do_init_module (kernel/module/main.c:2455)
    ...

unreferenced object 0xffff888003ba7180 (size 96):
  comm "modprobe", pid 3777, jiffies 4295537735 (age 233.784s)
  backtrace:
    kmem_cache_alloc (mm/slub.c:3250 mm/slub.c:3256 mm/slub.c:3263 mm/slub.c:3273)
    configfs_new_dirent (./include/linux/slab.h:723 fs/configfs/dir.c:194)
    configfs_make_dirent (fs/configfs/dir.c:248)
    configfs_create_dir (fs/configfs/dir.c:296)
    configfs_attach_group.isra.28 (fs/configfs/dir.c:816 fs/configfs/dir.c:852)
    configfs_register_subsystem (fs/configfs/dir.c:1881)
    basic_write (drivers/hwtracing/stm/p_basic.c:14) stm_p_basic
    do_one_initcall (init/main.c:1296)
    do_init_module (kernel/module/main.c:2455)
    ...

This is because the refcount is not correct in configfs_make_dirent().
For normal stage, the refcount is changing as:

configfs_register_subsystem()
  configfs_create_dir()
    configfs_make_dirent()
      configfs_new_dirent() # set s_count = 1
      dentry->d_fsdata = configfs_get(sd); # s_count = 2
...
configfs_unregister_subsystem()
  configfs_remove_dir()
    remove_dir()
      configfs_remove_dirent() # s_count = 1
    dput() ...
      *dentry_unlink_inode()*
        configfs_d_iput() # s_count = 0, release

However, if we failed in configfs_create():

configfs_register_subsystem()
  configfs_create_dir()
    configfs_make_dirent() # s_count = 2
    ...
    configfs_create() # fail
    ->out_remove:
    configfs_remove_dirent(dentry)
      configfs_put(sd) # s_count = 1
      return PTR_ERR(inode);

There is no inode in the error path, so the configfs_d_iput() is lost
and makes sd and fragment memory leaked.

To fix this, when we failed in configfs_create(), manually call
configfs_put(sd) to keep the refcount correct.

Fixes: 7063fbf226 ("[PATCH] configfs: User-driven configuration filesystem")
Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-04-19 17:57:29 +08:00
arch MIPS: OCTEON: warn only once if deprecated link status is being used 2023-04-19 17:57:17 +08:00
block block: clear ->slave_dir when dropping the main slave_dir reference 2023-04-19 17:57:23 +08:00
certs certs/blacklist_hashes.c: fix const confusion in certs blacklist 2023-04-19 17:50:34 +08:00
crypto crypto: akcipher - default implementation for setting a private key 2023-04-19 17:55:27 +08:00
Documentation ASoC: dt-bindings: wcd9335: fix reset line polarity in example 2023-04-19 17:57:26 +08:00
drivers clk: qcom: clk-krait: fix wrong div2 functions 2023-04-19 17:57:28 +08:00
fs configfs: fix possible memory leak in configfs_create_dir() 2023-04-19 17:57:29 +08:00
include bpf, sockmap: Fix missing BPF_F_INGRESS flag when using apply_bytes 2023-04-19 17:57:27 +08:00
init init/Kconfig: fix CC_HAS_ASM_GOTO_TIED_OUTPUT test with dash 2023-04-19 17:56:40 +08:00
io_uring io_uring: Fix a null-ptr-deref in io_tctx_exit_cb() 2023-04-19 17:57:04 +08:00
ipc ipc/sem: Fix dangling sem_array access in semtimedop race 2023-04-19 17:56:54 +08:00
kernel bpf: propagate precision across all frames, not just the last one 2023-04-19 17:57:21 +08:00
lib lib/notifier-error-inject: fix error when writing -errno to debugfs file 2023-04-19 17:57:15 +08:00
LICENSES LICENSES/dual/CC-BY-4.0: Git rid of "smart quotes" 2021-07-15 06:31:24 -06:00
mm mm/gup: fix gup_pud_range() for dax 2023-04-19 17:56:58 +08:00
net hsr: Synchronize sequence number updates. 2023-04-19 17:57:29 +08:00
samples samples/landlock: Format with clang-format 2023-04-19 17:50:01 +08:00
scripts scripts/faddr2line: Fix regression in name resolution on ppc64le 2023-04-19 17:56:46 +08:00
security ima: Fix misuse of dereference of pointer in template_desc_init_fields() 2023-04-19 17:57:23 +08:00
sound ASoC: pcm512x: Fix PM disable depth imbalance in pcm512x_probe 2023-04-19 17:57:27 +08:00
tools netfilter: conntrack: set icmpv6 redirects as RELATED 2023-04-19 17:57:27 +08:00
usr usr/include/Makefile: add linux/nfc.h to the compile-test coverage 2023-04-19 17:44:58 +08:00
virt kvm: Add support for arch compat vm ioctls 2023-04-19 17:55:40 +08:00
.clang-format clang-format: Update with the latest for_each macro list 2021-05-12 23:32:39 +02:00
.cocciconfig
.get_maintainer.ignore
.gitattributes .gitattributes: use 'dts' diff driver for dts files 2019-12-04 19:44:11 -08:00
.gitignore .gitignore: ignore only top-level modules.builtin 2021-05-02 00:43:35 +09:00
.mailmap mailmap: add Andrej Shadura 2021-10-18 20:22:03 -10:00
COPYING COPYING: state that all contributions really are covered by this file 2020-02-10 13:32:20 -08:00
CREDITS MAINTAINERS: Move Daniel Drake to credits 2021-09-21 08:34:58 +03:00
Kbuild kbuild: rename hostprogs-y/always to hostprogs/always-y 2020-02-04 01:53:07 +09:00
Kconfig kbuild: ensure full rebuild when the compiler is updated 2020-05-12 13:28:33 +09:00
MAINTAINERS futex: Move to kernel/futex/ 2023-04-19 17:57:16 +08:00
Makefile Linux 5.15.85 2023-04-19 17:57:07 +08:00
README

Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the Restructured Text markup notation.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.