linux-stable/fs/ocfs2
Li Zetao 4efe1d2db7 ocfs2: fix memory leak in ocfs2_mount_volume()
[ Upstream commit ce2fcf1516 ]

There is a memory leak reported by kmemleak:

  unreferenced object 0xffff88810cc65e60 (size 32):
    comm "mount.ocfs2", pid 23753, jiffies 4302528942 (age 34735.105s)
    hex dump (first 32 bytes):
      10 00 00 00 00 00 00 00 00 01 01 01 01 01 01 01  ................
      01 01 01 01 01 01 01 01 00 00 00 00 00 00 00 00  ................
    backtrace:
      [<ffffffff8170f73d>] __kmalloc+0x4d/0x150
      [<ffffffffa0ac3f51>] ocfs2_compute_replay_slots+0x121/0x330 [ocfs2]
      [<ffffffffa0b65165>] ocfs2_check_volume+0x485/0x900 [ocfs2]
      [<ffffffffa0b68129>] ocfs2_mount_volume.isra.0+0x1e9/0x650 [ocfs2]
      [<ffffffffa0b7160b>] ocfs2_fill_super+0xe0b/0x1740 [ocfs2]
      [<ffffffff818e1fe2>] mount_bdev+0x312/0x400
      [<ffffffff819a086d>] legacy_get_tree+0xed/0x1d0
      [<ffffffff818de82d>] vfs_get_tree+0x7d/0x230
      [<ffffffff81957f92>] path_mount+0xd62/0x1760
      [<ffffffff81958a5a>] do_mount+0xca/0xe0
      [<ffffffff81958d3c>] __x64_sys_mount+0x12c/0x1a0
      [<ffffffff82f26f15>] do_syscall_64+0x35/0x80
      [<ffffffff8300006a>] entry_SYSCALL_64_after_hwframe+0x46/0xb0

This call stack is related to two problems.  Firstly, the ocfs2 super uses
"replay_map" to trace online/offline slots, in order to recover offline
slots during recovery and mount.  But when ocfs2_truncate_log_init()
returns an error in ocfs2_mount_volume(), the memory of "replay_map" will
not be freed in error handling path.  Secondly, the memory of "replay_map"
will not be freed if d_make_root() returns an error in ocfs2_fill_super().
But the memory of "replay_map" will be freed normally when completing
recovery and mount in ocfs2_complete_mount_recovery().

Fix the first problem by adding error handling path to free "replay_map"
when ocfs2_truncate_log_init() fails.  And fix the second problem by
calling ocfs2_free_replay_slots(osb) in the error handling path
"out_dismount".  In addition, since ocfs2_free_replay_slots() is static,
it is necessary to remove its static attribute and declare it in header
file.

Link: https://lkml.kernel.org/r/20221109074627.2303950-1-lizetao1@huawei.com
Fixes: 9140db04ef ("ocfs2: recover orphans in offline slots during recovery and mount")
Signed-off-by: Li Zetao <lizetao1@huawei.com>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Mark Fasheh <mark@fasheh.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Junxiao Bi <junxiao.bi@oracle.com>
Cc: Changwei Ge <gechangwei@live.cn>
Cc: Gang He <ghe@suse.com>
Cc: Jun Piao <piaojun@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-12-31 13:25:45 +01:00
..
cluster fs/ocfs2: Use the enum req_op and blk_opf_t types 2022-07-14 12:14:33 -06:00
dlm ocfs2: remove usage of list iterator variable after the loop body 2022-04-29 14:37:57 -07:00
dlmfs ocfs2: kill EBUSY from dlmfs_evict_inode 2022-06-16 19:58:20 -07:00
Kconfig ocfs2: replace HTTP links with HTTPS ones 2020-08-07 11:33:22 -07:00
Makefile ocfs2: improve ocfs2 Makefile 2018-12-28 12:11:45 -08:00
acl.c vfs: add rcu argument to ->get_acl() callback 2021-08-18 22:08:24 +02:00
acl.h vfs: add rcu argument to ->get_acl() callback 2021-08-18 22:08:24 +02:00
alloc.c ocfs2: Convert ocfs2 to read_folio 2022-05-09 16:21:46 -04:00
alloc.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
aops.c Folio changes for 6.0 2022-08-03 10:35:43 -07:00
aops.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
blockcheck.c treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
blockcheck.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
buffer_head_io.c fs/buffer: Combine two submit_bh() and ll_rw_block() arguments 2022-07-14 12:14:32 -06:00
buffer_head_io.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
dcache.c treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
dcache.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
dir.c fs/ocfs2: fix comments mentioning i_mutex 2022-03-22 15:57:00 -07:00
dir.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
dlmglue.c ocfs2: fix freeing uninitialized resource on ocfs2_dlm_shutdown 2022-08-28 14:02:45 -07:00
dlmglue.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
export.c treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
export.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
extent_map.c treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
extent_map.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
file.c attr: port attribute changes to new types 2022-06-26 18:18:56 +02:00
file.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
filecheck.c ocfs2: use default_groups in kobj_type 2022-01-15 16:30:24 +02:00
filecheck.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
heartbeat.c ocfs2: fix a typo in a comment 2022-07-29 18:12:36 -07:00
heartbeat.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
inode.c ocfs2: fix mounting crash if journal is not alloced 2022-04-29 14:37:58 -07:00
inode.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
ioctl.c block: add a bdev_discard_granularity helper 2022-04-17 19:49:59 -06:00
ioctl.h ocfs2: convert to fileattr 2021-04-12 15:04:30 +02:00
journal.c ocfs2: fix memory leak in ocfs2_mount_volume() 2022-12-31 13:25:45 +01:00
journal.h ocfs2: fix memory leak in ocfs2_mount_volume() 2022-12-31 13:25:45 +01:00
localalloc.c fs/ocfs2: fix comments mentioning i_mutex 2022-03-22 15:57:00 -07:00
localalloc.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
locks.c fs: remove mandatory file locking support 2021-08-23 06:15:36 -04:00
locks.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
mmap.c treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
mmap.h
move_extents.c treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
move_extents.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
namei.c ocfs2: fix BUG when iput after ocfs2_mknod fails 2022-10-29 10:08:29 +02:00
namei.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
ocfs1_fs_compat.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
ocfs2.h Revert "ocfs2: mount shared volume without ha stack" 2022-07-18 15:09:15 -07:00
ocfs2_fs.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
ocfs2_ioctl.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
ocfs2_lockid.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
ocfs2_lockingver.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
ocfs2_trace.h ocfs2: fix the application IO timeout when fstrim is running 2019-03-05 21:07:13 -08:00
quota.h
quota_global.c fs/ocfs2: Fix spelling typo in comment 2022-07-17 17:31:43 -07:00
quota_local.c ocfs2: replace usage of found with dedicated list iterator variable 2022-04-29 14:37:57 -07:00
refcounttree.c ocfs2: Use filemap_write_and_wait_range() in ocfs2_cow_sync_writeback() 2022-08-02 12:34:02 -04:00
refcounttree.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
reservations.c ocfs2: change return type of ocfs2_resmap_init 2022-04-29 14:37:58 -07:00
reservations.h ocfs2: change return type of ocfs2_resmap_init 2022-04-29 14:37:58 -07:00
resize.c treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
resize.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
slot_map.c Revert "ocfs2: mount shared volume without ha stack" 2022-07-18 15:09:15 -07:00
slot_map.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
stack_o2cb.c treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
stack_user.c ocfs2: cleanup some return variables 2022-03-22 15:57:00 -07:00
stackglue.c ocfs2: fix memory leak in ocfs2_stack_glue_init() 2022-12-31 13:25:43 +01:00
stackglue.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
suballoc.c ocfs2: fix a deadlock when commit trans 2022-01-30 09:56:58 +02:00
suballoc.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
super.c ocfs2: fix memory leak in ocfs2_mount_volume() 2022-12-31 13:25:45 +01:00
super.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
symlink.c ocfs2: Convert ocfs2 to read_folio 2022-05-09 16:21:46 -04:00
symlink.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
sysfile.c treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
sysfile.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
uptodate.c treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
uptodate.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00
xattr.c fs/ocfs2: fix comments mentioning i_mutex 2022-03-22 15:57:00 -07:00
xattr.h treewide: remove editor modelines and cruft 2021-05-07 00:26:34 -07:00