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