Re: [PATCH v2] scsi: handle out-of-range SG_SET_TIMEOUT values

From: Bart Van Assche

Date: Wed Oct 21 2026 - 16:29:28 EST


On 10/21/26 11:18 AM, Wang Yingjie wrote:
diff --git a/block/bsg.c b/block/bsg.c
index 82aaf3cee5825..632b3f6d98b29 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -132,7 +132,11 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
case SG_SET_TIMEOUT:
if (get_user(val, intp))
return -EFAULT;
- bd->timeout = clock_t_to_jiffies(val);
+ if (val < 0)
+ return -EIO;
+ bd->timeout = min_t(unsigned long, clock_t_to_jiffies(val),
+ min_t(unsigned long, UINT_MAX,
+ MAX_JIFFY_OFFSET));

MAX_JIFFY_OFFSET is guaranteed to be larger than UINT_MAX so the second
min_t() expression can be changed into UINT_MAX. Additionally, please
use min() instead of min_t(). min() has been modified recently such that
it allows some type promotions.

Thanks,

Bart.