Skip to contentSkip to conversation

clean_bdev_aliases: Prevent cleaning blocks that are not in block range

PATCH Applied Chandan Rajendra 4 participants 5 messages Dec 25, 2016 – Jan 2, 2017

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

PATCH 1/1 clean_bdev_aliases: Prevent cleaning blocks that are not in block range

The first block to be cleaned may start at a non-zero page offset. In such a scenario clean_bdev_aliases() will end up cleaning blocks that do not fall in the range of blocks to be cleaned. This commit fixes the issue by skipping blocks that do not fall in valid block range.

---
 fs/buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/buffer.c +1 -1
index 1df2bd5..28484b3 100644
@@ -1660,7 +1660,7 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len)
 			head = page_buffers(page);
 			bh = head;
 			do {
-				if (!buffer_mapped(bh))
+				if (!buffer_mapped(bh) || (bh->b_blocknr < block))
 					goto next;
 				if (bh->b_blocknr >= block + len)
 					break;
Signature · 1 line
2.5.5
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Chandan Rajendra

The first block to be cleaned may start at a non-zero page offset. In such a scenario clean_bdev_aliases() will end up cleaning blocks that do not fall in the range of blocks to be cleaned. This commit fixes the issue by skipping blocks that do not fall in valid block range.

Ah, very good catch! How did you spot this?

The patch looks good. You can add:

Jens, please merge this fix quickly as we may end up discarding changes to innocent metadata blocks due to this... Thanks!

Honza

Quoted 20 lines
---
 fs/buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/buffer.c +1 -1
index 1df2bd5..28484b3 100644
@@ -1660,7 +1660,7 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len)
 			head = page_buffers(page);
 			bh = head;
 			do {
-				if (!buffer_mapped(bh))
+				if (!buffer_mapped(bh) || (bh->b_blocknr < block))
 					goto next;
 				if (bh->b_blocknr >= block + len)
 					break;
Signature · 1 line
2.5.5
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
Reviewed-by
#2 lore raw
Quoted 9 lines · Jan Kara
Quoted 6 lines · Chandan Rajendra

The first block to be cleaned may start at a non-zero page offset. In such a scenario clean_bdev_aliases() will end up cleaning blocks that do not fall in the range of blocks to be cleaned. This commit fixes the issue by skipping blocks that do not fall in valid block range.

Ah, very good catch! How did you spot this?

I failed to notice this patch, and I came up with a same patch today myself, and I'm still testing it.

I found this by xfstests, many tests (tens of tests) failed fsck after test when testing extN if blocksize < pagesize. E.g. generic/013 could reproduce the fs corruption quite reliablely for me.

Quoted 36 lines

The patch looks good. You can add:

Jens, please merge this fix quickly as we may end up discarding changes to innocent metadata blocks due to this... Thanks!

Honza

Quoted 20 lines
---
 fs/buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/buffer.c +1 -1
index 1df2bd5..28484b3 100644
@@ -1660,7 +1660,7 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len)
 			head = page_buffers(page);
 			bh = head;
 			do {
-				if (!buffer_mapped(bh))
+				if (!buffer_mapped(bh) || (bh->b_blocknr < block))
 					goto next;
 				if (bh->b_blocknr >= block + len)
 					break;
Signature · 1 line
2.5.5
Signature · 6 lines
Jan Kara <[email protected]>
SUSE Labs, CR
--
To unsubscribe from this list: send the line "unsubscribe linux-block" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
reviewer
#3 lore raw
Quoted 11 lines · Eryu Guan
Quoted 9 lines · Jan Kara
Quoted 6 lines · Chandan Rajendra

The first block to be cleaned may start at a non-zero page offset. In such a scenario clean_bdev_aliases() will end up cleaning blocks that do not fall in the range of blocks to be cleaned. This commit fixes the issue by skipping blocks that do not fall in valid block range.

Ah, very good catch! How did you spot this?

Quoted 8 lines

I failed to notice this patch, and I came up with a same patch today myself, and I'm still testing it.

I found this by xfstests, many tests (tens of tests) failed fsck after test when testing extN if blocksize < pagesize. E.g. generic/013 could reproduce the fs corruption quite reliablely for me.

Thanks! Yeah, I had run xfstests with those patches but not with blocksize < pagesize :-| Shit happens... need to be more careful next time.

Honza

Quoted 35 lines
Quoted 35 lines

The patch looks good. You can add:

Jens, please merge this fix quickly as we may end up discarding changes to innocent metadata blocks due to this... Thanks!

Honza

Quoted 20 lines
---
 fs/buffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/buffer.c +1 -1
index 1df2bd5..28484b3 100644
@@ -1660,7 +1660,7 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len)
 			head = page_buffers(page);
 			bh = head;
 			do {
-				if (!buffer_mapped(bh))
+				if (!buffer_mapped(bh) || (bh->b_blocknr < block))
 					goto next;
 				if (bh->b_blocknr >= block + len)
 					break;
Signature · 1 line
2.5.5
Signature · 6 lines
Jan Kara <[email protected]>
SUSE Labs, CR
--
To unsubscribe from this list: send the line "unsubscribe linux-block" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
maintainer Applied
#4 lore raw
In reply to Chandan Rajendra
Quoted 4 lines · Chandan Rajendra

The first block to be cleaned may start at a non-zero page offset. In such a scenario clean_bdev_aliases() will end up cleaning blocks that do not fall in the range of blocks to be cleaned. This commit fixes the issue by skipping blocks that do not fall in valid block range.

Queued up, thanks.

Signature · 1 line
Jens Axboe