nvme-fabrics: bound reconnect_delay, kato and fast_io_fail_tmo
v2 cover nvme-fabrics: bound reconnect_delay, kato and fast_io_fail_tmo
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(-)
Signature · 1 line
2.53.0
PATCH v2 1/3 nvme-fabrics: bound reconnect_delay to avoid overflow
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.
--- drivers/nvme/host/fabrics.c | 2 +- drivers/nvme/host/sysfs.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/nvme/host/fabrics.c +1 -1
@@ -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;
drivers/nvme/host/sysfs.c +1 -1
@@ -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;
Signature · 1 line
2.53.0
Re: [PATCH v2 1/3] nvme-fabrics: bound reconnect_delay to avoid overflow
Looks good:
PATCH v2 2/3 nvme-fabrics: bound keep_alive_tmo to avoid overflow
In reply to Martin Georgekeep_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.
--- drivers/nvme/host/fabrics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/fabrics.c +1 -1
@@ -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;
Signature · 1 line
2.53.0
Re: [PATCH v2 2/3] nvme-fabrics: bound keep_alive_tmo to avoid overflow
Looks good:
PATCH v2 3/3 nvme-fabrics: bound fast_io_fail_tmo to avoid overflow
In reply to Martin Georgefast_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.
--- drivers/nvme/host/fabrics.c | 6 +++++- drivers/nvme/host/sysfs.c | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/nvme/host/fabrics.c +5 -1
@@ -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);
drivers/nvme/host/sysfs.c +2 -0
@@ -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;
Signature · 1 line
2.53.0
Re: [PATCH v2 3/3] nvme-fabrics: bound fast_io_fail_tmo to avoid overflow
Looks good:
Quoted 24 lines · Martin George
reconnect_delay,keep_alive_tmo(kato) andfast_io_fail_tmoare 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 forreconnect_delay(f92fe8dea19c).Changes since v1:
- Add patch 3/3 boundingfast_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.
Quoted 8 lines
Martin George (3):
nvme-fabrics: boundreconnect_delayto avoid overflow
nvme-fabrics: boundkeep_alive_tmoto avoid overflow
nvme-fabrics: boundfast_io_fail_tmoto avoid overflowdrivers/nvme/host/fabrics.c | 10 +++++++---
drivers/nvme/host/sysfs.c | 4 +++-2 files changed, 10 insertions(+), 4 deletions(-)
Looks good.
For the V2 series
Quoted 10 lines · Martin George
reconnect_delay,keep_alive_tmo(kato) andfast_io_fail_tmoare 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 forreconnect_delay(f92fe8dea19c).[...]
Thanks, applied to nvme-7.4.
[1/3] nvme-fabrics: bound reconnect_delay to avoid overflow
commit: af904d3b2c6d8581b03716f35a814e3899bc1ec9
[2/3] nvme-fabrics: bound keep_alive_tmo to avoid overflow
commit: 95312acf502748e63623069380c39fe5f055d245
[3/3] nvme-fabrics: bound fast_io_fail_tmo to avoid overflow
commit: ed666c3cbdce1c72521db41270694ff1e1b8631d--
Keith Busch <[email protected]>