Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp957884ybg; Wed, 10 Jun 2020 19:15:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHkOtF5y7wsvZbEKIH5zjP5vMFHZYx/oq7FSwawtwkbX/ennAnrHZsNFKveMGnzjJC6IqY X-Received: by 2002:a50:f694:: with SMTP id d20mr4779311edn.171.1591841753701; Wed, 10 Jun 2020 19:15:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591841753; cv=none; d=google.com; s=arc-20160816; b=ZGzGrM0UfzQJFzh5yJMZI2Mt7+pXvwn2LiOqbf/x6qXk3jpoXs7sM8aWQfveEnn1ZU kVxPFOpT+DvXRdmvEMYgkFxLJjcjQvzqJ7OJXwdLfWs9Ml8mnRXevrPIuLSg7aw9PB1d tXu8/2RECB58ITdltekjvAFhyBHAxPzJCT/wJCv3W9Ws6V14IfDnmmECwMZ4FoAfwS/N bqL1VyfNxNrIJwx59E4Rui96vvIK/+PzHpozWOqLFJq3ycZLIPd8HWwtAemkJHPPKW3E vxRXpdp68+OECnTBmU/fYpuDueroYtwiJaJ5MzHh3ccPq/Ls7cfucDcwjTp4gAjaorsP vc8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=wSclIs7n5vpOSvxh2OrnHeX+5b5kOfOtKGtkOgLl0/Y=; b=rD3iMYZmEoFDVxC/iY/7GrkI5cVG8lwdg6w0L58rPnZAdo7USfo764uzFUqHcnOckT FQrBKAf4XKyxeD+pxmhZv7XABcLCrJAin1fYzb3Nxfuh9Whos1bZ0Vniag5wymN0Ns3N rpM6giHuEvzHqHb8VuKuhQ893FaBWXgAh1DBwwR4OZjYeuMBHk+6c1vw/+RFIi9jxmKx 19Kfoj5TJTnJf0VfTRnGjyQHtK9YuIVSwVhRFEtnEDqg8ui5VRvl7LpCvYJQyxu7k9q9 Z/2fKbwBDkRKoE38jv47D4JjKJ+c0lX9oAUpwiQMVvVGhsASG26FK5TUb75t9xdWH637 eg9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=v8+6EYja; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n7si748807edt.65.2020.06.10.19.15.31; Wed, 10 Jun 2020 19:15:53 -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=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=v8+6EYja; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726387AbgFKCN2 (ORCPT + 99 others); Wed, 10 Jun 2020 22:13:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726163AbgFKCN2 (ORCPT ); Wed, 10 Jun 2020 22:13:28 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE938C08C5C1 for ; Wed, 10 Jun 2020 19:13:27 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id x1so4789845ejd.8 for ; Wed, 10 Jun 2020 19:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wSclIs7n5vpOSvxh2OrnHeX+5b5kOfOtKGtkOgLl0/Y=; b=v8+6EYjaTY6Fw2wnUUu6UJNua3V+Lp53KEHLNac2TEyYj9A2BadRkPLnSl/9YGGSyY T+OtnVMqO3xg/6L/4Nz08Mjb8nZo6NBSLdJSDqdfsJfSBLSCJh8KebIiyYCwV/s5cM9p N4Xs60MSyKAQ/KYjoC7hCG5yphEFesouJle1fShaDIcorlZn0iBB3bbrrytdHDbAELFC UYcuflCA6Bvrd9rGKshvhPFITNVjLQFiijsQMxQ7HyFPN9KDpI8QFlufe6imer80UQPr 4owye83ciH2aTw1fRvOmHgKrDhXFOgRLnp8gb82hFc5C85ZqJeNOSAiMFX+2AEbsAjdn lRKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wSclIs7n5vpOSvxh2OrnHeX+5b5kOfOtKGtkOgLl0/Y=; b=WHt5aucTT0/ChXwBJ9j5jdo+mWTxXHI64u+k79mvLg4rldAphk+PwolFhERt4VPh2X IcYs/SyyYeWMDQjhlQSypV94zxEx9TQ77VHQKjkF0S/iZ4whFDKU7903nOB9/YKDPFv6 /91iXtsCPQDYI2fC9CweuCkq4M5ZKE/WJxPrQNUl0LaCyl3fTjp/ZgwxVp3bqBV4FuTo wMytk2jQKoQuKQiNuQF0H2p7rhb9kUOsYbAhzLN8sq29a51G8UgsYzJuk5h+qEzHTpjz Ydph8vkofHZLgcumBa/Ot4gSkeQZGrLcCjq/1vjC8w99Xqir6HpsFb1xZXTUvGzswYpb B/1g== X-Gm-Message-State: AOAM533Cl0Zvkl0prUA4p9Bav6nDOe8YaMxBTmGIySzmgLpC8FhJkShm UPG3LqbdvjXiCTH5aCPTZ9RYuDhPJDYRzRZv5Rq/ X-Received: by 2002:a17:906:19d3:: with SMTP id h19mr6064005ejd.106.1591841606286; Wed, 10 Jun 2020 19:13:26 -0700 (PDT) MIME-Version: 1.0 References: <20200610215713.5319-1-trix@redhat.com> <20200610215713.5319-2-trix@redhat.com> In-Reply-To: <20200610215713.5319-2-trix@redhat.com> From: Paul Moore Date: Wed, 10 Jun 2020 22:13:15 -0400 Message-ID: Subject: Re: [PATCH v2 1/1] selinux: fix double free To: trix@redhat.com Cc: Stephen Smalley , Eric Paris , Ondrej Mosnacek , jeffv@google.com, rgb@redhat.com, selinux@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 10, 2020 at 5:57 PM wrote: > 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(+) Thanks Tom for the patch and Stephen for the review. I've marked this for stable and merged it into selinux/stable-5.8. Considering we are just a few days away from the close of the merge window and -rc1, I'll probably hold off until next to send this up to Linus. > 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 -- paul moore www.paul-moore.com