Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2451179pxj; Mon, 17 May 2021 01:38:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynyk4vEXA9I2n9P6Blm3F5HHAGjMME0S9QwCRmVGGJidCwmxW3yIM8i0EgVxAYYYSeY0Xh X-Received: by 2002:a17:906:a18e:: with SMTP id s14mr58317514ejy.311.1621240722769; Mon, 17 May 2021 01:38:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621240722; cv=none; d=google.com; s=arc-20160816; b=fUYNoP5SnapHOiO1KHbigRlbWsDsSnz2dUFezAFCyyXEzTFp6y1PaqVO3r5QE/Z8pe czBGT2VdM+CLQTHR1xznI+fuPQBm72kqy1VWh77zDL2aTv6TqVQUByP9+lWTWMbVcJFB mgLSw9wmU+qhWN9HOgWO5QVcsFOo0Xl3aQ85fXv8702KpBkjdTkhqDzfOq8jMLjN1e1M vG14VM2laQVHgYLomPk+dvHJ1CI6/T/gefvtdbCCm9sCh0Drge+YGtlP2jpqOivs+B0g wsiNhI3KiRAoAxzM3dJnbczHe8JoeMiODnuPPJ33CBPL0lq9tV4NGPb4cH/+bXStaWQF pzCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=H0rIkLZVSWvcw5d0SRX5kn9M8zHvErYPyZMfehLrUnc=; b=OKMlcmOBMz9JPNbX3cbvPXqp8/84IaG7oYKquQo5M7axqSZz3Blqqt0H7sMWhFy0rq ttl6KeJ5oRk+Qvb6vgkzP1DoAtFoM5wUb3z+yiCv9IT6GvK6v5RVSDIYPiugSzXglqvg fvch+jwLjXhBth8YoCNSMWSm+KNPEYgVzwslYweoDlHNikoqwYIC55MBqhI1N/nlzpDX gqjgTlw5bbD14moQUCN30UFFS6aNxZdKSz1YkiIs3B7K1MJcIN2JAzND184X+w+b6tfJ kzJB10YWo6Sw/4bfLiKJIbrPLMZ07j0k9SA4vdTrCVd0Z29DsJ0CJ96d3yNpYvRiev2X fSDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="hQJu/Q9D"; 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 m26si14801837edp.58.2021.05.17.01.38.20; Mon, 17 May 2021 01:38:42 -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="hQJu/Q9D"; 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 S235692AbhEQIfo (ORCPT + 99 others); Mon, 17 May 2021 04:35:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45452 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235650AbhEQIfn (ORCPT ); Mon, 17 May 2021 04:35:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621240467; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=H0rIkLZVSWvcw5d0SRX5kn9M8zHvErYPyZMfehLrUnc=; b=hQJu/Q9DiIwDZsPigFsECdGZgI7dhLjR8o5xX89/y1TC1IZINiym/UUegzE+cTRD3GG0ol l5keOYQNMBqPJiGpSoxICfmnsvkyfuOpV0pEuZoKIXMoAm0nou/uRfyLt8+UPCIgDvn8iH 5SvCP6MyCUSGpL35pJQ38LbggjfzmUQ= Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-213-BWotMYwWPnmUzhtgL3I4RQ-1; Mon, 17 May 2021 04:34:25 -0400 X-MC-Unique: BWotMYwWPnmUzhtgL3I4RQ-1 Received: by mail-yb1-f197.google.com with SMTP id d63-20020a254f420000b02904f91ef33453so8510875ybb.12 for ; Mon, 17 May 2021 01:34:25 -0700 (PDT) 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=H0rIkLZVSWvcw5d0SRX5kn9M8zHvErYPyZMfehLrUnc=; b=cHJeDY+AqRunsdi1JqmifxUsHeMvy587LCWAyTBs6N9Fhg9RbhqDExZ2kY7lYtFQHt JUfibirIdDZgUesgGJyBSAfZOly2ruN9xr+QVBLyDmEl3EwAFKH9bL9kWCOn2ep8dcG4 sOBxseMO9LQjGsgfIyuELrN6mUMreogyD/HtjSRSnL8UyuHQtMz8+ok+rl56/BX7apsf GLZZ6rCcEQcV1zS66+CnGnIgt29cStljpOQ8OWecB3xduGEoZ6B/K1lkdLp3aVoCZPVB lqO1mtwZ4OG/YI2zmxQ/BvnC06SuZhE2CqlO722SsNRZYxbO4PK6AYuCzlnLtyK3uBPl nB+A== X-Gm-Message-State: AOAM532NRN+zPIzvcIiOpFErQmeebPFAxsopjHyARsM9vsaMnlZntNq3 ChVEY1Pez47qrFYFOXhvtRtnv/QHRoG4DFSmuGZSgAw5P3FBz5PYBKv7QyqgKNPMxPzSunlJvsb sgEbaaTB6RGtlgUn3/aG9augO1WSZgO+FCI8hlMqR X-Received: by 2002:a25:7451:: with SMTP id p78mr10684347ybc.227.1621240465229; Mon, 17 May 2021 01:34:25 -0700 (PDT) X-Received: by 2002:a25:7451:: with SMTP id p78mr10684322ybc.227.1621240465001; Mon, 17 May 2021 01:34:25 -0700 (PDT) MIME-Version: 1.0 References: <20210507114048.138933-1-omosnace@redhat.com> <24a61ff1-e415-adf8-17e8-d212364d4b97@schaufler-ca.com> <94486043-322f-74bd-dc33-83e43b531068@schaufler-ca.com> In-Reply-To: <94486043-322f-74bd-dc33-83e43b531068@schaufler-ca.com> From: Ondrej Mosnacek Date: Mon, 17 May 2021 10:34:12 +0200 Message-ID: Subject: Re: [PATCH] lockdown,selinux: fix bogus SELinux lockdown permission checks To: Casey Schaufler Cc: Linux Security Module list , James Morris , Steven Rostedt , Ingo Molnar , Stephen Smalley , SElinux list , linuxppc-dev@lists.ozlabs.org, Linux FS Devel , bpf , network dev , Linux kernel mailing list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 15, 2021 at 2:57 AM Casey Schaufler wrote: > On 5/14/2021 8:12 AM, Ondrej Mosnacek wrote: > > On Wed, May 12, 2021 at 7:12 PM Casey Schaufler wrote: > >> On 5/12/2021 9:44 AM, Ondrej Mosnacek wrote: > >>> On Wed, May 12, 2021 at 6:18 PM Casey Schaufler wrote: > >>>> On 5/12/2021 6:21 AM, Ondrej Mosnacek wrote: > >>>>> On Sat, May 8, 2021 at 12:17 AM Casey Schaufler wrote: > >>>>>> On 5/7/2021 4:40 AM, Ondrej Mosnacek wrote: > >>>>>>> Commit 59438b46471a ("security,lockdown,selinux: implement SELinux > >>>>>>> lockdown") added an implementation of the locked_down LSM hook to > >>>>>>> SELinux, with the aim to restrict which domains are allowed to perform > >>>>>>> operations that would breach lockdown. > >>>>>>> > >>>>>>> However, in several places the security_locked_down() hook is called in > >>>>>>> situations where the current task isn't doing any action that would > >>>>>>> directly breach lockdown, leading to SELinux checks that are basically > >>>>>>> bogus. > >>>>>>> > >>>>>>> Since in most of these situations converting the callers such that > >>>>>>> security_locked_down() is called in a context where the current task > >>>>>>> would be meaningful for SELinux is impossible or very non-trivial (and > >>>>>>> could lead to TOCTOU issues for the classic Lockdown LSM > >>>>>>> implementation), fix this by adding a separate hook > >>>>>>> security_locked_down_globally() > >>>>>> This is a poor solution to the stated problem. Rather than adding > >>>>>> a new hook you should add the task as a parameter to the existing hook > >>>>>> and let the security modules do as they will based on its value. > >>>>>> If the caller does not have an appropriate task it should pass NULL. > >>>>>> The lockdown LSM can ignore the task value and SELinux can make its > >>>>>> own decision based on the task value passed. > >>>>> The problem with that approach is that all callers would then need to > >>>>> be updated and I intended to keep the patch small as I'd like it to go > >>>>> to stable kernels as well. > >>>>> > >>>>> But it does seem to be a better long-term solution - would it work for > >>>>> you (and whichever maintainer would be taking the patch(es)) if I just > >>>>> added another patch that refactors it to use the task parameter? > >>>> I can't figure out what you're suggesting. Are you saying that you > >>>> want to add a new hook *and* add the task parameter? > >>> No, just to keep this patch as-is (and let it go to stable in this > >>> form) and post another (non-stable) patch on top of it that undoes the > >>> new hook and re-implements the fix using your suggestion. (Yeah, it'll > >>> look weird, but I'm not sure how better to handle such situation - I'm > >>> open to doing it whatever different way the maintainers prefer.) > >> James gets to make the call on this one. If it was my call I would > >> tell you to make the task parameter change and accept the backport > >> pain. I think that as a security developer community we spend way too > >> much time and effort trying to avoid being noticed in source trees. > > Hm... actually, what about this attached patch? It switches to a > > single hook with a cred argument (I figured cred makes more sense than > > task_struct, since the rest of task_struct should be irrelevant for > > the LSM, anyway...) right from the start and keeps the original > > security_locked_down() function only as a simple wrapper around the > > main hook. > > > > At that point I think converting the other callers to call > > security_cred_locked_down() directly isn't really worth it, since the > > resulting calls would just be more verbose without much benefit. So > > I'm tempted to just leave the security_locked_down() helper as is, so > > that the more common pattern can be still achieved with a simpler > > call. > > > > What do you think? > > It's still a bit kludgy, but a big improvement over the previous version. > I wouldn't object to this approach. Ok, thanks. I'll post it as a v2 then. -- Ondrej Mosnacek Software Engineer, Linux Security - SELinux kernel Red Hat, Inc.