net/mlx5: Fix uninitialized variable bug in outlen_write()
authorYueHaibing <yuehaibing@huawei.com>
Mon, 21 Nov 2022 11:22:04 +0000 (19:22 +0800)
committerSaeed Mahameed <saeedm@nvidia.com>
Thu, 24 Nov 2022 08:03:21 +0000 (00:03 -0800)
If sscanf() return 0, outlen is uninitialized and used in kzalloc(),
this is unexpected. We should return -EINVAL if the string is invalid.

Fixes: e126ba97dba9 ("mlx5: Add driver for Mellanox Connect-IB adapters")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/cmd.c

index 74bd05e..e7a894b 100644 (file)
@@ -1497,8 +1497,8 @@ static ssize_t outlen_write(struct file *filp, const char __user *buf,
                return -EFAULT;
 
        err = sscanf(outlen_str, "%d", &outlen);
-       if (err < 0)
-               return err;
+       if (err != 1)
+               return -EINVAL;
 
        ptr = kzalloc(outlen, GFP_KERNEL);
        if (!ptr)