Commit 41e76c6
nbd: use shifts rather than multiplies
commit fad7cd3 ("nbd: add the check to prevent overflow in
__nbd_ioctl()") raised an issue from the fallback helpers added in
commit f090782 ("compiler.h: enable builtin overflow checkers and
add fallback code")
ERROR: modpost: "__divdi3" [drivers/block/nbd.ko] undefined!
As Stephen Rothwell notes:
The added check_mul_overflow() call is being passed 64 bit values.
COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW is not set for this build (see
include/linux/overflow.h).
Specifically, the helpers for checking whether the results of a
multiplication overflowed (__unsigned_mul_overflow,
__signed_add_overflow) use the division operator when
!COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW. This is problematic for 64b
operands on 32b hosts.
This was fixed upstream by
commit 76ae847 ("Documentation: raise minimum supported version of
GCC to 5.1")
which is not suitable to be backported to stable.
Further, __builtin_mul_overflow() would emit a libcall to a
compiler-rt-only symbol when compiling with clang < 14 for 32b targets.
ld.lld: error: undefined symbol: __mulodi4
In order to keep stable buildable with GCC 4.9 and clang < 14, modify
struct nbd_config to instead track the number of bits of the block size;
reconstructing the block size using runtime checked shifts that are not
problematic for those compilers and in a ways that can be backported to
stable.
In nbd_set_size, we do validate that the value of blksize must be a
power of two (POT) and is in the range of [512, PAGE_SIZE] (both
inclusive).
This does modify the debugfs interface.
Cc: [email protected]
Cc: Arnd Bergmann <[email protected]>
Cc: Rasmus Villemoes <[email protected]>
Link: ClangBuiltLinux#1438
Link: https://lore.kernel.org/all/[email protected]/
Link: https://lore.kernel.org/stable/CAHk-=whiQBofgis_rkniz8GBP9wZtSZdcDEffgSLO62BUGV3gg@mail.gmail.com/
Reported-by: Naresh Kamboju <[email protected]>
Reported-by: Nathan Chancellor <[email protected]>
Reported-by: Stephen Rothwell <[email protected]>
Suggested-by: Kees Cook <[email protected]>
Suggested-by: Linus Torvalds <[email protected]>
Suggested-by: Pavel Machek <[email protected]>
Signed-off-by: Nick Desaulniers <[email protected]>
Reviewed-by: Josef Bacik <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>1 parent ebc69e8 commit 41e76c6
1 file changed
+17
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
107 | 112 | | |
108 | 113 | | |
109 | 114 | | |
| |||
146 | 151 | | |
147 | 152 | | |
148 | 153 | | |
149 | | - | |
| 154 | + | |
150 | 155 | | |
151 | 156 | | |
152 | 157 | | |
| |||
317 | 322 | | |
318 | 323 | | |
319 | 324 | | |
320 | | - | |
| 325 | + | |
321 | 326 | | |
322 | 327 | | |
323 | 328 | | |
324 | 329 | | |
325 | | - | |
| 330 | + | |
326 | 331 | | |
327 | 332 | | |
328 | 333 | | |
| |||
1337 | 1342 | | |
1338 | 1343 | | |
1339 | 1344 | | |
1340 | | - | |
| 1345 | + | |
1341 | 1346 | | |
1342 | 1347 | | |
1343 | 1348 | | |
| |||
1406 | 1411 | | |
1407 | 1412 | | |
1408 | 1413 | | |
1409 | | - | |
| 1414 | + | |
1410 | 1415 | | |
1411 | | - | |
| 1416 | + | |
1412 | 1417 | | |
1413 | | - | |
| 1418 | + | |
1414 | 1419 | | |
1415 | 1420 | | |
1416 | 1421 | | |
| |||
1476 | 1481 | | |
1477 | 1482 | | |
1478 | 1483 | | |
1479 | | - | |
| 1484 | + | |
1480 | 1485 | | |
1481 | 1486 | | |
1482 | 1487 | | |
| |||
1604 | 1609 | | |
1605 | 1610 | | |
1606 | 1611 | | |
1607 | | - | |
| 1612 | + | |
1608 | 1613 | | |
1609 | 1614 | | |
1610 | 1615 | | |
| |||
1826 | 1831 | | |
1827 | 1832 | | |
1828 | 1833 | | |
1829 | | - | |
| 1834 | + | |
1830 | 1835 | | |
1831 | 1836 | | |
1832 | 1837 | | |
| |||
1835 | 1840 | | |
1836 | 1841 | | |
1837 | 1842 | | |
1838 | | - | |
| 1843 | + | |
1839 | 1844 | | |
1840 | 1845 | | |
1841 | 1846 | | |
| |||
0 commit comments