From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS, T_DKIMWL_WL_HIGH,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C2A6C04A6B for ; Mon, 6 May 2019 14:55:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 32B692054F for ; Mon, 6 May 2019 14:55:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557154507; bh=fPgT4HY0bky+EBue+zskn1nEizjuV4KXjab0xYNNJzc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=V9HZR26Q1GeLZJf4Fo7fqG4SW1JfX02OIlIl7byh3Io02hvVxOsaZmZ/hew06Bazm VGd41GcKvWxAUtAe7ovAz2PyQCRZ9TYTHhXOGpHHTWLYoqh97k3aNS7ozRCEbL404r SJq2lK7FtrJecFYH3IllfF3utEt9i66QJJrSoOdI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728600AbfEFOqQ (ORCPT ); Mon, 6 May 2019 10:46:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:43894 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729089AbfEFOqP (ORCPT ); Mon, 6 May 2019 10:46:15 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4FB812053B; Mon, 6 May 2019 14:46:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153974; bh=fPgT4HY0bky+EBue+zskn1nEizjuV4KXjab0xYNNJzc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xh63Au69w5/YM53AmJo9wcwTSKEYrtQxVESUYFr80+PI983vi7GnpawSoaKipzqRD UjRYpLIqjRc2NSodY5RsQbz1uIbd8A9xWvkssja6r1yN0mg+4ZP6oSlDDCGZ9SfLFv cft4f9ojI5/r5FwBibzPLzOjIf2K6xvsipl0IQe0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Jurgens , Parav Pandit , Leon Romanovsky , Jason Gunthorpe Subject: [PATCH 4.14 66/75] IB/core: Fix potential memory leak while creating MAD agents Date: Mon, 6 May 2019 16:33:14 +0200 Message-Id: <20190506143059.235039238@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143053.287515952@linuxfoundation.org> References: <20190506143053.287515952@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Daniel Jurgens commit 6e88e672b69f0e627acdae74a527b730ea224b6b upstream. 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 Reviewed-by: Parav Pandit Reported-by: Parav Pandit Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/core/security.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/drivers/infiniband/core/security.c +++ b/drivers/infiniband/core/security.c @@ -715,16 +715,20 @@ int ib_mad_agent_security_setup(struct i agent->device->name, 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)