fs/ntfs3: Add initialization of super block
Subsystems (2)
Hello Konstantin Komarov,
The patch 82cae269cfa9: "fs/ntfs3: Add initialization of super block" from Aug 13, 2021, leads to the following
Smatch static checker warning:
fs/ntfs3/index.c:238 bmp_buf_get() warn: 'bh' could be an error pointer
fs/ntfs3/index.c
229 data_size = le64_to_cpu(b->nres.data_size);
230 if (WARN_ON(off >= data_size)) {
231 /* looks like filesystem error */
232 return -EINVAL;
233 }
234
235 valid_size = le64_to_cpu(b->nres.valid_size);
236
237 bh = ntfs_bread_run(sbi, &indx->bitmap_run, off);
--> 238 if (!bh)
239 return -EIO;
240
241 if (IS_ERR(bh))This is not a bug, but it is wrong style. When a function returns both error pointers and NULL then the NULL return is means the feature is disabled. It's not an error. Just that the feature is turned off deliberately in the Kconfig or whatever. Don't print an error message, just continue with the feature disabled as the admin has requested.
But here NULL is just an error. The ntfs_bread_run() should do:
bh = ntfs_bread();
if (!bh)
return ERR_PTR(-EIO);
return bh;
242 return PTR_ERR(bh);
243
244 bbuf->bh = bh;
245 regards,
dan carpenter
Quoted 24 lines · Dan Carpenter
Hello Konstantin Komarov,
The patch
82cae269cfa9: "fs/ntfs3: Add initialization of super block" from Aug 13, 2021, leads to the following
Smatch static checker warning:fs/ntfs3/index.c:238 bmp_buf_get() warn: 'bh' could be an error pointer
fs/ntfs3/index.c229 data_size = le64_to_cpu(b->nres.data_size); 230 if (WARN_ON(off >= data_size)) { 231 /* looks like filesystem error */ 232 return -EINVAL; 233 } 234 235 valid_size = le64_to_cpu(b->nres.valid_size); 236 237 bh = ntfs_bread_run(sbi, &indx->bitmap_run, off); --> 238 if (!bh) 239 return -EIO; 240 241 if (IS_ERR(bh))
Quoted 7 lines
This is not a bug, but it is wrong style. When a function returns both error pointers and NULL then the NULL return is means the feature is disabled. It's not an error. Just that the feature is turned off deliberately in the
Kconfigor whatever. Don't print an error message, just continue with the feature disabled as the admin has requested.But here NULL is just an error. The
ntfs_bread_run()should do:
Agreed.
Quoted 5 lines
bh = ntfs_bread(); if (!bh) return ERR_PTR(-EIO); return bh;
Can also be like below but probably your version is more readable.
return ntfs_bread(sb, lbo >> sb->s_blocksize_bits) ? : ERR_PTR(-EIO);
Quoted 8 lines
242 return PTR_ERR(bh); 243 244 bbuf->bh = bh; 245regards,
dan carpenter
Konstantin Komarov
maintainerPATCH 1/1 fs/ntfs3: avoid calling run_get_entry() when run == NULL in ntfs_read_run_nb_ra()
In reply to Dan CarpenterWhen ntfs_read_run_nb_ra() is invoked with run == NULL the code later assumes run is valid and may call run_get_entry(NULL, ...), and also uses clen/idx without initializing them. Smatch reported uninitialized variable warnings and this can lead to undefined behaviour. This patch fixes it.
--- fs/ntfs3/fsntfs.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/ntfs3/fsntfs.c +6 -0
@@ -1256,6 +1256,12 @@ int ntfs_read_run_nb_ra(struct ntfs_sb_info *sbi, const struct runs_tree *run, }while (len32); +if (!run) { + err = -EINVAL ; + goto out; + } + +/* Get next fragment to read. */ vcn_next = vcn + clen;if (!run_get_entry (run, ++idx, &vcn, &lcn, &clen) || vcn != vcn_next) {
Signature · 1 line
2.43.0