Skip to contentSkip to conversation

nvdimm: Prevent integer overflow in ramdax_get_config_data()

PATCH In review Dan Carpenter 3 participants 3 messages Nov 26, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nvdimm: Prevent integer overflow in ramdax_get_config_data()

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")

---
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(-)
drivers/nvdimm/ramdax.c +2 -2
index 63cf05791829..954cb7919807 100644
@@ -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);
Signature · 1 line
2.51.0
Acked-by on v2 1/1
#1 lore raw
Quoted 8 lines · Dan Carpenter

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")
Quoted 32 lines

---
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(-)
drivers/nvdimm/ramdax.c +2 -2
index 63cf05791829..954cb7919807 100644
@@ -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);
Signature · 1 line
2.51.0
Signature · 2 lines
Sincerely yours,
Mike.
#2 lore raw
In reply to Dan Carpenter
Quoted 8 lines · Dan Carpenter

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")

Staged.

Thanks!
Ira

[snip]