From patchwork Tue Jun 23 19:58:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 223262 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=ham 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 E2D7DC433E0 for ; Tue, 23 Jun 2020 21:10:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B5D2720706 for ; Tue, 23 Jun 2020 21:10:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592946628; bh=OvdgE5Y5rBORuUbfMDJbswl3DeGzsCcxccz0W59OSik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=NcAJlTr6FjYMOTScHXTsiVvG6hWE3Q6ebCpUtSOoTyl+7d/phmdunlHDw7xR5XPj2 K30V/6mziYZAWr+BTfHwBiEFlo+fzQR7LNEla6SlIJFIY2URN/NMTSn4nh18IWRVcj BDXUp97gRatufxRwZCTxTUY9l88cgmTiMApKiiP4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390548AbgFWVK1 (ORCPT ); Tue, 23 Jun 2020 17:10:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:54388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389673AbgFWUdL (ORCPT ); Tue, 23 Jun 2020 16:33:11 -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 802472064B; Tue, 23 Jun 2020 20:33:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592944392; bh=OvdgE5Y5rBORuUbfMDJbswl3DeGzsCcxccz0W59OSik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uB9o5hEpyAYdbcMW1rkXQokfbFduQ6I0WVksS9WrzFZX8Lmhq3gVU8N/JCHmW/KfZ NTBMjXCl8vk2TfAxfLYK4bimR3hU3Y8SScmnt6f14Htcd4MXx27XfhO54m5HE082EX tfKImTej0VBBixYXNtwC2VYpJAFzWCAql7z5/jHw= 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.4 286/314] selinux: fix double free Date: Tue, 23 Jun 2020 21:58:01 +0200 Message-Id: <20200623195352.627009011@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623195338.770401005@linuxfoundation.org> References: <20200623195338.770401005@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 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 @@ -2844,8 +2844,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; }