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
75 int n = 0;75 int n = 0;
76 int i;76 int i;
77 int parent = minix_new_block(inode);77 int parent = minix_new_block(inode);
78 int err = -ENOSPC;
78 79
79 branch[0].key = cpu_to_block(parent);80 branch[0].key = cpu_to_block(parent);
80 if (parent) for (n = 1; n < num; n++) {81 if (parent) for (n = 1; n < num; n++) {
@@ -85,6 +86,11 @@ static int alloc_branch(struct inode *inode, · 4 unmodified lines
85 break;86 break;
86 branch[n].key = cpu_to_block(nr);87 branch[n].key = cpu_to_block(nr);
87 bh = sb_getblk(inode->i_sb, parent);88 bh = sb_getblk(inode->i_sb, parent);
89 if (!bh) {
90 minix_free_block(inode, nr);
91 err = -ENOMEM;
92 break;
93 }
88 lock_buffer(bh);94 lock_buffer(bh);
89 memset(bh->b_data, 0, bh->b_size);95 memset(bh->b_data, 0, bh->b_size);
90 branch[n].bh = bh;96 branch[n].bh = bh;
@@ -103,7 +109,7 @@ static int alloc_branch(struct inode *inode, · 12 unmodified lines
103 bforget(branch[i].bh);109 bforget(branch[i].bh);
104 for (i = 0; i < n; i++)110 for (i = 0; i < n; i++)
105 minix_free_block(inode, block_to_cpu(branch[i].key));111 minix_free_block(inode, block_to_cpu(branch[i].key));
106 return -ENOSPC;112 return err;
107}113}
108 114
109static inline int splice_branch(struct inode *inode,115static 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