linux/drivers/block
Nick Desaulniers 41e76c6a3c nbd: use shifts rather than multiplies
commit fad7cd3310 ("nbd: add the check to prevent overflow in
__nbd_ioctl()") raised an issue from the fallback helpers added in
commit f0907827a8 ("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 76ae847497 ("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: stable@vger.kernel.org
Cc: Arnd Bergmann <arnd@kernel.org>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Link: https://github.com/ClangBuiltLinux/linux/issues/1438
Link: https://lore.kernel.org/all/20210909182525.372ee687@canb.auug.org.au/
Link: https://lore.kernel.org/stable/CAHk-=whiQBofgis_rkniz8GBP9wZtSZdcDEffgSLO62BUGV3gg@mail.gmail.com/
Reported-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Reported-by: Nathan Chancellor <nathan@kernel.org>
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Suggested-by: Kees Cook <keescook@chromium.org>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Suggested-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
Link: https://lore.kernel.org/r/20210920232533.4092046-1-ndesaulniers@google.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2021-09-29 20:31:41 -06:00
..
aoe for-5.14/drivers-2021-06-29 2021-06-30 12:21:16 -07:00
drbd block: move the bdi from the request_queue to the gendisk 2021-08-09 11:53:23 -06:00
mtip32xx mtip32xx: use blk_mq_alloc_disk and blk_cleanup_disk 2021-06-30 15:34:04 -06:00
null_blk null_blk: add error handling support for add_disk() 2021-08-23 12:55:46 -06:00
paride SCSI misc on 20210902 2021-09-02 15:09:46 -07:00
rnbd block/rnbd: Use sysfs_emit instead of s*printf function for sysfs show 2021-08-02 13:37:40 -06:00
rsxx for-5.14/drivers-2021-06-29 2021-06-30 12:21:16 -07:00
xen-blkback isystem: trim/fixup stdarg.h and other headers 2021-08-19 09:02:55 +09:00
zram Merge branch 'akpm' (patches from Andrew) 2021-07-02 12:08:10 -07:00
amiflop.c amiflop: use blk_mq_alloc_disk and blk_cleanup_disk 2021-06-11 11:54:43 -06:00
ataflop.c ataflop: use blk_mq_alloc_disk and blk_cleanup_disk 2021-06-11 11:54:43 -06:00
brd.c block: move some macros to blkdev.h 2021-08-11 19:40:28 -06:00
cryptoloop.c cryptoloop: add a deprecation warning 2021-08-27 10:44:54 -06:00
floppy.c Revert "floppy: reintroduce O_NDELAY fix" 2021-08-28 11:16:47 +03:00
Kconfig SCSI misc on 20210902 2021-09-02 15:09:46 -07:00
loop.c loop: reduce the loop_ctl_mutex scope 2021-09-03 22:14:40 -06:00
loop.h loop: reduce the loop_ctl_mutex scope 2021-09-03 22:14:40 -06:00
Makefile drivers/block: remove the umem driver 2021-03-24 06:57:40 -06:00
n64cart.c n64cart: fix return value check in n64cart_probe() 2021-09-09 14:24:02 -06:00
nbd.c nbd: use shifts rather than multiplies 2021-09-29 20:31:41 -06:00
pktcdvd.c block: move the bdi from the request_queue to the gendisk 2021-08-09 11:53:23 -06:00
ps3disk.c ps3disk: use memcpy_{from,to}_bvec 2021-08-02 13:37:27 -06:00
ps3vram.c ps3vram: use bvec_virt 2021-08-16 10:50:33 -06:00
rbd_types.h libceph, rbd: replace zero-length array with flexible-array 2020-06-01 13:22:53 +02:00
rbd.c rbd: use bvec_virt 2021-08-16 10:50:33 -06:00
sunvdc.c Char / Misc driver updates for 5.14-rc1 2021-07-05 13:42:16 -07:00
swim3.c swim3: use blk_mq_alloc_disk 2021-06-11 11:53:02 -06:00
swim_asm.S
swim.c swim: use blk_mq_alloc_disk 2021-06-11 11:53:03 -06:00
sx8.c sx8: use the internal state machine to check if del_gendisk needs to be called 2021-08-12 10:29:36 -06:00
virtio_blk.c virtio,vdpa,vhost: features, fixes 2021-09-11 14:48:42 -07:00
xen-blkfront.c xen: branch for v5.15-rc1 2021-09-02 13:20:11 -07:00
z2ram.c for-5.14/drivers-2021-06-29 2021-06-30 12:21:16 -07:00