* [PATCH next v2] nvdimm: Prevent integer overflow in ramdax_get_config_data()
@ 2025-11-26 12:11 Dan Carpenter
2025-11-26 13:21 ` Mike Rapoport
2025-11-26 16:59 ` Ira Weiny
0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2025-11-26 12:11 UTC (permalink / raw)
To: Mike Rapoport
Cc: Dan Williams, Vishal Verma, Dave Jiang, Ira Weiny, nvdimm,
linux-kernel, kernel-janitors
The "cmd->in_offset" variable comes from the user via the __nd_ioctl()
function. The problem is that the "cmd->in_offset + cmd->in_length"
addition could have an integer wrapping issue if cmd->in_offset is close
to UINT_MAX . Both "cmd->in_offset" and "cmd->in_length" are u32
variables.
Fixes: 43bc0aa19a21 ("nvdimm: allow exposing RAM carveouts as NVDIMM DIMM devices")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
v2: Ira Weiny pointed out that ramdax_set_config_data() needs to be
fixed as well.
drivers/nvdimm/ramdax.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/nvdimm/ramdax.c b/drivers/nvdimm/ramdax.c
index 63cf05791829..954cb7919807 100644
--- a/drivers/nvdimm/ramdax.c
+++ b/drivers/nvdimm/ramdax.c
@@ -143,7 +143,7 @@ static int ramdax_get_config_data(struct nvdimm *nvdimm, int buf_len,
return -EINVAL;
if (struct_size(cmd, out_buf, cmd->in_length) > buf_len)
return -EINVAL;
- if (cmd->in_offset + cmd->in_length > LABEL_AREA_SIZE)
+ if (size_add(cmd->in_offset, cmd->in_length) > LABEL_AREA_SIZE)
return -EINVAL;
memcpy(cmd->out_buf, dimm->label_area + cmd->in_offset, cmd->in_length);
@@ -160,7 +160,7 @@ static int ramdax_set_config_data(struct nvdimm *nvdimm, int buf_len,
return -EINVAL;
if (struct_size(cmd, in_buf, cmd->in_length) > buf_len)
return -EINVAL;
- if (cmd->in_offset + cmd->in_length > LABEL_AREA_SIZE)
+ if (size_add(cmd->in_offset, cmd->in_length) > LABEL_AREA_SIZE)
return -EINVAL;
memcpy(dimm->label_area + cmd->in_offset, cmd->in_buf, cmd->in_length);
--
2.51.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH next v2] nvdimm: Prevent integer overflow in ramdax_get_config_data()
2025-11-26 12:11 [PATCH next v2] nvdimm: Prevent integer overflow in ramdax_get_config_data() Dan Carpenter
@ 2025-11-26 13:21 ` Mike Rapoport
2025-11-26 16:59 ` Ira Weiny
1 sibling, 0 replies; 3+ messages in thread
From: Mike Rapoport @ 2025-11-26 13:21 UTC (permalink / raw)
To: Dan Carpenter
Cc: Dan Williams, Vishal Verma, Dave Jiang, Ira Weiny, nvdimm,
linux-kernel, kernel-janitors
On Wed, Nov 26, 2025 at 03:11:53PM +0300, Dan Carpenter wrote:
> The "cmd->in_offset" variable comes from the user via the __nd_ioctl()
> function. The problem is that the "cmd->in_offset + cmd->in_length"
> addition could have an integer wrapping issue if cmd->in_offset is close
> to UINT_MAX . Both "cmd->in_offset" and "cmd->in_length" are u32
> variables.
>
> Fixes: 43bc0aa19a21 ("nvdimm: allow exposing RAM carveouts as NVDIMM DIMM devices")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> v2: Ira Weiny pointed out that ramdax_set_config_data() needs to be
> fixed as well.
>
> drivers/nvdimm/ramdax.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nvdimm/ramdax.c b/drivers/nvdimm/ramdax.c
> index 63cf05791829..954cb7919807 100644
> --- a/drivers/nvdimm/ramdax.c
> +++ b/drivers/nvdimm/ramdax.c
> @@ -143,7 +143,7 @@ static int ramdax_get_config_data(struct nvdimm *nvdimm, int buf_len,
> return -EINVAL;
> if (struct_size(cmd, out_buf, cmd->in_length) > buf_len)
> return -EINVAL;
> - if (cmd->in_offset + cmd->in_length > LABEL_AREA_SIZE)
> + if (size_add(cmd->in_offset, cmd->in_length) > LABEL_AREA_SIZE)
> return -EINVAL;
>
> memcpy(cmd->out_buf, dimm->label_area + cmd->in_offset, cmd->in_length);
> @@ -160,7 +160,7 @@ static int ramdax_set_config_data(struct nvdimm *nvdimm, int buf_len,
> return -EINVAL;
> if (struct_size(cmd, in_buf, cmd->in_length) > buf_len)
> return -EINVAL;
> - if (cmd->in_offset + cmd->in_length > LABEL_AREA_SIZE)
> + if (size_add(cmd->in_offset, cmd->in_length) > LABEL_AREA_SIZE)
> return -EINVAL;
>
> memcpy(dimm->label_area + cmd->in_offset, cmd->in_buf, cmd->in_length);
> --
> 2.51.0
>
--
Sincerely yours,
Mike.
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH next v2] nvdimm: Prevent integer overflow in ramdax_get_config_data()
2025-11-26 12:11 [PATCH next v2] nvdimm: Prevent integer overflow in ramdax_get_config_data() Dan Carpenter
2025-11-26 13:21 ` Mike Rapoport
@ 2025-11-26 16:59 ` Ira Weiny
1 sibling, 0 replies; 3+ messages in thread
From: Ira Weiny @ 2025-11-26 16:59 UTC (permalink / raw)
To: Dan Carpenter, Mike Rapoport
Cc: Dan Williams, Vishal Verma, Dave Jiang, Ira Weiny, nvdimm,
linux-kernel, kernel-janitors
Dan Carpenter wrote:
> The "cmd->in_offset" variable comes from the user via the __nd_ioctl()
> function. The problem is that the "cmd->in_offset + cmd->in_length"
> addition could have an integer wrapping issue if cmd->in_offset is close
> to UINT_MAX . Both "cmd->in_offset" and "cmd->in_length" are u32
> variables.
>
> Fixes: 43bc0aa19a21 ("nvdimm: allow exposing RAM carveouts as NVDIMM DIMM devices")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Staged.
Thanks!
Ira
[snip]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-11-26 16:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-26 12:11 [PATCH next v2] nvdimm: Prevent integer overflow in ramdax_get_config_data() Dan Carpenter
2025-11-26 13:21 ` Mike Rapoport
2025-11-26 16:59 ` Ira Weiny
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox