Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp177402pxa; Wed, 26 Aug 2020 07:49:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMOvf6jfJ77acz33ENi7sN5nxP1WR217dzBGC/r2UBzuW+6FQmbbFgKPw9T0cyvCKfuyD0 X-Received: by 2002:a17:907:20c8:: with SMTP id qq8mr16958468ejb.253.1598453357024; Wed, 26 Aug 2020 07:49:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598453357; cv=none; d=google.com; s=arc-20160816; b=xO8wkbH0rpR8+w0eGAXOXMegeC5aKNt2r6wW4ILyJJ0g0Shr1j1OnZwTUobbOHOTgl ygr7/huFWIYQzvOrmZT6HSUBazRTASE8Qo+FAzuRwEOgxq6ju8qz2mmSQLzlSRFTOpoq sHVb+7KM8EnIFdcL94bJmmbssWGZtaf3raEl4xM2VJClFye+rHJcjvCusrNCqvb1vYkV oaQrwftx5hNK2jr4jCyW9CpHPOodFcjbhQ+3mNjWTe7LAPhAYQPmS97eceV9VkgEUpve 2f3szTNSKrA3ODNJJVAUgEW/gNcGogaf56zo5y6g1vfQPVVt1PpyL1/jiQWagNhfjKe2 rBmg== 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=jpXoOzxjmaSPieMUrMwjgj+f7eMHv3D0MiHLZevapy8=; b=v7Ol6UAho8IFUfhTdL3p7S4fgigPoY2Kx16B+IImNktoNCAIJk11Ghm9xEL48QqMlD hnV+AjPBLPyARtI/9apAq0PQG434+ATnk36ofTCWQf2sGInQwg+09CDoqQtXIV7dIO8N wrQdNE2ATLrTqp9eRqIINbjuTnKFH2VVL/kDFt8Xu0d8D6qfslrK+V7wENJJxm1mw3ig C9JfZFaDfoedmp7Ja56IERjB4vT0mwFdu2ShuM109N6l+/BZDD0Lf5gQYH6gw1TvODDS xt2zafHTs8429ZzB43WwVlkU8Yb1v921ulKzZoWRaNagKMbLipcMnG1jgeYULtyRQb7d PLYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=uuviY+HH; 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 s25si1598992edr.590.2020.08.26.07.48.53; Wed, 26 Aug 2020 07:49:17 -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=uuviY+HH; 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 S1726977AbgHZOr6 (ORCPT + 99 others); Wed, 26 Aug 2020 10:47:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727008AbgHZOrz (ORCPT ); Wed, 26 Aug 2020 10:47:55 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77411C061756 for ; Wed, 26 Aug 2020 07:47:53 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id o18so3231437eje.7 for ; Wed, 26 Aug 2020 07:47:53 -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=jpXoOzxjmaSPieMUrMwjgj+f7eMHv3D0MiHLZevapy8=; b=uuviY+HHY4G/qSfupdmikJBac7QR65ENkowJ6J/jYfnCePd8Xn9EiwqHhGK6jIRITH a5Ep6mk1NvA/fuR+G8ichkTPQwvkzP/b3MyrRRTinYparaXT/281yKXIj/TpRYdqsI6I 5g6azBhlombBDx76l6r3mMxwJbwbzZ332F9aN5vanV+W1jG8CuvLqfa45p36iPiLfgcX aFEkVindyv2dVZDV1qIptDPZ9WkKPuSIrA6dN4bs21tIv/aKU9gbU+RKZxkgnY6iIs4S ++3D7x6o/4rTIV7zlf0n6Xr4eWd8x+fZliorBKrrERgW/wA9Mr4GSs4fq3+oqfodZeNI dGng== 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=jpXoOzxjmaSPieMUrMwjgj+f7eMHv3D0MiHLZevapy8=; b=a6cpsY2h/RJXh0yuraPVWYPYBv7lvVzUqwBOwWe+HHWi5DEqCtv9AK9QlMkcERGT05 4bSXOWFk/3UKC22gwvrRQMBBM74Kfs/aw7sNPx9n+VXQBE9yIZPKOprEUM8e0u0R4YzW 2NecLZtISF9Q/TrPKB0mSBTpn98yMXMuyfc1PCraZz3/pRi4kQBvPaIFLgHpA6l8/CQk kuK4hfFo1gTfqYVTbs1ZEOIR/0UzLgzGRgdCRMGK7krXPj6Svw71k2/JSVcr/XLS5/zy w6Oxdamkey3BaXyY15ZQsDSTTiC/6RSHyJ0nScrEW/L9c9cFq8tTewRnApO2qpx3Kv0L C2aQ== X-Gm-Message-State: AOAM530X0B5N0lIvk/wEa86j0UdRtaoZ3RsQ/CwVotqml9Q7yFsvjLXe +NLnRyJmX+H8ZnfrWTnA2CmdE+7OISQQg9XMfipP X-Received: by 2002:a17:906:f955:: with SMTP id ld21mr766045ejb.398.1598453272483; Wed, 26 Aug 2020 07:47:52 -0700 (PDT) MIME-Version: 1.0 References: <20200826113148.GA393664@mwanda> In-Reply-To: From: Paul Moore Date: Wed, 26 Aug 2020 10:47:41 -0400 Message-ID: Subject: Re: [PATCH] selinux: fix error handling bugs in security_load_policy() To: Stephen Smalley , Dan Carpenter Cc: Eric Paris , Ondrej Mosnacek , Jeff Vander Stoep , SElinux list , linux-kernel , kernel-janitors@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, Aug 26, 2020 at 8:49 AM Stephen Smalley wrote: > On Wed, Aug 26, 2020 at 7:32 AM Dan Carpenter wrote: > > > > There are a few bugs in the error handling for security_load_policy(). > > > > 1) If the newpolicy->sidtab allocation fails then it leads to a NULL > > dereference. Also the error code was not set to -ENOMEM on that > > path. > > 2) If policydb_read() failed then we call policydb_destroy() twice > > which meands we call kvfree(p->sym_val_to_name[i]) twice. > > 3) If policydb_load_isids() failed then we call sidtab_destroy() twice > > and that results in a double free in the sidtab_destroy_tree() > > function because entry.ptr_inner and entry.ptr_leaf are not set to > > NULL. > > > > One thing that makes this code nice to deal with is that none of the > > functions return partially allocated data. In other words, the > > policydb_read() either allocates everything successfully or it frees > > all the data it allocates. It never returns a mix of allocated and > > not allocated data. > > > > I re-wrote this to only free the successfully allocated data which > > avoids the double frees. I also re-ordered selinux_policy_free() so > > it's in the reverse order of the allocation function. > > > > Fixes: c7c556f1e81b ("selinux: refactor changing booleans") > > Signed-off-by: Dan Carpenter > > I guess this wasn't against current selinux next branch? > > patching file security/selinux/ss/services.c > Hunk #1 succeeded at 2145 (offset 18 lines). > Hunk #2 succeeded at 2263 (offset 39 lines). > Hunk #3 succeeded at 2303 with fuzz 1 (offset 47 lines). > Hunk #4 succeeded at 2323 (offset 42 lines). > > But otherwise it looked good to me. > > Acked-by: Stephen Smalley My guess is that Dan was using selinux/next, just not the latest. Anyway, the patch is now merged into selinux/next but I had to do some manual fixes so please double check that it looks okay to you. Thanks everyone. -- paul moore www.paul-moore.com