History

fs/minix: check return value of sb_getblk()

Patch series "fs/minix: fix syzbot bugs and set s_maxbytes". This series fixes all syzbot bugs in the minix filesystem: KASAN: null-ptr-deref Write in get_block KASAN: use-after-free Write in get_block KASAN: use-after-free Read in get_block WARNING in inc_nlink KMSAN: uninit-value in get_block WARNING in drop_nlink It also fixes the minix filesystem to set s_maxbytes correctly, so that userspace sees the correct behavior when exceeding the max file size. This patch (of 6): sb_getblk() can fail, so check its return value. This fixes a NULL pointer dereference. Originally from Qiujun Huang.

Eric Biggers committed 6 years ago

Commit da27e0a1 parent 2fb32441 file · +7 −1Browse files

Unified · Split

fs/minix/itree_common.c+7−1
@@ -75,6 +75,7 @@ static int alloc_branch(struct inode *inode, · 74 unmodified lines
7575 int n = 0;
7676 int i;
7777 int parent = minix_new_block(inode);
78+ int err = -ENOSPC;
7879
7980 branch[0].key = cpu_to_block(parent);
8081 if (parent) for (n = 1; n < num; n++) {
@@ -85,6 +86,11 @@ static int alloc_branch(struct inode *inode, · 4 unmodified lines
8586 break;
8687 branch[n].key = cpu_to_block(nr);
8788 bh = sb_getblk(inode->i_sb, parent);
89+ if (!bh) {
90+ minix_free_block(inode, nr);
91+ err = -ENOMEM;
92+ break;
93+ }
8894 lock_buffer(bh);
8995 memset(bh->b_data, 0, bh->b_size);
9096 branch[n].bh = bh;
@@ -103,7 +109,7 @@ static int alloc_branch(struct inode *inode, · 12 unmodified lines
103109 bforget(branch[i].bh);
104110 for (i = 0; i < n; i++)
105111 minix_free_block(inode, block_to_cpu(branch[i].key));
106− return -ENOSPC;
112+ return err;
107113 }
108114
109115 static inline int splice_branch(struct inode *inode,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t