Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

buffer: fix grow_buffers() for block size > PAGE_SIZE

We must not shift by a negative number so work in terms of a byte offset
to avoid the awkward shift left-or-right-depending-on-sign option. This
means we need to use check_mul_overflow() to ensure that a large block
number does not result in a wrap.

Link: https://lkml.kernel.org/r/20231109210608.2252323-4-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Pankaj Raghav <p.raghav@samsung.com>
Cc: Ryusuke Konishi <konishi.ryusuke@gmail.com>
[nathan@kernel.org: add cast in grow_buffers() to avoid a multiplication libcall]
Link: https://lkml.kernel.org/r/20231128-avoid-muloti4-grow_buffers-v1-1-bc3d0f0ec483@kernel.org
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Matthew Wilcox (Oracle) and committed by
Andrew Morton
5f3bd90d 382497ad

+6 -11
+6 -11
fs/buffer.c
··· 1085 1085 static bool grow_buffers(struct block_device *bdev, sector_t block, 1086 1086 unsigned size, gfp_t gfp) 1087 1087 { 1088 - pgoff_t index; 1089 - int sizebits; 1090 - 1091 - sizebits = PAGE_SHIFT - __ffs(size); 1092 - index = block >> sizebits; 1088 + loff_t pos; 1093 1089 1094 1090 /* 1095 - * Check for a block which wants to lie outside our maximum possible 1096 - * pagecache index. (this comparison is done using sector_t types). 1091 + * Check for a block which lies outside our maximum possible 1092 + * pagecache index. 1097 1093 */ 1098 - if (unlikely(index != block >> sizebits)) { 1099 - printk(KERN_ERR "%s: requested out-of-range block %llu for " 1100 - "device %pg\n", 1094 + if (check_mul_overflow(block, (sector_t)size, &pos) || pos > MAX_LFS_FILESIZE) { 1095 + printk(KERN_ERR "%s: requested out-of-range block %llu for device %pg\n", 1101 1096 __func__, (unsigned long long)block, 1102 1097 bdev); 1103 1098 return false; 1104 1099 } 1105 1100 1106 1101 /* Create a folio with the proper size buffers */ 1107 - return grow_dev_folio(bdev, block, index, size, gfp); 1102 + return grow_dev_folio(bdev, block, pos / PAGE_SIZE, size, gfp); 1108 1103 } 1109 1104 1110 1105 static struct buffer_head *