Skip to content

Commit 30065e7

Browse files
Dan Carpenterweiny2
authored andcommitted
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: 43bc0aa ("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> Link: https://patch.msgid.link/aSbuiYCznEIZDa02@stanley.mountain Signed-off-by: Ira Weiny <ira.weiny@intel.com>
1 parent acd9ea1 commit 30065e7

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/nvdimm/ramdax.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static int ramdax_get_config_data(struct nvdimm *nvdimm, int buf_len,
143143
return -EINVAL;
144144
if (struct_size(cmd, out_buf, cmd->in_length) > buf_len)
145145
return -EINVAL;
146-
if (cmd->in_offset + cmd->in_length > LABEL_AREA_SIZE)
146+
if (size_add(cmd->in_offset, cmd->in_length) > LABEL_AREA_SIZE)
147147
return -EINVAL;
148148

149149
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,
160160
return -EINVAL;
161161
if (struct_size(cmd, in_buf, cmd->in_length) > buf_len)
162162
return -EINVAL;
163-
if (cmd->in_offset + cmd->in_length > LABEL_AREA_SIZE)
163+
if (size_add(cmd->in_offset, cmd->in_length) > LABEL_AREA_SIZE)
164164
return -EINVAL;
165165

166166
memcpy(dimm->label_area + cmd->in_offset, cmd->in_buf, cmd->in_length);

0 commit comments

Comments
 (0)