aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/infiniband/core/sysfs.c
diff options
context:
space:
mode:
authorColin Ian King <colin.king@canonical.com>2016-06-01 14:06:36 -0400
committerDoug Ledford <dledford@redhat.com>2016-06-06 19:22:18 -0400
commit0147ebcf8927f09e1923114092f6b14c1de75a95 (patch)
treef11bcfbdf15e37a0998c16ebdde94ad070448350 /drivers/infiniband/core/sysfs.c
parentda1f857be62ca0472024da37eab068b3b8ce0a15 (diff)
IB/core: fix null pointer deref and mem leak in error handling
The current error handling in setup_hw_stats has a couple of issues. It is possible to generate a null pointer deference on the kfree of hsag->attrs[i] because two of the early error exit paths jump to the kfree when hsags NULL and not allocated. Fix this by moving the kfree on stats and jumping to that, avoiding the hsag freeing. Secondly, there is a memory leak of stats if the hsag allocation fails; instead of returning, jump to the kfree on stats. Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Doug Ledford <dledford@redhat.com>
Diffstat (limited to 'drivers/infiniband/core/sysfs.c')
-rw-r--r--drivers/infiniband/core/sysfs.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 5e573bb18660..ed04a7bd4481 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -899,14 +899,14 @@ static void setup_hw_stats(struct ib_device *device, struct ib_port *port,
899 return; 899 return;
900 900
901 if (!stats->names || stats->num_counters <= 0) 901 if (!stats->names || stats->num_counters <= 0)
902 goto err; 902 goto err_free_stats;
903 903
904 hsag = kzalloc(sizeof(*hsag) + 904 hsag = kzalloc(sizeof(*hsag) +
905 // 1 extra for the lifespan config entry 905 // 1 extra for the lifespan config entry
906 sizeof(void *) * (stats->num_counters + 1), 906 sizeof(void *) * (stats->num_counters + 1),
907 GFP_KERNEL); 907 GFP_KERNEL);
908 if (!hsag) 908 if (!hsag)
909 return; 909 goto err_free_stats;
910 910
911 ret = device->get_hw_stats(device, stats, port_num, 911 ret = device->get_hw_stats(device, stats, port_num,
912 stats->num_counters); 912 stats->num_counters);
@@ -946,10 +946,11 @@ static void setup_hw_stats(struct ib_device *device, struct ib_port *port,
946 return; 946 return;
947 947
948err: 948err:
949 kfree(stats);
950 for (; i >= 0; i--) 949 for (; i >= 0; i--)
951 kfree(hsag->attrs[i]); 950 kfree(hsag->attrs[i]);
952 kfree(hsag); 951 kfree(hsag);
952err_free_stats:
953 kfree(stats);
953 return; 954 return;
954} 955}
955 956