The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Tao Cui <cui.tao@linux.dev>
To: josef@toxicpanda.com, axboe@kernel.dk, hch@lst.de,
	yukuai@kernel.org, linux-block@vger.kernel.org
Cc: nbd@other.debian.org, linux-kernel@vger.kernel.org,
	mchristi@redhat.com, cui.tao@linux.dev,
	Tao Cui <cuitao@kylinos.cn>
Subject: [PATCH] nbd: clamp the timeout before converting it to jiffies
Date: Mon, 17 Aug 2026 22:10:27 +0800	[thread overview]
Message-ID: <20260817141027.48423-1-cui.tao@linux.dev> (raw)

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


                 reply	other threads:[~2026-08-17 14:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260817141027.48423-1-cui.tao@linux.dev \
    --to=cui.tao@linux.dev \
    --cc=axboe@kernel.dk \
    --cc=cuitao@kylinos.cn \
    --cc=hch@lst.de \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchristi@redhat.com \
    --cc=nbd@other.debian.org \
    --cc=yukuai@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox