]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
RDMA/uverbs: Don't overwrite NULL pointer with ZERO_SIZE_PTR
authorLeon Romanovsky <leonro@mellanox.com>
Sun, 24 Jun 2018 08:23:47 +0000 (11:23 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 3 Oct 2018 23:59:13 +0000 (16:59 -0700)
[ Upstream commit a5cc9831af05e658543593abaee45a29d061bac4 ]

Number of specs is provided by user and in valid case can be equal to zero.
Such argument causes to call to kcalloc() with zero-length request and in
return the ZERO_SIZE_PTR is assigned. This pointer is different from NULL
and makes various if (..) checks to success.

Fixes: b6ba4a9aa59f ("IB/uverbs: Add support for flow counters")
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/infiniband/core/uverbs_cmd.c

index 583d3a10b94057e64615d2b0de1b3a08dc2e8c70..0e5eb0f547d396706b761eaa190792191abf5abb 100644 (file)
@@ -2812,6 +2812,9 @@ static struct ib_uflow_resources *flow_resources_alloc(size_t num_specs)
        if (!resources)
                goto err_res;
 
+       if (!num_specs)
+               goto out;
+
        resources->counters =
                kcalloc(num_specs, sizeof(*resources->counters), GFP_KERNEL);
 
@@ -2824,8 +2827,8 @@ static struct ib_uflow_resources *flow_resources_alloc(size_t num_specs)
        if (!resources->collection)
                goto err_collection;
 
+out:
        resources->max = num_specs;
-
        return resources;
 
 err_collection: