nilfs2: fix dereferencing freed memory
PATCH 1/1 nilfs2: fix dereferencing freed memory
Fix smatch warning:
fs/nilfs2/gcinode.c:103 nilfs_gccache_submit_read_data() error:
dereferencing freed memory 'bh'
fs/nilfs2/gcinode.c +3 -3
@@ -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 (err) +brelse (bh);return err; }
Signature · 1 line
2.19.1.6.gb485710b
Ryusuke Konishi
maintainerQuoted 34 lines · On Fri, Aug 18, 2023 at 6:20 PM Ferry Meng wrote:
Fix smatch warning:
fs/nilfs2/gcinode.c:103nilfs_gccache_submit_read_data()error:
dereferencing freed memory 'bh'Signed-off-by Ferry Meng <[email protected]>fs/nilfs2/gcinode.c +3
-4@@ -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 (err) +brelse (bh);return err; } --
Quoted 2 lines
2.19.1.6.gb485710b
Ah, this is almost identical to the patch Pan Bian sent me earlier. After a closer look, I'll pick up his patch instead with a "Reported-by" tag of your name on it.
Anyway, thanks for your feedback.
Regards,
Ryusuke Konishi