All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] nvme-fabrics: bound reconnect_delay, kato and fast_io_fail_tmo
@ 2026-11-13 16:49 Martin George
  2026-11-13 16:50 ` [PATCH v2 1/3] nvme-fabrics: bound reconnect_delay to avoid overflow Martin George
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Martin George @ 2026-11-13 16:49 UTC (permalink / raw)
  To: linux-nvme; +Cc: hch, kbusch, sagi, loberman

reconnect_delay, keep_alive_tmo (kato) and fast_io_fail_tmo are accepted 
in seconds but later multiplied by HZ (and, for kato, by 1000) in 32-bit 
arithmetic, so large values overflow and yield bogus timers. Bound all 
three at parse/store time so the conversions can't wrap.

The target already does this for kato via NVMET_MAX_KATO, and the host 
recently fixed the same class for admin_timeout/io_timeout (4a5aeebf1a00) 
and partly for reconnect_delay (f92fe8dea19c).

Changes since v1:
 - Add patch 3/3 bounding fast_io_fail_tmo, which is the same 
   "seconds * HZ" overflow class and was unbounded in both the parser 
   and the sysfs store (spotted by Laurence Oberman).
 - 2/3: reword the changelog to drop the inaccurate "1000 >= HZ" claim; 
   the bound is safe because kato is unsigned, so "kato * HZ" cannot wrap 
   even where HZ > 1000 (noted by Laurence Oberman). No code change.

Martin George (3):
  nvme-fabrics: bound reconnect_delay to avoid overflow
  nvme-fabrics: bound keep_alive_tmo to avoid overflow
  nvme-fabrics: bound fast_io_fail_tmo to avoid overflow

 drivers/nvme/host/fabrics.c | 10 +++++++---
 drivers/nvme/host/sysfs.c   |  4 +++-
 2 files changed, 10 insertions(+), 4 deletions(-)

-- 
2.53.0



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

* [PATCH v2 1/3] nvme-fabrics: bound reconnect_delay to avoid overflow
  2026-11-13 16:49 [PATCH v2 0/3] nvme-fabrics: bound reconnect_delay, kato and fast_io_fail_tmo Martin George
@ 2026-11-13 16:50 ` Martin George
  2026-11-20 17:55   ` Christoph Hellwig
  2026-11-13 16:50 ` [PATCH v2 2/3] nvme-fabrics: bound keep_alive_tmo " Martin George
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Martin George @ 2026-11-13 16:50 UTC (permalink / raw)
  To: linux-nvme; +Cc: hch, kbusch, sagi, loberman

reconnect_delay is accepted up to INT_MAX, but every consumer computes
"reconnect_delay * HZ" in 32-bit (nvme-tcp, nvme-rdma, nvme-fc), so a
large value wraps into a short, bogus reconnect interval.

Reject values above INT_MAX / HZ in both the option parser and the
sysfs store.

Signed-off-by: Martin George <marting@netapp.com>
Reviewed-by: Laurence Oberman <loberman@redhat.com>
---
 drivers/nvme/host/fabrics.c | 2 +-
 drivers/nvme/host/sysfs.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index c262538523fb..25029978b978 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -893,7 +893,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
 				ret = -EINVAL;
 				goto out;
 			}
-			if (token <= 0) {
+			if (token <= 0 || token > INT_MAX / HZ) {
 				pr_err("Invalid reconnect_delay %d\n", token);
 				ret = -EINVAL;
 				goto out;
diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
index 9672ca3f74d2..8876d8db5401 100644
--- a/drivers/nvme/host/sysfs.c
+++ b/drivers/nvme/host/sysfs.c
@@ -632,7 +632,7 @@ static ssize_t nvme_ctrl_reconnect_delay_store(struct device *dev,
 	if (err)
 		return err;
 
-	if (!v || v > INT_MAX)
+	if (!v || v > INT_MAX / HZ)
 		return -EINVAL;
 
 	ctrl->opts->reconnect_delay = v;
-- 
2.53.0



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

* [PATCH v2 2/3] nvme-fabrics: bound keep_alive_tmo to avoid overflow
  2026-11-13 16:49 [PATCH v2 0/3] nvme-fabrics: bound reconnect_delay, kato and fast_io_fail_tmo Martin George
  2026-11-13 16:50 ` [PATCH v2 1/3] nvme-fabrics: bound reconnect_delay to avoid overflow Martin George
@ 2026-11-13 16:50 ` Martin George
  2026-11-20 17:55   ` Christoph Hellwig
  2026-11-13 16:50 ` [PATCH v2 3/3] nvme-fabrics: bound fast_io_fail_tmo " Martin George
  2026-11-13 16:57 ` [PATCH v2 0/3] nvme-fabrics: bound reconnect_delay, kato and fast_io_fail_tmo Laurence Oberman
  3 siblings, 1 reply; 8+ messages in thread
From: Martin George @ 2026-11-13 16:50 UTC (permalink / raw)
  To: linux-nvme; +Cc: hch, kbusch, sagi, loberman

keep_alive_tmo (kato) is only checked for being negative, yet it is sent
to the controller as "kato * 1000" ms and used as "kato * HZ" jiffies for
the keep-alive timer; a large value overflows both.

Reject values above INT_MAX / 1000 so the millisecond form "kato * 1000"
stays within 32 bits. kato is unsigned, so the "kato * HZ" jiffies form
cannot wrap even on architectures where HZ exceeds 1000 (e.g. alpha).
This mirrors the target, which caps kato via NVMET_MAX_KATO.

Signed-off-by: Martin George <marting@netapp.com>
Reviewed-by: Laurence Oberman <loberman@redhat.com>
---
 drivers/nvme/host/fabrics.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index 25029978b978..b4ca0f9fd703 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -837,7 +837,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
 				goto out;
 			}
 
-			if (token < 0) {
+			if (token < 0 || token > INT_MAX / 1000) {
 				pr_err("Invalid keep_alive_tmo %d\n", token);
 				ret = -EINVAL;
 				goto out;
-- 
2.53.0



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

* [PATCH v2 3/3] nvme-fabrics: bound fast_io_fail_tmo to avoid overflow
  2026-11-13 16:49 [PATCH v2 0/3] nvme-fabrics: bound reconnect_delay, kato and fast_io_fail_tmo Martin George
  2026-11-13 16:50 ` [PATCH v2 1/3] nvme-fabrics: bound reconnect_delay to avoid overflow Martin George
  2026-11-13 16:50 ` [PATCH v2 2/3] nvme-fabrics: bound keep_alive_tmo " Martin George
@ 2026-11-13 16:50 ` Martin George
  2026-11-20 17:56   ` Christoph Hellwig
  2026-11-13 16:57 ` [PATCH v2 0/3] nvme-fabrics: bound reconnect_delay, kato and fast_io_fail_tmo Laurence Oberman
  3 siblings, 1 reply; 8+ messages in thread
From: Martin George @ 2026-11-13 16:50 UTC (permalink / raw)
  To: linux-nvme; +Cc: hch, kbusch, sagi, loberman

fast_io_fail_tmo is accepted up to INT_MAX in both the option parser and
the sysfs store (only negatives are mapped to -1, "off"). It is then
scheduled as "fast_io_fail_tmo * HZ" in nvme_start_failfast_work(). As
the field is a signed int, a large value overflows that multiply and the
failfast work is queued with a bogus (effectively never-firing) delay.

Reject values above INT_MAX / HZ in both the parser and the sysfs store,
matching the reconnect_delay handling.

Suggested-by: Laurence Oberman <loberman@redhat.com>
Signed-off-by: Martin George <marting@netapp.com>
---
 drivers/nvme/host/fabrics.c | 6 +++++-
 drivers/nvme/host/sysfs.c   | 2 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index b4ca0f9fd703..7da6fc344985 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -862,7 +862,11 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
 				ret = -EINVAL;
 				goto out;
 			}
-
+			if (token > INT_MAX / HZ) {
+				pr_err("Invalid fast_io_fail_tmo %d\n", token);
+				ret = -EINVAL;
+				goto out;
+			}
 			if (token >= 0)
 				pr_warn("I/O fail on reconnect controller after %d sec\n",
 					token);
diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
index 8876d8db5401..dc59473f06f3 100644
--- a/drivers/nvme/host/sysfs.c
+++ b/drivers/nvme/host/sysfs.c
@@ -664,6 +664,8 @@ static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,
 
 	if (fast_io_fail_tmo < 0)
 		opts->fast_io_fail_tmo = -1;
+	else if (fast_io_fail_tmo > INT_MAX / HZ)
+		return -EINVAL;
 	else
 		opts->fast_io_fail_tmo = fast_io_fail_tmo;
 	return count;
-- 
2.53.0



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

* Re: [PATCH v2 0/3] nvme-fabrics: bound reconnect_delay, kato and fast_io_fail_tmo
  2026-11-13 16:49 [PATCH v2 0/3] nvme-fabrics: bound reconnect_delay, kato and fast_io_fail_tmo Martin George
                   ` (2 preceding siblings ...)
  2026-11-13 16:50 ` [PATCH v2 3/3] nvme-fabrics: bound fast_io_fail_tmo " Martin George
@ 2026-11-13 16:57 ` Laurence Oberman
  3 siblings, 0 replies; 8+ messages in thread
From: Laurence Oberman @ 2026-11-13 16:57 UTC (permalink / raw)
  To: Martin George, linux-nvme; +Cc: hch, kbusch, sagi

On Fri, 2026-11-13 at 22:19 +0530, Martin George wrote:
> reconnect_delay, keep_alive_tmo (kato) and fast_io_fail_tmo are
> accepted 
> in seconds but later multiplied by HZ (and, for kato, by 1000) in 32-
> bit 
> arithmetic, so large values overflow and yield bogus timers. Bound
> all 
> three at parse/store time so the conversions can't wrap.
> 
> The target already does this for kato via NVMET_MAX_KATO, and the
> host 
> recently fixed the same class for admin_timeout/io_timeout
> (4a5aeebf1a00) 
> and partly for reconnect_delay (f92fe8dea19c).
> 
> Changes since v1:
>  - Add patch 3/3 bounding fast_io_fail_tmo, which is the same 
>    "seconds * HZ" overflow class and was unbounded in both the parser
>    and the sysfs store (spotted by Laurence Oberman).
>  - 2/3: reword the changelog to drop the inaccurate "1000 >= HZ"
> claim; 
>    the bound is safe because kato is unsigned, so "kato * HZ" cannot
> wrap 
>    even where HZ > 1000 (noted by Laurence Oberman). No code change.
> 
> Martin George (3):
>   nvme-fabrics: bound reconnect_delay to avoid overflow
>   nvme-fabrics: bound keep_alive_tmo to avoid overflow
>   nvme-fabrics: bound fast_io_fail_tmo to avoid overflow
> 
>  drivers/nvme/host/fabrics.c | 10 +++++++---
>  drivers/nvme/host/sysfs.c   |  4 +++-
>  2 files changed, 10 insertions(+), 4 deletions(-)

Looks good.

For the V2 series
Reviewed-by: Laurence Oberman <loberman@redhat.com>



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

* Re: [PATCH v2 1/3] nvme-fabrics: bound reconnect_delay to avoid overflow
  2026-11-13 16:50 ` [PATCH v2 1/3] nvme-fabrics: bound reconnect_delay to avoid overflow Martin George
@ 2026-11-20 17:55   ` Christoph Hellwig
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2026-11-20 17:55 UTC (permalink / raw)
  To: Martin George; +Cc: linux-nvme, kbusch, sagi, loberman

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>



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

* Re: [PATCH v2 2/3] nvme-fabrics: bound keep_alive_tmo to avoid overflow
  2026-11-13 16:50 ` [PATCH v2 2/3] nvme-fabrics: bound keep_alive_tmo " Martin George
@ 2026-11-20 17:55   ` Christoph Hellwig
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2026-11-20 17:55 UTC (permalink / raw)
  To: Martin George; +Cc: linux-nvme, hch, kbusch, sagi, loberman

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>



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

* Re: [PATCH v2 3/3] nvme-fabrics: bound fast_io_fail_tmo to avoid overflow
  2026-11-13 16:50 ` [PATCH v2 3/3] nvme-fabrics: bound fast_io_fail_tmo " Martin George
@ 2026-11-20 17:56   ` Christoph Hellwig
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2026-11-20 17:56 UTC (permalink / raw)
  To: Martin George; +Cc: linux-nvme, kbusch, sagi, loberman

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>


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

end of thread, other threads:[~2026-11-20 17:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 16:49 [PATCH v2 0/3] nvme-fabrics: bound reconnect_delay, kato and fast_io_fail_tmo Martin George
2026-11-13 16:50 ` [PATCH v2 1/3] nvme-fabrics: bound reconnect_delay to avoid overflow Martin George
2026-11-20 17:55   ` Christoph Hellwig
2026-11-13 16:50 ` [PATCH v2 2/3] nvme-fabrics: bound keep_alive_tmo " Martin George
2026-11-20 17:55   ` Christoph Hellwig
2026-11-13 16:50 ` [PATCH v2 3/3] nvme-fabrics: bound fast_io_fail_tmo " Martin George
2026-11-20 17:56   ` Christoph Hellwig
2026-11-13 16:57 ` [PATCH v2 0/3] nvme-fabrics: bound reconnect_delay, kato and fast_io_fail_tmo Laurence Oberman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.