nvme-fabrics: bound reconnect_delay and keep_alive_tmo
cover nvme-fabrics: bound reconnect_delay and keep_alive_tmo
reconnect_delay and keep_alive_tmo (kato) 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 both 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).
Martin George (2):
nvme-fabrics: bound reconnect_delay to avoid timer overflow
nvme-fabrics: bound keep_alive_tmo to avoid overflow
drivers/nvme/host/fabrics.c | 4 ++-- drivers/nvme/host/sysfs.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/2 nvme-fabrics: bound reconnect_delay to avoid timer 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
PATCH 2/2 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, which (as 1000 >= HZ) covers both conversions, as the target already does 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
Quoted 13 lines · Martin George
reconnect_delayandkeep_alive_tmo(kato) 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 both 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).
Quoted 7 lines
Martin George (2):
nvme-fabrics: boundreconnect_delayto avoid timer overflow
nvme-fabrics: boundkeep_alive_tmoto avoid overflowdrivers/nvme/host/fabrics.c | 4 ++--
drivers/nvme/host/sysfs.c | 2 +-2 files changed, 3 insertions(+), 3 deletions(-)
For the series:
Looks good
One thought: fast_io_fail_tmo looks like the same class -- it's scheduled as fast_io_fail_tmo * HZ in nvme_start_failfast_work() and isn't upper-bounded in the parser or sysfs store. Might be worth folding into this series.
Minor nit on 2/2: "1000 >= HZ" doesn't hold on every arch (alpha allows HZ=1024/1200), though kato being unsigned keeps it safe here.
Quoted 26 lines · Laurence Oberman
Quoted 15 lines · Martin George
reconnect_delayandkeep_alive_tmo(kato) 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 both 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).Quoted 7 lines
Martin George (2):
nvme-fabrics: boundreconnect_delayto avoid timer overflow
nvme-fabrics: boundkeep_alive_tmoto avoid overflowdrivers/nvme/host/fabrics.c | 4 ++--
drivers/nvme/host/sysfs.c | 2 +-2 files changed, 3 insertions(+), 3 deletions(-)For the series:
Quoted 9 lines
Looks good
Reviewed-by Laurence Oberman <[email protected]>One thought:
fast_io_fail_tmolooks like the same class -- it's scheduled asfast_io_fail_tmo* HZ innvme_start_failfast_work()and isn't upper-bounded in the parser or sysfs store. Might be worth folding into this series.
Good catch. fast_io_fail_tmo seems to be arguably worse since it is a signed int (so "* HZ" is signed overflow). I'll add a 3/3 patch bounding it at INT_MAX / HZ in the parser and sysfs store.
Quoted 2 lines
Minor nit on 2/2: "1000 >= HZ" doesn't hold on every arch (alpha allows HZ=1024/1200), though kato being unsigned keeps it safe here.
Right, I'll drop that wording. The bound should be fine (INT_MAX / 1000 keeps "kato * 1000" in range, and kato being unsigned keeps "kato * HZ" from wrapping) - just a changelog reword, no code change.
Thanks for the review comments.
-Martin