Skip to contentSkip to conversation

iomap: iomap_bmap should check iomap_apply return value

PATCH In review Darrick J. Wong 2 participants 5 messages Nov 7, 2019 – Nov 8, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iomap: iomap_bmap should check iomap_apply return value

From: Darrick J. Wong <[email protected]>

Check the return value of iomap_apply and return 0 (i.e. error) if it didn't succeed.

Coverity-id: 1437065

---
 fs/iomap/fiemap.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
fs/iomap/fiemap.c +5 -1
index 690ef2d7c6c8..bccf305ea9ce 100644
@@ -133,12 +133,16 @@ iomap_bmap(struct address_space *mapping, sector_t bno,
 	struct inode *inode = mapping->host;
 	loff_t pos = bno << inode->i_blkbits;
 	unsigned blocksize = i_blocksize(inode);
+	int ret;
 
 	if (filemap_write_and_wait(mapping))
 		return 0;
 
 	bno = 0;
-	iomap_apply(inode, pos, blocksize, 0, ops, &bno, iomap_bmap_actor);
+	ret = iomap_apply(inode, pos, blocksize, 0, ops, &bno,
+			  iomap_bmap_actor);
+	if (ret)
+		return 0;
 	return bno;
 }
 EXPORT_SYMBOL_GPL(iomap_bmap);
#1 lore raw
Quoted 4 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Check the return value of iomap_apply and return 0 (i.e. error) if it didn't succeed.

And how could we set the bno value if we didn't succeed?

#2 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 4 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Check the return value of iomap_apply and return 0 (i.e. error) if it didn't succeed.

And how could we set the bno value if we didn't succeed?

The iomap_bmap caller supplies an ->iomap_end that returns an error.

Granted there's only one caller and it doesn't, so we could dump this patch and just tell Coverity to shut up, but it's odd that this is the one place where we ignore the return value.

OTOH it's bmap which has been broken for ages; the more insane behavior seen in the wild, the better to scare away users. :P

--D

Reviewed-by
#3 lore raw
Quoted 9 lines · Darrick J. Wong
Quoted 7 lines · Christoph Hellwig
Quoted 4 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Check the return value of iomap_apply and return 0 (i.e. error) if it didn't succeed.

And how could we set the bno value if we didn't succeed?

Quoted 8 lines

The iomap_bmap caller supplies an ->iomap_end that returns an error.

Granted there's only one caller and it doesn't, so we could dump this patch and just tell Coverity to shut up, but it's odd that this is the one place where we ignore the return value.

OTOH it's bmap which has been broken for ages; the more insane behavior seen in the wild, the better to scare away users. :P

Oh well. I guess the patch is fine, it just isn't really needed as-is.

#4 lore raw
Quoted 12 lines · Christoph Hellwig
Quoted 11 lines · Darrick J. Wong
Quoted 7 lines · Christoph Hellwig
Quoted 4 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Check the return value of iomap_apply and return 0 (i.e. error) if it didn't succeed.

And how could we set the bno value if we didn't succeed?

The iomap_bmap caller supplies an ->iomap_end that returns an error.

Quoted 8 lines
Quoted 6 lines

Granted there's only one caller and it doesn't, so we could dump this patch and just tell Coverity to shut up, but it's odd that this is the one place where we ignore the return value.

OTOH it's bmap which has been broken for ages; the more insane behavior seen in the wild, the better to scare away users. :P

Oh well. I guess the patch is fine, it just isn't really needed as-is.

Thanks for the review. :)

--D

Quoted 1 line