Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2566590yba; Mon, 6 May 2019 08:06:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqwNBuTCOF9BK/GpftMyVNS0ymIccOIvIlnH0KDpubfTNuXDRyvRPlWrEv9ZjQNR5bRESuTX X-Received: by 2002:a17:902:201:: with SMTP id 1mr33107479plc.89.1557155182043; Mon, 06 May 2019 08:06:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557155182; cv=none; d=google.com; s=arc-20160816; b=VM+19rTIpK5UuGsZDCjtnNHMj5j9hPuZiR8bmW49q0mota6qRh1ZuUicnQUC7uPUhh qoaDtUmNRa9+UiSw2NpkwL18LjRNVkf4pPCHkMriIOMQhLTLgwbODPpwJt6vSBwYtJcN wCFyYKgZzpXknelvewRn3YidPIDO7vC+RmAq/Sdh+hpwSl4PgVdeT0dH5dyF1UMAL/Nf c1ykF62RdhAYDQZA3uI5W0Ud1sb780vuy+dKS7LTy7my9TcHi/6YPf9TsZNA+EuTP3i7 XNELP+ODoDXgZqPkF+9IBkwgjjiaylTUl1yOR896mv/wWyC30ZzNUf6zoeQ+mAkhGh8H RqUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NfpBtx05dhd4D8c3CTUY+tOA7OqJEx1MxrdS6EgQNIY=; b=PLvcXIWuWGLkZYXokWKsydnLZ5MIw/GQAeJL9HItoIA/KJ+ToAryt7Rxmnj7Y2HHtj DNrAAbaM0I4EytvSd9GFcuUYbtdzs/DeeXyTjeF0T7k+ESINU6CBkl8vvVwD9uYPkfWi rU52WpqQlWBUNYN1MH2ZVXJ/tNY285E/eyy3fI9niwIa6ZAb5XLJUGQ4J8WTwU/bl+Xh 4uL4eKWcNErKzim6N2orqPALOcdG2YtEm0TDjOZoUL/QmxmfbRR8B7IjogoE1lbc3nBa E/0jO07qhyfc9j2+Ui+zbo1R1U+pI0+7x69CKP8PQcUPixWbmm8p9e5RtLfPhPRbbVDz +h4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ix10W4p6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h29si15307316pfd.180.2019.05.06.08.05.57; Mon, 06 May 2019 08:06:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ix10W4p6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727736AbfEFOjF (ORCPT + 99 others); Mon, 6 May 2019 10:39:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:60390 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727722AbfEFOjD (ORCPT ); Mon, 6 May 2019 10:39:03 -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 78A4D21479; Mon, 6 May 2019 14:39:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557153543; bh=YWmIRXnPDSIST+5S/E+Jo9v990ZF95a3j597D5119sE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ix10W4p6q1WIb5Zo+Fn34wIF+YhjyyWfF+f9GUrKDcujBxmtEYEpAkwk0NHLtXLax zbx8ze43HXQFPBgYKoT91ffJgd7/4ARdiZ/zgAzY6sfuDIOmsMRcS20eu7ixH5Z49G vsS2qrHVfN4ihsqA2cvVF8Oe3t8kS/v70ncijDxY= 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 5.0 107/122] IB/core: Fix potential memory leak while creating MAD agents Date: Mon, 6 May 2019 16:32:45 +0200 Message-Id: <20190506143104.203535744@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143054.670334917@linuxfoundation.org> References: <20190506143054.670334917@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -710,16 +710,20 @@ int ib_mad_agent_security_setup(struct i 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)