Skip to content

Commit f8e6cc0

Browse files
committed
nilfs2: fix buffer head leak in nilfs_btnode_submit_block
nilfs_btnode_submit_block() refers to buffer head just before returning from the function, but it releases the buffer head earlier than that if nilfs_dat_translate() gets an error. This has potential for oops in the erroneous case. This fixes the issue. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
1 parent 7c397a8 commit f8e6cc0

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎fs/nilfs2/btnode.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,15 @@ int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr,
100100
{
101101
struct buffer_head *bh;
102102
struct inode *inode = NILFS_BTNC_I(btnc);
103+
struct page *page;
103104
int err;
104105

105106
bh = nilfs_grab_buffer(inode, btnc, blocknr, 1 << BH_NILFS_Node);
106107
if (unlikely(!bh))
107108
return -ENOMEM;
108109

109110
err = -EEXIST; /* internal code */
111+
page = bh->b_page;
110112

111113
if (buffer_uptodate(bh) || buffer_dirty(bh))
112114
goto found;
@@ -143,8 +145,8 @@ int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr,
143145
*pbh = bh;
144146

145147
out_locked:
146-
unlock_page(bh->b_page);
147-
page_cache_release(bh->b_page);
148+
unlock_page(page);
149+
page_cache_release(page);
148150
return err;
149151
}
150152

0 commit comments

Comments
 (0)