Skip to contentSkip to conversation

nvdimm: Prevent integer overflow in ramdax_get_config_data()

PATCH Superseded Dan Carpenter 2 participants 3 messages Nov 25, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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 . The "cmd->in_length" variable has been capped, but the "cmd->in_offset" variable has not. Both of these variables are type u32.

Fixes 43bc0aa19a21 ("nvdimm: allow exposing RAM carveouts as NVDIMM DIMM devices")
---
 drivers/nvdimm/ramdax.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvdimm/ramdax.c +1 -1
index 63cf05791829..faa6f3101972 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);
Signature · 1 line
2.51.0
#1 lore raw
Quoted 5 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 . The "cmd->in_length" variable has been capped, but the "cmd->in_offset" variable has not. Both of these variables are type u32.

Does ramdax_set_config_data() also need this? I'm not quite following where in_length is capped so I'm inclined to add size_add in both set and get.

Ira

Quoted 23 lines
Fixes 43bc0aa19a21 ("nvdimm: allow exposing RAM carveouts as NVDIMM DIMM devices")
---
 drivers/nvdimm/ramdax.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvdimm/ramdax.c +1 -1
index 63cf05791829..faa6f3101972 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);
Signature · 1 line
2.51.0
#2 lore raw
Quoted 8 lines · Ira Weiny
Quoted 5 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 . The "cmd->in_length" variable has been capped, but the "cmd->in_offset" variable has not. Both of these variables are type u32.

Does ramdax_set_config_data() also need this?

Yes. It does. These are from Smatch warnings, right. They take a few rebuilds for the taint information to propagate from the ioctl to the ramdax_get_config_data() function. When I rebuilt it, then it propagates to both so I would have seen the ramdax_set_config_data() tomorrow.

But they're called from the same function so the taint data should have propagated to both at the same time... WTF? I don't know what happened. Anyway, I will fix that and resend.

Thanks for noticing.

Quoted 2 lines

I'm not quite following where in_length is capped so I'm inclined to
add size_add in both set and get.

I meant that the if (struct_size(cmd, in_buf, cmd->in_length) > buf_len) line checks that cmd->in_length is okay.

regards,
dan carpenter