Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp862189pxb; Thu, 23 Sep 2021 12:10:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrC5tAypddOMMajYBCE1C62JgxE1GbqIeRrb3QJ2ZmDeKvmDRxI6YqPkjfhV0Dw/vaI8Hi X-Received: by 2002:a50:ee82:: with SMTP id f2mr424887edr.15.1632424231946; Thu, 23 Sep 2021 12:10:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632424231; cv=none; d=google.com; s=arc-20160816; b=CiY6Aind8wZ51hJ5novuDfqgIMhiOalvDzCyN5wpZUn24W/AN//zKsKYSdNIhAsjrp 2P4fu8MzIOw7gTnA1ND487zGfNrvlscY6iGystMyXOguXbWCKuM0RefZ/6EQ3EQLOIem P0/x/rTUsQXsG2YcnPX5g/BWy9Huccsvr/gxp7pG2VINb6VPRvEeldQwqFJWyxh87KlL uadUCr30Cj7ZQUpWgkHFkW6Uv3z37qW/Fim8Feqeznm9gv5tV+HNnvMvZvvumoswT/zS UE7+qQGm0wu7CONYf+UNUUr5WEM2thlUJIdqtETbCeF1AnmYof8WA0LcTyfVBh/eOzPk 463g== 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=wPA6Pkqk/8ab9RW5HZw193jEL/3tz5PDXJBPjTVJtdU=; b=L/HONMhizESnh1S0SkUxtydJ40Lm9oX11zcvWfV2tpI/3RedhkqVOebwrtT56oTHre 0vRICuAgk6omluZSGHSn6Sevfz4WIxs+SDGZTVl9nktMLhYytdhSMUKrxEpGPEny+08z qOjBR4xcxNrmcnAq2jtptgFxqdPVYv85OGqTimX3hAgS/AcPAj97mbJ59JKxL015V5IH Y8CD7LCiHjOsY3QT+yaxj+wPabX3vx9rth6zz4d0EV181QeU1hS3kU0gy6AculPsA7X9 zwNcEcLCWf74m6fkT27xhbVzrsNphAUYptzUeibey/GyDQ7Hv6bsMe3XNuTEhxWuqIiu kEQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20210112.gappssmtp.com header.s=20210112 header.b=t1rPCUco; 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 v6si6973931ejh.227.2021.09.23.12.09.54; Thu, 23 Sep 2021 12:10:31 -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.20210112.gappssmtp.com header.s=20210112 header.b=t1rPCUco; 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 S242840AbhIWTJb (ORCPT + 99 others); Thu, 23 Sep 2021 15:09:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242837AbhIWTJ0 (ORCPT ); Thu, 23 Sep 2021 15:09:26 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D5EAC061762 for ; Thu, 23 Sep 2021 12:07:54 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id eg28so26902361edb.1 for ; Thu, 23 Sep 2021 12:07:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wPA6Pkqk/8ab9RW5HZw193jEL/3tz5PDXJBPjTVJtdU=; b=t1rPCUcoa8HEEbAcar5GeFzOJfqI7UfROKcFgIGMv00KZqB4bGNj1yz/Io6IQtZ9+Z NusuDSgjdkYMBVPbv2Vf3ap3Dbmry0u8fptJLN2cjl3LD0YJiwSIuBvYwnbH0rpaioQF s88qN4rAhn2A6bjocX70mp+3vXylM59wSuZYYWLOfUKeLAaAxF3Zwk8fzDO06/nV0A9+ HsVgP4O9uIzFx80rDBeCkIGHcNp1EPBKoNORwSEOCOnT2lOJA5lLnJNU7gfbyJ+41Gti zD8XRqIUaiJOWJBUAoo8PMoRjsXYVqkGOPgNVTuehmVHE3E5VSK+CrreHU4ugQScViDj 7cjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wPA6Pkqk/8ab9RW5HZw193jEL/3tz5PDXJBPjTVJtdU=; b=f7gM4ER7FR4z3NRmtBkGAgANZlpdCq1UVPdQ9tZtUloNFDHYlTJSN6Smnwfp1pFDqa BJckp5L9+GW2K0V/EUeHIuWAu259VIXjuAshlsMKLFseBEVSpWyBoAEMN1fd4Mp98xeG kp161fjn0+xyPzoVsv5DwMPX7WOaYDInyp0NeIJ19OY9jmZYybYE2cZ3kD0PGU9PqDd8 TkWgaXndgqW72m/TwfdvtxRGYRa+2T29hQmjX05uce4aPbaOK3SrCJEjX2p3yseXCEso Pbdypb4iNDlZLtgKqPayNhkuC5DuOyqWw4HlKk9+DVwk0WF+fWx+u8aclfFpBk6dAlMI IjVg== X-Gm-Message-State: AOAM533lzm1OHu3bi222/PnUZ8+sesa9xwSMs7NrNBJXW5Lp1T5TqKmQ VJZdg2nPRWYSIRDf/tJrk5TJPVWB1jNif1iO3hBz X-Received: by 2002:a50:cf48:: with SMTP id d8mr377146edk.293.1632424072663; Thu, 23 Sep 2021 12:07:52 -0700 (PDT) MIME-Version: 1.0 References: <20210913140229.24797-1-omosnace@redhat.com> In-Reply-To: From: Paul Moore Date: Thu, 23 Sep 2021 15:07:41 -0400 Message-ID: Subject: Re: [PATCH v4] lockdown,selinux: fix wrong subject in some SELinux lockdown checks To: Ondrej Mosnacek Cc: linux-security-module@vger.kernel.org, James Morris , Steven Rostedt , Ingo Molnar , Steffen Klassert , Herbert Xu , "David S . Miller" , Stephen Smalley , selinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-acpi@vger.kernel.org, linux-cxl@vger.kernel.org, linux-efi@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-pci@vger.kernel.org, linux-pm@vger.kernel.org, linux-serial@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Casey Schaufler , Dan Williams Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 15, 2021 at 10:59 PM Paul Moore wrote: > > On Mon, Sep 13, 2021 at 5:05 PM Paul Moore wrote: > > > > On Mon, Sep 13, 2021 at 10:02 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. > > > > > > To fix this, add an explicit struct cred pointer argument to > > > security_lockdown() and define NULL as a special value to pass instead > > > of current_cred() in such situations. LSMs that take the subject > > > credentials into account can then fall back to some default or ignore > > > such calls altogether. In the SELinux lockdown hook implementation, use > > > SECINITSID_KERNEL in case the cred argument is NULL. > > > > > > Most of the callers are updated to pass current_cred() as the cred > > > pointer, thus maintaining the same behavior. The following callers are > > > modified to pass NULL as the cred pointer instead: > > > 1. arch/powerpc/xmon/xmon.c > > > Seems to be some interactive debugging facility. It appears that > > > the lockdown hook is called from interrupt context here, so it > > > should be more appropriate to request a global lockdown decision. > > > 2. fs/tracefs/inode.c:tracefs_create_file() > > > Here the call is used to prevent creating new tracefs entries when > > > the kernel is locked down. Assumes that locking down is one-way - > > > i.e. if the hook returns non-zero once, it will never return zero > > > again, thus no point in creating these files. Also, the hook is > > > often called by a module's init function when it is loaded by > > > userspace, where it doesn't make much sense to do a check against > > > the current task's creds, since the task itself doesn't actually > > > use the tracing functionality (i.e. doesn't breach lockdown), just > > > indirectly makes some new tracepoints available to whoever is > > > authorized to use them. > > > 3. net/xfrm/xfrm_user.c:copy_to_user_*() > > > Here a cryptographic secret is redacted based on the value returned > > > from the hook. There are two possible actions that may lead here: > > > a) A netlink message XFRM_MSG_GETSA with NLM_F_DUMP set - here the > > > task context is relevant, since the dumped data is sent back to > > > the current task. > > > b) When adding/deleting/updating an SA via XFRM_MSG_xxxSA, the > > > dumped SA is broadcasted to tasks subscribed to XFRM events - > > > here the current task context is not relevant as it doesn't > > > represent the tasks that could potentially see the secret. > > > It doesn't seem worth it to try to keep using the current task's > > > context in the a) case, since the eventual data leak can be > > > circumvented anyway via b), plus there is no way for the task to > > > indicate that it doesn't care about the actual key value, so the > > > check could generate a lot of "false alert" denials with SELinux. > > > Thus, let's pass NULL instead of current_cred() here faute de > > > mieux. > > > > > > Improvements-suggested-by: Casey Schaufler > > > Improvements-suggested-by: Paul Moore > > > Fixes: 59438b46471a ("security,lockdown,selinux: implement SELinux lockdown") > > > Acked-by: Dan Williams [cxl] > > > Acked-by: Steffen Klassert [xfrm] > > > Signed-off-by: Ondrej Mosnacek > > > --- > > > > > > v4: > > > - rebase on top of TODO > > > - fix rebase conflicts: > > > * drivers/cxl/pci.c > > > - trivial: the lockdown reason was corrected in mainline > > > * kernel/bpf/helpers.c, kernel/trace/bpf_trace.c > > > - trivial: LOCKDOWN_BPF_READ was renamed to LOCKDOWN_BPF_READ_KERNEL > > > in mainline > > > * kernel/power/hibernate.c > > > - trivial: !secretmem_active() was added to the condition in > > > hibernation_available() > > > - cover new security_locked_down() call in kernel/bpf/helpers.c > > > (LOCKDOWN_BPF_WRITE_USER in BPF_FUNC_probe_write_user case) > > > > > > v3: https://lore.kernel.org/lkml/20210616085118.1141101-1-omosnace@redhat.com/ > > > - add the cred argument to security_locked_down() and adapt all callers > > > - keep using current_cred() in BPF, as the hook calls have been shifted > > > to program load time (commit ff40e51043af ("bpf, lockdown, audit: Fix > > > buggy SELinux lockdown permission checks")) > > > - in SELinux, don't ignore hook calls where cred == NULL, but use > > > SECINITSID_KERNEL as the subject instead > > > - update explanations in the commit message > > > > > > v2: https://lore.kernel.org/lkml/20210517092006.803332-1-omosnace@redhat.com/ > > > - change to a single hook based on suggestions by Casey Schaufler > > > > > > v1: https://lore.kernel.org/lkml/20210507114048.138933-1-omosnace@redhat.com/ > > > > The changes between v3 and v4 all seem sane to me, but I'm going to > > let this sit for a few days in hopes that we can collect a few more > > Reviewed-bys and ACKs. If I don't see any objections I'll merge it > > mid-week(ish) into selinux/stable-5.15 and plan on sending it to Linus > > after it goes through a build/test cycle. > > Time's up, I just merged this into selinux/stable-5.15 and I'll send > this to Linus once it passes testing. ... and it's back out of selinux/stable-5.15 in spectacular fashion. I'll be following up with another SELinux patch today or tomorrow. -- paul moore www.paul-moore.com