Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp825939ybg; Wed, 10 Jun 2020 15:01:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxmfuUVVSnMTZZOxHxTvNJX/vsc4oW5q/Ua78oZ2eLghJIiL+glvcKLAVuX72eDfQybOYUO X-Received: by 2002:aa7:cc19:: with SMTP id q25mr4250701edt.26.1591826512909; Wed, 10 Jun 2020 15:01:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591826512; cv=none; d=google.com; s=arc-20160816; b=MVlHV1C17aNpD3d+MAKSMKla46jmeR0EsW1KiXCyFBl1KVC/LKj/2EDhpejr/5oa6b fe2pfc7n2JPKhdbx3k1AbrN4nOP7WxYZ9KB7vLapKTaiGHKWcUKzk2IaX2AuGFvOagZj /2L158GM60Mywl5kNFddeYWBuDqt3/Cw61lmcJ06MXvfePScgn3djScPAswVIxXBwvTB w5+zcnijheQjpJLuKYtwqkznPUQgGbhkQT6TtIQhDMHH+1/28zH1i+1TYDn20UeRvyei PRuc3iSsFl3i6Xir+dTJbaMJRQbHbON7750BpN61TD6fP5plV3V4fZzIpKmCN4rJJ5Od LplA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=EmDVUV812Um/BnCfmKxviR5G7cIbPJybAe69FI9PP8c=; b=alybVi2vtGuQf+uXba8sdKcI79iXGAvrhgYhKZya0zihSjqqf71djpU4lGjbAqA7K1 9F2x9H3E+nocg/SUmx/sSlUPhDR9M4qfsPj6Ll+AmOSgces2PhBJ/A9jtcO5mSyCaj02 SITgdsT0o7923sPAwaijHHtBvsHnFVJoMgV47zLOtlqxCFAXaERgbAZKxye6AXaS96s7 v0B1hbZ2G8wsKWdKabi/qEJFL4RQBR/yZ1emjSjvqWElgNbUe4dtlR5ILZbY3KZB9M4C 03DDcO0ICI3qZvslLpHuSN2tRLFPif1JaKYd0zK48aFPB7vP+hKNfeR46kgYINH5vwRO 7s1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="P/Mp0GsJ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r12si452581edc.599.2020.06.10.15.01.30; Wed, 10 Jun 2020 15:01:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="P/Mp0GsJ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726552AbgFJV53 (ORCPT + 99 others); Wed, 10 Jun 2020 17:57:29 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:39624 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726531AbgFJV52 (ORCPT ); Wed, 10 Jun 2020 17:57:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591826245; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=EmDVUV812Um/BnCfmKxviR5G7cIbPJybAe69FI9PP8c=; b=P/Mp0GsJU6x7noigR7GhbVYS8xUVaoO+PxgS/0mUIw20HTlwC5RQwGizqrNR7RV+kXbWS9 TOpLEQoUjWf2vfNpr27XiAt4563SNtcBBim8dFGETZpFO7uf95ZI0Izd6V/tQEh3aZP1dk c7xeXrJupGr2xoLD2Gc11bwN5ZL1x3s= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-155-3sdLEYJsMcaUCq403d_LRg-1; Wed, 10 Jun 2020 17:57:24 -0400 X-MC-Unique: 3sdLEYJsMcaUCq403d_LRg-1 Received: by mail-qt1-f197.google.com with SMTP id l1so3122953qtv.13 for ; Wed, 10 Jun 2020 14:57:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EmDVUV812Um/BnCfmKxviR5G7cIbPJybAe69FI9PP8c=; b=I5wGumA+Q3tofvK3z+5TBZzLQXHNYnMHU10nSdGQOfuZx8asF2SVLcacNIs8sjekuw 3HOrs0EWj81ho4q0yiggvWSiEkr2czYUfvM3p8ookzststw+ybWEfL+OPli1ULZXRYMO 12wKNYz9zJog7jns1+U4p6pBcxgEcKRadrRAiN+Xgr/dPoFusk5z+XyzPElSEPI680IQ nkCwMsnHUNYubhedbmfZzy3duTgCqAnucrgOTp6Y0CWJfxewUEin1CvX+4BCn9QHVOC9 uYtPaFumaJbGkrBqpz2IHLKFLpNx8I7AZo2Tm3s5erYUJWseoWfEPOeME7MWASAz5mQl noEQ== X-Gm-Message-State: AOAM532+xuLtwSlOVPxzGiQyeQIgm9WH5SOrlaIhKEYpx/RmcHN/KuLb ileORbAE/y6cwPYn25scypYQqlJOMANtkdcOhevezu4ztIB9OVLPX0a8i8akhJ+8DG858FyTlC4 ielJHWWhQdqvfrQb7yjm1uoMh X-Received: by 2002:a37:7c6:: with SMTP id 189mr5121395qkh.24.1591826244090; Wed, 10 Jun 2020 14:57:24 -0700 (PDT) X-Received: by 2002:a37:7c6:: with SMTP id 189mr5121378qkh.24.1591826243867; Wed, 10 Jun 2020 14:57:23 -0700 (PDT) Received: from trix.remote.csb (075-142-250-213.res.spectrum.com. [75.142.250.213]) by smtp.gmail.com with ESMTPSA id t13sm934883qtc.77.2020.06.10.14.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 14:57:23 -0700 (PDT) From: trix@redhat.com To: paul@paul-moore.com, stephen.smalley.work@gmail.com, eparis@parisplace.org, omosnace@redhat.com, jeffv@google.com, rgb@redhat.com Cc: selinux@vger.kernel.org, linux-kernel@vger.kernel.org, Tom Rix Subject: [PATCH v2 1/1] selinux: fix double free Date: Wed, 10 Jun 2020 14:57:13 -0700 Message-Id: <20200610215713.5319-2-trix@redhat.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20200610215713.5319-1-trix@redhat.com> References: <20200610215713.5319-1-trix@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tom Rix 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 Signed-off-by: Tom Rix --- security/selinux/ss/services.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c index 313919bd42f8..ef0afd878bfc 100644 --- a/security/selinux/ss/services.c +++ b/security/selinux/ss/services.c @@ -2888,8 +2888,12 @@ int security_get_bools(struct selinux_state *state, if (*names) { for (i = 0; i < *len; i++) kfree((*names)[i]); + kfree(*names); } kfree(*values); + *len = 0; + *names = NULL; + *values = NULL; goto out; } -- 2.18.1