linux/Documentation
Justin Stitt d1297c83bc scsi: sr: Fix unintentional arithmetic wraparound
[ Upstream commit 9fad9d560a ]

Running syzkaller with the newly reintroduced signed integer overflow
sanitizer produces this report:

[   65.194362] ------------[ cut here ]------------
[   65.197752] UBSAN: signed-integer-overflow in ../drivers/scsi/sr_ioctl.c:436:9
[   65.203607] -2147483648 * 177 cannot be represented in type 'int'
[   65.207911] CPU: 2 PID: 10416 Comm: syz-executor.1 Not tainted 6.8.0-rc2-00035-gb3ef86b5a957 #1
[   65.213585] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
[   65.219923] Call Trace:
[   65.221556]  <TASK>
[   65.223029]  dump_stack_lvl+0x93/0xd0
[   65.225573]  handle_overflow+0x171/0x1b0
[   65.228219]  sr_select_speed+0xeb/0xf0
[   65.230786]  ? __pm_runtime_resume+0xe6/0x130
[   65.233606]  sr_block_ioctl+0x15d/0x1d0
...

Historically, the signed integer overflow sanitizer did not work in the
kernel due to its interaction with `-fwrapv` but this has since been
changed [1] in the newest version of Clang. It was re-enabled in the kernel
with Commit 557f8c582a ("ubsan: Reintroduce signed overflow sanitizer").

Firstly, let's change the type of "speed" to unsigned long as
sr_select_speed()'s only caller passes in an unsigned long anyways.

$ git grep '\.select_speed'
|	drivers/scsi/sr.c:      .select_speed           = sr_select_speed,
...
|	static int cdrom_ioctl_select_speed(struct cdrom_device_info *cdi,
|	                unsigned long arg)
|	{
|	        ...
|	        return cdi->ops->select_speed(cdi, arg);
|	}

Next, let's add an extra check to make sure we don't exceed 0xffff/177
(350) since 0xffff is the max speed. This has two benefits: 1) we deal
with integer overflow before it happens and 2) we properly respect the
max speed of 0xffff. There are some "magic" numbers here but I did not
want to change more than what was necessary.

Link: https://github.com/llvm/llvm-project/pull/82432 [1]
Closes: https://github.com/KSPP/linux/issues/357
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Justin Stitt <justinstitt@google.com>
Link: https://lore.kernel.org/r/20240508-b4-b4-sio-sr_select_speed-v2-1-00b68f724290@google.com
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-07-25 09:53:19 +02:00
..
ABI block: add a partscan sysfs attribute for disks 2024-05-25 16:30:56 +02:00
accel
accounting
admin-guide cifs: fix setting SecurityFlags to true 2024-07-18 13:22:44 +02:00
arch Documentation/x86: Fix title underline length 2024-03-25 11:29:16 +01:00
block
bpf bpf, docs: Rename legacy conformance group to packet 2024-03-04 14:31:06 +01:00
cdrom scsi: sr: Fix unintentional arithmetic wraparound 2024-07-25 09:53:19 +02:00
core-api Documentation/core-api: Update events_freezable_power references. 2024-04-03 08:45:18 -10:00
cpu-freq
crypto
dev-tools Documentation: dev-tools: Add link to RV docs 2024-03-29 08:27:21 -06:00
devicetree Revert "dt-bindings: cache: qcom,llcc: correct QDU1000 reg entries" 2024-07-18 13:22:54 +02:00
doc-guide docs: drop the version constraints for sphinx and dependencies 2024-03-03 08:17:20 -07:00
driver-api fpga: region: add owner module and take its refcount 2024-06-12 11:39:13 +02:00
fault-injection Fixed case issue with 'fault-injection' in documentation 2024-02-21 13:44:21 -07:00
fb
features membarrier: riscv: Provide core serializing command 2024-02-15 08:04:14 -08:00
filesystems Documentation: filesystems: Add bcachefs toctree 2024-04-06 13:50:26 -04:00
firmware_class
firmware-guide More ACPI updates for 6.9-rc1 2024-03-19 11:15:14 -07:00
fpga
gpu drm-misc-next for v6.9: 2024-02-26 09:51:49 +01:00
hid
hwmon hwmon: (aspeed-g6-pwm-tacho): Support for ASPEED g6 PWM/Fan tach 2024-03-07 10:50:16 -08:00
i2c Documentation: i2c: Document that client auto-detection is a legacy mechanism 2024-03-07 09:42:09 +01:00
iio docs: iio: adis16475: fix device files tables 2024-06-12 11:39:15 +02:00
images
infiniband
input
isdn
kbuild kbuild: doc: Update default INSTALL_MOD_DIR from extra to updates 2024-07-05 09:38:06 +02:00
kernel-hacking
leds
litmus-tests
livepatch
locking
maintainer
mhi
misc-devices
mm mm: fix race between __split_huge_pmd_locked() and GUP-fast 2024-06-16 13:51:04 +02:00
netlabel
netlink netlink: specs: Add missing bridge linkinfo attrs 2024-05-06 19:06:07 -07:00
networking Revert "xsk: Document ability to redirect to any socket bound to the same umem" 2024-06-16 13:51:10 +02:00
nvdimm
nvme
PCI
pcmcia
peci
power Documentation: power: Fix typo in suspend and interrupts doc 2024-03-13 20:51:11 +01:00
process Documentation: embargoed-hardware-issues.rst: Add myself for Power 2024-04-11 15:21:18 +02:00
RCU A moderatly busy cycle for development this time around. 2024-03-12 15:18:34 -07:00
rust docs: rust: fix improper rendering in Arch Support page 2024-03-31 20:45:18 +02:00
scheduler A single update for the documentation of the base_slice_ns tunable to 2024-03-24 11:11:05 -07:00
scsi
security
sound ALSA: doc: Use DEFINE_SIMPLE_DEV_PM_OPS() 2024-02-12 11:50:26 +01:00
sphinx docs: kernel_include.py: Cope with docutils 0.21 2024-05-25 16:30:56 +02:00
sphinx-static
spi spi: docs: spidev: fix echo command format 2024-03-19 18:37:55 +00:00
staging docs: staging: fix typo in docs 2024-02-08 15:38:21 -07:00
target
tee
timers sched/isolation: Prevent boot crash when the boot CPU is nohz_full 2024-04-28 10:07:12 +02:00
tools tools/rtla: Add -U/--user-load option to timerlat 2024-03-20 05:39:06 +01:00
trace tracing/user_events: Document multi-format flag 2024-03-18 10:13:16 -04:00
translations docs/zh_CN: core-api: Update translation of workqueue.rst to 6.9-rc1 2024-04-03 08:46:56 -10:00
usb Documentation: usb: Document FunctionFS DMABUF API 2024-02-17 17:00:09 +01:00
userspace-api media updates for v6.9-rc1 2024-03-15 11:36:54 -07:00
virt Documentation: kvm/sev: clarify usage of KVM_MEMORY_ENCRYPT_OP 2024-03-18 19:03:53 -04:00
w1 w1: add UART w1 bus driver 2024-02-15 15:02:33 +01:00
watchdog
wmi platform/x86: wmi: Update documentation regarding _WED 2024-02-27 14:44:31 +02:00
.gitignore
atomic_bitops.txt
atomic_t.txt
Changes
CodingStyle
conf.py docs: Restore "smart quotes" for quotes 2024-02-28 15:48:18 -07:00
docutils.conf
dontdiff
index.rst A moderatly busy cycle for development this time around. 2024-03-12 15:18:34 -07:00
Kconfig
Makefile docs: Makefile: Add dependency to $(YNL_INDEX) for targets other than htmldocs 2024-03-05 11:06:43 -07:00
memory-barriers.txt
SubmittingPatches
subsystem-apis.rst