Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp772116ybg; Wed, 10 Jun 2020 13:19:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6BOCupDUqH0YUluMSwn5qev0pKYJUnUhepALDrA/0RO71Q5DaEk2lUX3SlSrGg9I7nZ1v X-Received: by 2002:a17:906:2b88:: with SMTP id m8mr5417927ejg.509.1591820343072; Wed, 10 Jun 2020 13:19:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591820343; cv=none; d=google.com; s=arc-20160816; b=FRBB9xjnM3UMTOMqlwDSnv0QorG+s1/rr+N9T11ca8Gu2nO6jllZjEgDnbwxdBKoKA FblQDSjBY6GTXmJ7BSYhJS56FqGepUZ6juTeZG5pXxF5SKgWKxomgNVRXDtGXnc2QDnr GMCToSwoNcqd7aufo9n+zv6JflqvlDRg5bLw+2e97+93icCBBPWZW8Iyul7eATYMnH/M pGgjBXzGPvWqwv2RuSFZuxtS6EW++EgpGVu2fK5v4frO9hEaiyTJHlrz0fIM2pVvWymT QWC+X/wfst/PgAFmqTOb5taeXx6JDYSpaGoh4P2WIxuUdHyjl6Rq8JZINVa9AcSdTJvR Jj2g== 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=u9aakgaaTX8ly9LiyA2N/fiL1n/d0S5lnU2rxVugXIg=; b=I+o3pvEE5FEO2kzKvwuJ8wgEHSF1DW75RXONOuPnXwRLvVwct40ntWYahWzVEZdzqQ dftUFCanJHgvgTW4YC96i8mQjth99YSUoXT4TO0lqMfYF4/scIJsbpgQErI3EHTBAMLB DssUBRq6GDvXhWn4fbxTAVT0+80zj9EzYLCYpo8rYIIVazfwXE+Udx6CbvlavLHBdfcW /lLJPrsDOUUqGNE4lVcl93KDCKirUkWtUP9N1H/E8N/8w6bG/2t+jV1ks2qL3V/7QqDd neAxcZ3JD4vfEHmdYdbeqhutaAcXvBfAWuoP0P50Cpab9iHAHVMt8fGFN6P7+U1/hetY DsCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KmnpfePX; 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 qw23si656603ejb.231.2020.06.10.13.18.40; Wed, 10 Jun 2020 13:19:03 -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=KmnpfePX; 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 S1728522AbgFJSKi (ORCPT + 99 others); Wed, 10 Jun 2020 14:10:38 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:40788 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728505AbgFJSKi (ORCPT ); Wed, 10 Jun 2020 14:10:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591812636; 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=u9aakgaaTX8ly9LiyA2N/fiL1n/d0S5lnU2rxVugXIg=; b=KmnpfePXqHTpLIv/wdPv9weYyZ4fl7bvjTeVVlIMN11n1QVfifb/Q2/BT+hMIas4XFEvhg KWBoRfbCAIzBNVS97aeSKk3l32tUTuCFOmyASIPnyMQGQLgR9qPUfVgJSogULNJKM3SQ1c eb8zKUIfF1he5Di4bT1QLDgUIMZ5Ohg= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-426-xEDH3VkzO4q9WvLZi17xdQ-1; Wed, 10 Jun 2020 14:10:32 -0400 X-MC-Unique: xEDH3VkzO4q9WvLZi17xdQ-1 Received: by mail-qk1-f197.google.com with SMTP id 186so2858546qkg.3 for ; Wed, 10 Jun 2020 11:10:32 -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=u9aakgaaTX8ly9LiyA2N/fiL1n/d0S5lnU2rxVugXIg=; b=Dv+YZYL1vaPn5jlToBXJ/y/4/C/V6jN5Mj2caK6S2es3eGi2blmn8KzmgmHDyg4SLy Vq8oJQMm/rDjzq9Xy51XFyyDXqLtQzcumjEw+al/lADKZzxdhuOOh39OjlILBDV3G4z5 MLT13KI20F9/7r9Huc/515JPaiu3S2ZT9Ir8MLGNXw5dNscVfHoc5Dz0xVQfs3oOy20n hS9GOtqdgDU38yqVn8XzPNyMIpTKuQluo60VRB4hZ9cr+7Q+lynqDQEJpxyre9Tx65Dg Pi13HZTIZJ88uuJ/PGBHUTzYRH3HR8P+9uhU7vUdOwt0Y80UIcyM611MzLsXeYr8vx6G 9xXw== X-Gm-Message-State: AOAM532F07rJCo8WOnOKZw+ahl66IVXirB0u6F2KdVrnvvJw6ALWj4DG kDSU2cjLtQGDHNaGOFr516ki0NQthoQHIBmKi7417Zb0vZr29q6pZcbG5WIAHWnrk4IiF0Uegl4 7ZgmnVNLV+MXQ4BNdROfyBYH+ X-Received: by 2002:a05:620a:753:: with SMTP id i19mr4454560qki.357.1591812632216; Wed, 10 Jun 2020 11:10:32 -0700 (PDT) X-Received: by 2002:a05:620a:753:: with SMTP id i19mr4454542qki.357.1591812632028; Wed, 10 Jun 2020 11:10:32 -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 w13sm339047qkb.91.2020.06.10.11.10.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 11:10:31 -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 1/1] selinux: fix double free Date: Wed, 10 Jun 2020 11:10:21 -0700 Message-Id: <20200610181021.19209-2-trix@redhat.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20200610181021.19209-1-trix@redhat.com> References: <20200610181021.19209-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..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(*values); + *len = 0; + *names = NULL; + *values = NULL; goto out; } -- 2.18.1