linux-stable/fs/ubifs
Zhihao Cheng f0824ca283 ubifs: ubifs_symlink: Fix memleak of inode->i_link in error path
commit 1e022216dc upstream.

For error handling path in ubifs_symlink(), inode will be marked as
bad first, then iput() is invoked. If inode->i_link is initialized by
fscrypt_encrypt_symlink() in encryption scenario, inode->i_link won't
be freed by callchain ubifs_free_inode -> fscrypt_free_inode in error
handling path, because make_bad_inode() has changed 'inode->i_mode' as
'S_IFREG'.
Following kmemleak is easy to be reproduced by injecting error in
ubifs_jnl_update() when doing symlink in encryption scenario:
 unreferenced object 0xffff888103da3d98 (size 8):
  comm "ln", pid 1692, jiffies 4294914701 (age 12.045s)
  backtrace:
   kmemdup+0x32/0x70
   __fscrypt_encrypt_symlink+0xed/0x1c0
   ubifs_symlink+0x210/0x300 [ubifs]
   vfs_symlink+0x216/0x360
   do_symlinkat+0x11a/0x190
   do_syscall_64+0x3b/0xe0
There are two ways fixing it:
 1. Remove make_bad_inode() in error handling path. We can do that
    because ubifs_evict_inode() will do same processes for good
    symlink inode and bad symlink inode, for inode->i_nlink checking
    is before is_bad_inode().
 2. Free inode->i_link before marking inode bad.
Method 2 is picked, it has less influence, personally, I think.

Cc: stable@vger.kernel.org
Fixes: 2c58d548f5 ("fscrypt: cache decrypted symlink target in ->i_link")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Suggested-by: Eric Biggers <ebiggers@kernel.org>
Reviewed-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-02-23 08:24:49 +01:00
..
auth.c ubifs: Fix memleak in ubifs_init_authentication 2021-03-04 10:26:25 +01:00
budget.c ubifs: Reserve one leb for each journal head while doing budget 2023-03-11 16:44:09 +01:00
commit.c treewide: Remove uninitialized_var() usage 2023-06-09 10:29:01 +02:00
compress.c
crypto.c
debug.c ubifs: dent: Fix some potential memory leaks while iterating entries 2020-11-05 11:43:32 +01:00
debug.h Driver Core and debugfs changes for 5.3-rc1 2019-07-12 12:24:03 -07:00
dir.c ubifs: ubifs_symlink: Fix memleak of inode->i_link in error path 2024-02-23 08:24:49 +01:00
file.c treewide: Remove uninitialized_var() usage 2023-06-09 10:29:01 +02:00
find.c
gc.c
io.c ubifs: Fix read out-of-bounds in ubifs_wbuf_write_nolock() 2022-04-15 14:18:28 +02:00
ioctl.c ubifs: setflags: Make dirtied_ino_d 8 bytes aligned 2022-04-15 14:18:28 +02:00
journal.c treewide: Remove uninitialized_var() usage 2023-06-09 10:29:01 +02:00
Kconfig
key.h
log.c
lprops.c
lpt.c treewide: Remove uninitialized_var() usage 2023-06-09 10:29:01 +02:00
lpt_commit.c
Makefile
master.c
misc.c
misc.h
orphan.c ubifs: xattr: Fix some potential memory leaks while iterating entries 2020-11-05 11:43:32 +01:00
recovery.c
replay.c ubifs: Only check replay with inode type to judge if inode linked 2021-05-11 14:04:14 +02:00
sb.c ubifs: Fix wrong memory allocation 2020-02-11 04:35:20 -08:00
scan.c
shrinker.c
super.c ubifs: Fix memory leak in alloc_wbufs() 2023-03-11 16:44:09 +01:00
tnc.c treewide: Remove uninitialized_var() usage 2023-06-09 10:29:01 +02:00
tnc_commit.c ubifs: ubifs_tnc_start_commit: Fix OOB in layout_in_gaps 2020-01-09 10:20:06 +01:00
tnc_misc.c treewide: Remove uninitialized_var() usage 2023-06-09 10:29:01 +02:00
ubifs-media.h
ubifs.h ubifs: Fix build errors as symbol undefined 2023-03-11 16:44:08 +01:00
xattr.c ubifs: Fix races between xattr_{set|get} and listxattr operations 2021-07-19 08:53:16 +02:00