Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

authored by

Dan Carpenter and committed by
Ira Weiny
30065e73 acd9ea17

+2 -2
+2 -2
drivers/nvdimm/ramdax.c
··· 143 143 return -EINVAL; 144 144 if (struct_size(cmd, out_buf, cmd->in_length) > buf_len) 145 145 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) 147 147 return -EINVAL; 148 148 149 149 memcpy(cmd->out_buf, dimm->label_area + cmd->in_offset, cmd->in_length); ··· 160 160 return -EINVAL; 161 161 if (struct_size(cmd, in_buf, cmd->in_length) > buf_len) 162 162 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) 164 164 return -EINVAL; 165 165 166 166 memcpy(dimm->label_area + cmd->in_offset, cmd->in_buf, cmd->in_length);