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 | 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 | ||
| 109 | static inline int splice_branch(struct inode *inode, | 115 | static inline int splice_branch(struct inode *inode, |