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=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,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 67C84C433E1 for ; Tue, 23 Jun 2020 21:25:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3DA0D20738 for ; Tue, 23 Jun 2020 21:25:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592947538; bh=pcVWBQgxGpe/YfxjYihvBQJmOnuIdosCzeBy3mZT0lY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=EPece7rtyBfRBDY1XzmrsE0tBVTaqKWay6AXkUUoD+n6ED4NpFyEK2XPXqpT/PIb0 jApx3CKX7ToIEeVIevmFv+sBIM3QHkKQOM7Ddpa891O0YyqBSx/wj/RLhZ2SsQTHCq Q4x/oY0uS65Hnwdi7yo0AeiA6XANAgBJua2wqcIU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389710AbgFWUSq (ORCPT ); Tue, 23 Jun 2020 16:18:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:35796 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388831AbgFWUSq (ORCPT ); Tue, 23 Jun 2020 16:18:46 -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 A494720E65; Tue, 23 Jun 2020 20:18:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592943526; bh=pcVWBQgxGpe/YfxjYihvBQJmOnuIdosCzeBy3mZT0lY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1oiIhJ/VAmbihqFxR/zGpvPtJG6kJJQ27zBZe2i1zGl8fRZ5Tj+UqWnzZXb99ZONo qq/9qYRPrdRwlhoh/owzZ86uCBfsMK1iy6bCyzhN3O47uxT51ZYn5wx6CLr/3nuxSn XmHVX2/O69ymuNHw8XZML5AXUa8UOypXPAfyob88= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tom Rix , Stephen Smalley , Paul Moore Subject: [PATCH 5.7 426/477] selinux: fix double free Date: Tue, 23 Jun 2020 21:57:03 +0200 Message-Id: <20200623195427.667004235@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623195407.572062007@linuxfoundation.org> References: <20200623195407.572062007@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: Tom Rix commit 65de50969a77509452ae590e9449b70a22b923bb upstream. Clang's static analysis tool reports these double free memory errors. security/selinux/ss/services.c:2987:4: warning: Attempt to free released memory [unix.Malloc] kfree(bnames[i]); ^~~~~~~~~~~~~~~~ security/selinux/ss/services.c:2990:2: warning: Attempt to free released memory [unix.Malloc] kfree(bvalues); ^~~~~~~~~~~~~~ So improve the security_get_bools error handling by freeing these variables and setting their return pointers to NULL and the return len to 0 Cc: stable@vger.kernel.org Signed-off-by: Tom Rix Acked-by: Stephen Smalley Signed-off-by: Paul Moore Signed-off-by: Greg Kroah-Hartman --- security/selinux/ss/services.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -2923,8 +2923,12 @@ err: if (*names) { for (i = 0; i < *len; i++) kfree((*names)[i]); + kfree(*names); } kfree(*values); + *len = 0; + *names = NULL; + *values = NULL; goto out; }