]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
IB/core: Fix potential memory leak while creating MAD agents
authorDaniel Jurgens <danielj@mellanox.com>
Sat, 2 Feb 2019 09:09:43 +0000 (11:09 +0200)
committerJason Gunthorpe <jgg@mellanox.com>
Fri, 8 Feb 2019 23:24:44 +0000 (16:24 -0700)
If the MAD agents isn't allowed to manage the subnet, or fails to register
for the LSM notifier, the security context is leaked. Free the context in
these cases.

Fixes: 47a2b338fe63 ("IB/core: Enforce security on management datagrams")
Signed-off-by: Daniel Jurgens <danielj@mellanox.com>
Reviewed-by: Parav Pandit <parav@mellanox.com>
Reported-by: Parav Pandit <parav@mellanox.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
drivers/infiniband/core/security.c

index 402449d4a8887b069412e343f2b168a9bfe0df08..7662e934723807853249a389dfdc0ec2b9247990 100644 (file)
@@ -710,16 +710,20 @@ int ib_mad_agent_security_setup(struct ib_mad_agent *agent,
                                                dev_name(&agent->device->dev),
                                                agent->port_num);
        if (ret)
-               return ret;
+               goto free_security;
 
        agent->lsm_nb.notifier_call = ib_mad_agent_security_change;
        ret = register_lsm_notifier(&agent->lsm_nb);
        if (ret)
-               return ret;
+               goto free_security;
 
        agent->smp_allowed = true;
        agent->lsm_nb_reg = true;
        return 0;
+
+free_security:
+       security_ib_free_security(agent->security);
+       return ret;
 }
 
 void ib_mad_agent_security_cleanup(struct ib_mad_agent *agent)