Skip to content

Commit 6e88e67

Browse files
Daniel Jurgensjgunthorpe
authored andcommitted
IB/core: Fix potential memory leak while creating MAD agents
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: 47a2b33 ("IB/core: Enforce security on management datagrams") Signed-off-by: Daniel Jurgens <[email protected]> Reviewed-by: Parav Pandit <[email protected]> Reported-by: Parav Pandit <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent d60667f commit 6e88e67

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/infiniband/core/security.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,16 +710,20 @@ int ib_mad_agent_security_setup(struct ib_mad_agent *agent,
710710
dev_name(&agent->device->dev),
711711
agent->port_num);
712712
if (ret)
713-
return ret;
713+
goto free_security;
714714

715715
agent->lsm_nb.notifier_call = ib_mad_agent_security_change;
716716
ret = register_lsm_notifier(&agent->lsm_nb);
717717
if (ret)
718-
return ret;
718+
goto free_security;
719719

720720
agent->smp_allowed = true;
721721
agent->lsm_nb_reg = true;
722722
return 0;
723+
724+
free_security:
725+
security_ib_free_security(agent->security);
726+
return ret;
723727
}
724728

725729
void ib_mad_agent_security_cleanup(struct ib_mad_agent *agent)

0 commit comments

Comments
 (0)