Skip to content

Commit d49ba4b

Browse files
ndctl/namespace: protect against under|over-flow w bad param.align
A coverity scan highlighted an integer underflow when param.align is 0, and an integer overflow when the parsing of param.align fails and returns ULLONG_MAX. Add explicit checks for both values. Reviewed-by: Dave Jiang <[email protected]> Link: https://lore.kernel.org/r/5f8a8a6cf332ec9ceb636180b9dd5cbf801f1e6e.1741304303.git.alison.schofield@intel.com Signed-off-by: Alison Schofield <[email protected]>
1 parent 901b60c commit d49ba4b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ndctl/namespace.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -2087,7 +2087,11 @@ static int namespace_rw_infoblock(struct ndctl_namespace *ndns,
20872087
unsigned long long size = parse_size64(param.size);
20882088
align = parse_size64(param.align);
20892089

2090-
if (align < ULLONG_MAX && !IS_ALIGNED(size, align)) {
2090+
if (align == 0 || align == ULLONG_MAX) {
2091+
error("invalid alignment:%s\n", param.align);
2092+
rc = -EINVAL;
2093+
}
2094+
if (!IS_ALIGNED(size, align)) {
20912095
error("--size=%s not aligned to %s\n", param.size,
20922096
param.align);
20932097

0 commit comments

Comments
 (0)