]> Gentwo Git Trees - linux/.git/commitdiff
nvdimm: Prevent integer overflow in ramdax_get_config_data()
authorDan Carpenter <dan.carpenter@linaro.org>
Wed, 26 Nov 2025 12:11:53 +0000 (15:11 +0300)
committerIra Weiny <ira.weiny@intel.com>
Wed, 26 Nov 2025 16:58:23 +0000 (10:58 -0600)
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>
drivers/nvdimm/ramdax.c

index 63cf057918290b568c27bd497e3962a8f7a41062..954cb79198070a3192fd02a3bed7da7c95e7ac9f 100644 (file)
@@ -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);