Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp772728ybg; Wed, 10 Jun 2020 13:20:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtUSm8SsER66NazRV36xc93VQu95uC1wjpYsZm+GrkSHftb+gckg7AZwhKTDsp8Ut/0odA X-Received: by 2002:a17:906:4c42:: with SMTP id d2mr5304508ejw.474.1591820407268; Wed, 10 Jun 2020 13:20:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591820407; cv=none; d=google.com; s=arc-20160816; b=QRIUe4wac6sFzu9voaGAInvCPXz5HM+3jZhjotexfKUjBx06KFfMu8Y5/SGrfcGQCR Dh8RQQnrg9mkJlVMsidPR+tTnhNwSW3KqJ08Qh0jhV0/sLyvsYTIeMcuZ87zTmhlm2X9 ewmblih7Yj4/2Gn4wM549Ix9DbbG28vwwLkXQpYug5iEvgAGGmSJkd3FmnYpd+kScUOV UL5xAjVLBq5TYNFyBTTpqtaxLW8D2mw+spiO7VCl/y5BnWmkLA278XPOHLyBOmyFL1cY yzTB+/Wo4xQjCceLaF8O9QDHJEUsylAGIcCAJWp/NE4cNH61AbKbCcVrGm+gz+FA06PW GWVQ== 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=zr/uGupFuGvMrFAVa6WiJ1h2V/NHtuxzOm0zL5k6jBM=; b=hLFlcg6w8LQTOkYfZmhjwuCTEKseEbFPgylejoqwQw4EFooyJbBm3RBqzEs989X/XX xpni/JHpX0nMTmdUIEF52VjZI/rd53w0UymD1c27JXga74nrdeZ9lLT3xbk98DOGGZTT TBLkpPlIytcfiMoE1hIhzF4osdPFTWAGt+UhGGKZFDRVoq62FjeZNM7qqTg2IO15QCnc AiXfWF+kXmiq5aeZtArZR3GCchTfaoUea59VAWnuhozew14rU3m7FQ9oQOYjyUhsOJ8G f/SlXIPgBcifcKO7gkss0JWJ9zafhNSMBOKFccJOJTy/FSPj6Okto8cRa91tX2MZHzoy 9Ilw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cTcb83D4; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m17si361397eds.189.2020.06.10.13.19.43; Wed, 10 Jun 2020 13:20:07 -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=@gmail.com header.s=20161025 header.b=cTcb83D4; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729849AbgFJTKa (ORCPT + 99 others); Wed, 10 Jun 2020 15:10:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726266AbgFJTK3 (ORCPT ); Wed, 10 Jun 2020 15:10:29 -0400 Received: from mail-oi1-x244.google.com (mail-oi1-x244.google.com [IPv6:2607:f8b0:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27B68C03E96B; Wed, 10 Jun 2020 12:10:29 -0700 (PDT) Received: by mail-oi1-x244.google.com with SMTP id i74so3144560oib.0; Wed, 10 Jun 2020 12:10:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zr/uGupFuGvMrFAVa6WiJ1h2V/NHtuxzOm0zL5k6jBM=; b=cTcb83D44ug2dUwS+XVrUU+yCJEYXxDYasAHrnWL8Gt4Yq7IrV+9K88RpWjjaVGUZ/ J0pOMhK5d7tCTV7s/x+nDwvGIM/v6RhHaY69Pjw15NIhMdify9/oqAEFWoBjrXEFhPEI lD1aIQ8rfaE734NB9PZplKUn6bCXuUMIeHnZbcM/i9WiQedaMbWe7D4DmksV9jQJhbYY bi4IA21klGK3dTq/pv/q2wiIdeySVlQi/iuzyaQUfX6uYizQ4iZ1rFBgWRpFGOQESFXZ cB6tfg3nywhQDFz2EKR8GaBzuFGmA6++rj+DFLTqri+waeBeMO+mPeiIctTeosNe0U68 6P/w== 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=zr/uGupFuGvMrFAVa6WiJ1h2V/NHtuxzOm0zL5k6jBM=; b=fInML7aBUfom3Xh7Mpo3GrrgTUrkuJ4+lDS8BIjcpjLrSDW9jbC66YG8NQegAPllxx YJ6oyF0c+tLSbY5QyFkIFgquCyCeKVPZMlLlBpXwUOvEG+ai8qjA2eLf2Ju7PV68NqMd 6j7QkHMhkZyprwnRqKfxsJnD8C84UsA4frGrooPbZVVNPBg6pwRvvZVxwOrV5HvXIUOq yQXvnbQ/HA3Ru3Gu+ABxi5XGGC+2MNfwFwTxvD8Zc2sK1aEmoI66ea7MI4qPYaTEIzvd YAlUKfn977M1RhygGjO00OE7xqEB7VdkvHR5QjsxP4ZTNpk+21xzTpM6zMQQbJ+KMX8L KmmA== X-Gm-Message-State: AOAM532d+tcwLjLoHvlWXajvTbEMo53p1h9hZWHjWYL0XjlHNGUc7ilG BZRXG9qWzj/QM/Ar+vq0hBmqRfW+0seFvGdhoFM= X-Received: by 2002:aca:a948:: with SMTP id s69mr3720382oie.140.1591816228579; Wed, 10 Jun 2020 12:10:28 -0700 (PDT) MIME-Version: 1.0 References: <20200610181021.19209-1-trix@redhat.com> <20200610181021.19209-2-trix@redhat.com> In-Reply-To: <20200610181021.19209-2-trix@redhat.com> From: Stephen Smalley Date: Wed, 10 Jun 2020 15:10:17 -0400 Message-ID: Subject: Re: [PATCH 1/1] selinux: fix double free To: trix@redhat.com Cc: Paul Moore , Eric Paris , Ondrej Mosnacek , Jeffrey Vander Stoep , rgb@redhat.com, SElinux list , linux-kernel 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 2:10 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(+) > > diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c > index 313919bd42f8..2dffae1feaff 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(*names)? > } > kfree(*values); > + *len = 0; > + *names = NULL; > + *values = NULL; > goto out; > } Wondering if the caller handling ought to be changed too even though this should avoid the problem.