* [PATCH] nilfs2: fix potential use after free in nilfs_gccache_submit_read_data()
@ 2023-09-21 14:17 Ryusuke Konishi
0 siblings, 0 replies; only message in thread
From: Ryusuke Konishi @ 2023-09-21 14:17 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-nilfs-u79uwXL29TY76Z2rM5mHXA,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
From: Pan Bian <bianpan2016-9Onoh4P/yGk@public.gmane.org>
In nilfs_gccache_submit_read_data(), brelse(bh) is called to drop the
reference count of bh when the call to nilfs_dat_translate() fails. If
the reference count hits 0 and its owner page gets unlocked, bh may be
freed. However, bh->b_page is dereferenced to put the page after that,
which may result in a use-after-free bug. This patch moves the release
operation after unlocking and putting the page.
NOTE: The function in question is only called in GC, and in combination
with current userland tools, address translation using DAT does not occur
in that function, so the code path that causes this issue will not be
executed. However, it is possible to run that code path by intentionally
modifying the userland GC library or by calling the GC ioctl directly.
Link: https://lkml.kernel.org/r/1543201709-53191-1-git-send-email-bianpan2016-9Onoh4P/yGk@public.gmane.org
Signed-off-by: Pan Bian <bianpan2016-9Onoh4P/yGk@public.gmane.org>
Reported-by: Ferry Meng <mengferry-KPsoFbNs7GizrGE5bRqYAgC/G2K4zDHf@public.gmane.org>
Closes: https://lkml.kernel.org/r/20230818092022.111054-1-mengferry-KPsoFbNs7GizrGE5bRqYAgC/G2K4zDHf@public.gmane.org
Fixes: a3d93f709e89 ("nilfs2: block cache for garbage collection")
[konishi.ryusuke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org: NOTE added to the commit log]
Signed-off-by: Ryusuke Konishi <konishi.ryusuke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Tested-by: Ryusuke Konishi <konishi.ryusuke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: <stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
---
fs/nilfs2/gcinode.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/nilfs2/gcinode.c b/fs/nilfs2/gcinode.c
index 48fe71d309cb..8beb2730929d 100644
--- a/fs/nilfs2/gcinode.c
+++ b/fs/nilfs2/gcinode.c
@@ -73,10 +73,8 @@ int nilfs_gccache_submit_read_data(struct inode *inode, sector_t blkoff,
struct the_nilfs *nilfs = inode->i_sb->s_fs_info;
err = nilfs_dat_translate(nilfs->ns_dat, vbn, &pbn);
- if (unlikely(err)) { /* -EIO, -ENOMEM, -ENOENT */
- brelse(bh);
+ if (unlikely(err)) /* -EIO, -ENOMEM, -ENOENT */
goto failed;
- }
}
lock_buffer(bh);
@@ -102,6 +100,8 @@ int nilfs_gccache_submit_read_data(struct inode *inode, sector_t blkoff,
failed:
unlock_page(bh->b_page);
put_page(bh->b_page);
+ if (unlikely(err))
+ brelse(bh);
return err;
}
--
2.34.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2023-09-21 14:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-21 14:17 [PATCH] nilfs2: fix potential use after free in nilfs_gccache_submit_read_data() Ryusuke Konishi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).