mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] nbd: clamp the timeout before converting it to jiffies
@ 2026-08-17 14:10 Tao Cui
  2026-08-18  7:00 ` yu kuai
  0 siblings, 1 reply; 2+ messages in thread
From: Tao Cui @ 2026-08-17 14:10 UTC (permalink / raw)
  To: josef, axboe, hch, yukuai, linux-block
  Cc: nbd, linux-kernel, mchristi, cui.tao, Tao Cui

From: Tao Cui <cuitao@kylinos.cn>

nbd_set_cmd_timeout() stores timeout * HZ into tag_set.timeout, an
unsigned int, and passes the same product to blk_queue_rq_timeout()
without any range check.  A large timeout (2^32 seconds, say)
truncates to 0 instead of being a very long timeout.

Clamp the timeout to UINT_MAX / HZ seconds first.

Setting NBD_SET_TIMEOUT to 2^32 left the debugfs timeout at 0 before
this change and at 4294967000 after it.

Fixes: 55313e92bd17 ("nbd: add set cmd timeout helper")
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
 drivers/block/nbd.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 8f10762e90ef..1874c1a81d3a 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -1619,6 +1619,10 @@ static void nbd_clear_sock_ioctl(struct nbd_device *nbd)
 
 static void nbd_set_cmd_timeout(struct nbd_device *nbd, u64 timeout)
 {
+	/* clamp so that timeout * HZ fits in an unsigned int */
+	if (timeout > UINT_MAX / HZ)
+		timeout = UINT_MAX / HZ;
+
 	nbd->tag_set.timeout = timeout * HZ;
 	if (timeout)
 		blk_queue_rq_timeout(nbd->disk->queue, timeout * HZ);
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] nbd: clamp the timeout before converting it to jiffies
  2026-08-17 14:10 [PATCH] nbd: clamp the timeout before converting it to jiffies Tao Cui
@ 2026-08-18  7:00 ` yu kuai
  0 siblings, 0 replies; 2+ messages in thread
From: yu kuai @ 2026-08-18  7:00 UTC (permalink / raw)
  To: Tao Cui, josef, axboe, hch, linux-block, yu kuai
  Cc: nbd, linux-kernel, mchristi, Tao Cui

在 2026/8/17 22:10, Tao Cui 写道:

> From: Tao Cui<cuitao@kylinos.cn>
>
> nbd_set_cmd_timeout() stores timeout * HZ into tag_set.timeout, an
> unsigned int, and passes the same product to blk_queue_rq_timeout()
> without any range check.  A large timeout (2^32 seconds, say)
> truncates to 0 instead of being a very long timeout.
>
> Clamp the timeout to UINT_MAX / HZ seconds first.
>
> Setting NBD_SET_TIMEOUT to 2^32 left the debugfs timeout at 0 before
> this change and at 4294967000 after it.
>
> Fixes: 55313e92bd17 ("nbd: add set cmd timeout helper")
> Signed-off-by: Tao Cui<cuitao@kylinos.cn>
> ---
>   drivers/block/nbd.c | 4 ++++
>   1 file changed, 4 insertions(+)
Reviewed-by: Yu Kuai <yukuai@fygo.io>

-- 
Thanks,
Kuai

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-18  7:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-17 14:10 [PATCH] nbd: clamp the timeout before converting it to jiffies Tao Cui
2026-08-18  7:00 ` yu kuai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®