From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57507C04FE3 for ; Tue, 31 Aug 2021 09:08:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D97561029 for ; Tue, 31 Aug 2021 09:08:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240580AbhHaJJU (ORCPT ); Tue, 31 Aug 2021 05:09:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22681 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240537AbhHaJJS (ORCPT ); Tue, 31 Aug 2021 05:09:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630400903; 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=lCeb7MSVHIA6AQvPBMrpCMcewt6C5Hp/EtiNe37zzes=; b=i5pQA4mz1BFv+EFcR1ZstiuLo5fwLkAUMye5dkOkldQCBVzLmxtXglU/0MhcCMmNQfL4zB 8hVCHfwaRjQeFqsHTZEhKqTxVPt1G0h9DK6rwVIIUILPY48bK0IeBd4hlplEdqloqIMTLs AugHdcgbpTJ4VjH4JLZ3+wMtMSmxqlk= Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-601-o2oj4HPQNOe2AB-pQw_yRw-1; Tue, 31 Aug 2021 05:08:20 -0400 X-MC-Unique: o2oj4HPQNOe2AB-pQw_yRw-1 Received: by mail-yb1-f200.google.com with SMTP id h143-20020a25d095000000b0059c2e43cd3eso5295802ybg.12 for ; Tue, 31 Aug 2021 02:08:20 -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=lCeb7MSVHIA6AQvPBMrpCMcewt6C5Hp/EtiNe37zzes=; b=IKBZ13jyVi5fGdRnGjJxIHt0CGOtrn6uDXzoAFiJ/QTtXqZE5NL7umk5hlDZWlB3B4 1YNxhzmp9g0Dn6vBG3DkFFN9RGRp7hAD9OtkwmWbmi0p0ANaZQXxBm55CFKi+fi9daCb etm0ytKH9DLQTiE7/TLpF9Fh+1Fq0gRRYPpBN9zVeNL9ehGv6hAM9XHIlvOIJvm0BEQu PgWTKRbGkMM0NxKz4qfMSSC3dJTo68Y1bc7lUIp8gnnVBwDfCI6QsiOYJQw48nKP9S+/ YGWW9pSvlp+FG4b2h6hmrw7BFPMkRJefQH+FktFORLMzTwVhQj10nZPyljAFz18P9MT2 u4tA== X-Gm-Message-State: AOAM532h5aU8eHVihszsaYlK/A8HewmiID3ihzcrg2Gq/JklR/HdWyuI cs337pSMz47MLl1idS+AXB3oGeYzfDzsHQCaXaqEIykORG3Mfz9hASP5Mj8Dtn3+d0hSBLVFAPW qd+0qrDQKlBWHIzRYLjWo6aCau4HPK0mi4NOhLQ== X-Received: by 2002:a25:c184:: with SMTP id r126mr28651654ybf.123.1630400899633; Tue, 31 Aug 2021 02:08:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4ZNnqHdPHd1KpwqFLFV6AFeVHb5LZ7Jb5RG2vtJXhk7vybNwPbdTc2aQhHuASLbfSbAuaEwPm90oIL61rhUM= X-Received: by 2002:a25:c184:: with SMTP id r126mr28651621ybf.123.1630400899378; Tue, 31 Aug 2021 02:08:19 -0700 (PDT) MIME-Version: 1.0 References: <20210616085118.1141101-1-omosnace@redhat.com> In-Reply-To: From: Ondrej Mosnacek Date: Tue, 31 Aug 2021 11:08:08 +0200 Message-ID: Subject: Re: [PATCH v3] lockdown,selinux: fix wrong subject in some SELinux lockdown checks To: Paul Moore Cc: Linux Security Module list , James Morris , Steven Rostedt , Ingo Molnar , Steffen Klassert , Herbert Xu , "David S . Miller" , Stephen Smalley , SElinux list , linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-acpi@vger.kernel.org, linux-cxl@vger.kernel.org, linux-efi@vger.kernel.org, Linux FS Devel , linux-pci@vger.kernel.org, linux-pm@vger.kernel.org, linux-serial@vger.kernel.org, bpf , network dev , kexec@lists.infradead.org, Linux kernel mailing list , Casey Schaufler , Michael Ellerman Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org On Fri, Jun 18, 2021 at 5:40 AM Paul Moore wrote: > On Wed, Jun 16, 2021 at 4:51 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") > > Signed-off-by: Ondrej Mosnacek > > This seems reasonable to me, but before I merge it into the SELinux > tree I think it would be good to get some ACKs from the relevant > subsystem folks. I don't believe we ever saw a response to the last > question for the PPC folks, did we? Can we move this forward somehow, please? Quoting the yet-unanswered question from the v2 thread for convenience: > > > The callers migrated to the new hook, passing NULL as cred: > > > 1. arch/powerpc/xmon/xmon.c [...] > > > > This definitely sounds like kernel_t based on the description above. > > Here I'm a little concerned that the hook might be called from some > unusual interrupt, which is not masked by spin_lock_irqsave()... We > ran into this with PMI (Platform Management Interrupt) before, see > commit 5ae5fbd21079 ("powerpc/perf: Fix handling of privilege level > checks in perf interrupt context"). While I can't see anything that > would suggest something like this happening here, the whole thing is > so foreign to me that I'm wary of making assumptions :) > > @Michael/PPC devs, can you confirm to us that xmon_is_locked_down() is > only called from normal syscall/interrupt context (as opposed to > something tricky like PMI)? I strongly suspect the answer will be just "Of course it is, why would you even ask such a silly question?", but please let's have it on record so we can finally get this patch merged... > > --- > > > > v3: > > - 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/ > > > > arch/powerpc/xmon/xmon.c | 4 ++-- > > arch/x86/kernel/ioport.c | 4 ++-- > > arch/x86/kernel/msr.c | 4 ++-- > > arch/x86/mm/testmmiotrace.c | 2 +- > > drivers/acpi/acpi_configfs.c | 2 +- > > drivers/acpi/custom_method.c | 2 +- > > drivers/acpi/osl.c | 3 ++- > > drivers/acpi/tables.c | 2 +- > > drivers/char/mem.c | 2 +- > > drivers/cxl/mem.c | 2 +- > > drivers/firmware/efi/efi.c | 2 +- > > drivers/firmware/efi/test/efi_test.c | 2 +- > > drivers/pci/pci-sysfs.c | 6 +++--- > > drivers/pci/proc.c | 6 +++--- > > drivers/pci/syscall.c | 2 +- > > drivers/pcmcia/cistpl.c | 2 +- > > drivers/tty/serial/serial_core.c | 2 +- > > fs/debugfs/file.c | 2 +- > > fs/debugfs/inode.c | 2 +- > > fs/proc/kcore.c | 2 +- > > fs/tracefs/inode.c | 2 +- > > include/linux/lsm_hook_defs.h | 2 +- > > include/linux/lsm_hooks.h | 1 + > > include/linux/security.h | 4 ++-- > > kernel/bpf/helpers.c | 10 ++++++---- > > kernel/events/core.c | 2 +- > > kernel/kexec.c | 2 +- > > kernel/kexec_file.c | 2 +- > > kernel/module.c | 2 +- > > kernel/params.c | 2 +- > > kernel/power/hibernate.c | 3 ++- > > kernel/trace/bpf_trace.c | 20 ++++++++++++-------- > > kernel/trace/ftrace.c | 4 ++-- > > kernel/trace/ring_buffer.c | 2 +- > > kernel/trace/trace.c | 10 +++++----- > > kernel/trace/trace_events.c | 2 +- > > kernel/trace/trace_events_hist.c | 4 ++-- > > kernel/trace/trace_events_synth.c | 2 +- > > kernel/trace/trace_events_trigger.c | 2 +- > > kernel/trace/trace_kprobe.c | 6 +++--- > > kernel/trace/trace_printk.c | 2 +- > > kernel/trace/trace_stack.c | 2 +- > > kernel/trace/trace_stat.c | 2 +- > > kernel/trace/trace_uprobe.c | 4 ++-- > > net/xfrm/xfrm_user.c | 11 +++++++++-- > > security/lockdown/lockdown.c | 3 ++- > > security/security.c | 4 ++-- > > security/selinux/hooks.c | 7 +++++-- > > 48 files changed, 97 insertions(+), 77 deletions(-) > > -- > paul moore > www.paul-moore.com > -- Ondrej Mosnacek Software Engineer, Linux Security - SELinux kernel Red Hat, Inc From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64988C432BE for ; Tue, 31 Aug 2021 09:10:22 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 68D6C61029 for ; Tue, 31 Aug 2021 09:10:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 68D6C61029 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GzLxl5zbxz2yLm for ; Tue, 31 Aug 2021 19:10:19 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QTXu2LAL; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T9N8IfFX; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=216.205.24.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=omosnace@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QTXu2LAL; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T9N8IfFX; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4GzLww5bVSz2yJ5 for ; Tue, 31 Aug 2021 19:09:36 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630400973; 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=lCeb7MSVHIA6AQvPBMrpCMcewt6C5Hp/EtiNe37zzes=; b=QTXu2LALP6odVSKkRAWN9FGV8TQNpTVp7Kc8cL+vRT9xE1WVNDcnhDazN6cjB+3LsEVy/S iaHYFYHHBfhqlaXY4wdaFjSbUDbz6uPBlw72lJrW+RvRhoc9a08ZfleqrdGIlcUx3lGdZ/ 28skhgurbHz+U8a5OpkTGtQPz2n5pME= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630400974; 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=lCeb7MSVHIA6AQvPBMrpCMcewt6C5Hp/EtiNe37zzes=; b=T9N8IfFX3nw2JUKRbdli+hEMo57yx3ogCmsH/cIlIRionLIepvqBra72AW1qBcqkCC6D4k CTuut8H5EmajgAjSeofOiAeFjZrBtD+iaKMBBFVFKfq8QIF69dvD9T7Xa9MmqAa2jDcDLT zmQsvCTMJPljgJ33JaWeD6ux0fgtuPM= Received: from mail-yb1-f200.google.com (mail-yb1-f200.google.com [209.85.219.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-15-Y1whsINSP62dxcHd_CkG7A-1; Tue, 31 Aug 2021 05:08:20 -0400 X-MC-Unique: Y1whsINSP62dxcHd_CkG7A-1 Received: by mail-yb1-f200.google.com with SMTP id 131-20020a251489000000b0059bdeb10a84so4934719ybu.15 for ; Tue, 31 Aug 2021 02:08:20 -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=lCeb7MSVHIA6AQvPBMrpCMcewt6C5Hp/EtiNe37zzes=; b=WJZy7IWe05fD95aiPA1CyXtZIqBAnn2UpyuCQw4QDBZ38t9KaVqKo+awFmOwi8MHaX oC7F+my03GsiHDnOzs7Tk62mRL2YKR4EO0J+ESaGZdm0+KTBKHXykEm5Dk7+Qo0yXwyK vvtnPoF1xf8sKSO1D4uyF8/VluF9Aj/TGF0IFQMUl+PZ8O1XbXPV1qVJ69I0FpUStqMR liK8IwhNsqoLXfsD6ZkzM34nIzq6QaAn2BN7tLe4wW59MFePUjSHqQJpu100liDpBUfv t8+KzRUWCSnhK0VGKAmtZk4ycltlhg04KGURPi7DHwShp84p/tZEDoi9PoLwUEorj28m 9Vig== X-Gm-Message-State: AOAM530dt5sSPHZXoitCXkA+0gx4khR/cE7rE9rImD4sXUQcP1+5U6w0 yxHXULXfytODwN1XwF9An6aZnxZGKJOou6kksLu9nUwkYKE6E0A3Q0IBfYnOOCLwVJXotaA4Elq FPdqg8Tp4LS2GUK18pVGa3Wbg2ZWHTI2W6bEpok5xTA== X-Received: by 2002:a25:c184:: with SMTP id r126mr28651660ybf.123.1630400899634; Tue, 31 Aug 2021 02:08:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4ZNnqHdPHd1KpwqFLFV6AFeVHb5LZ7Jb5RG2vtJXhk7vybNwPbdTc2aQhHuASLbfSbAuaEwPm90oIL61rhUM= X-Received: by 2002:a25:c184:: with SMTP id r126mr28651621ybf.123.1630400899378; Tue, 31 Aug 2021 02:08:19 -0700 (PDT) MIME-Version: 1.0 References: <20210616085118.1141101-1-omosnace@redhat.com> In-Reply-To: From: Ondrej Mosnacek Date: Tue, 31 Aug 2021 11:08:08 +0200 Message-ID: Subject: Re: [PATCH v3] lockdown,selinux: fix wrong subject in some SELinux lockdown checks To: Paul Moore Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=omosnace@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-efi@vger.kernel.org, linux-pci@vger.kernel.org, linux-cxl@vger.kernel.org, Steffen Klassert , Herbert Xu , x86@kernel.org, James Morris , linux-acpi@vger.kernel.org, Ingo Molnar , linux-serial@vger.kernel.org, linux-pm@vger.kernel.org, SElinux list , Steven Rostedt , Casey Schaufler , network dev , Stephen Smalley , kexec@lists.infradead.org, Linux kernel mailing list , Linux Security Module list , Linux FS Devel , bpf , linuxppc-dev@lists.ozlabs.org, "David S . Miller" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Fri, Jun 18, 2021 at 5:40 AM Paul Moore wrote: > On Wed, Jun 16, 2021 at 4:51 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") > > Signed-off-by: Ondrej Mosnacek > > This seems reasonable to me, but before I merge it into the SELinux > tree I think it would be good to get some ACKs from the relevant > subsystem folks. I don't believe we ever saw a response to the last > question for the PPC folks, did we? Can we move this forward somehow, please? Quoting the yet-unanswered question from the v2 thread for convenience: > > > The callers migrated to the new hook, passing NULL as cred: > > > 1. arch/powerpc/xmon/xmon.c [...] > > > > This definitely sounds like kernel_t based on the description above. > > Here I'm a little concerned that the hook might be called from some > unusual interrupt, which is not masked by spin_lock_irqsave()... We > ran into this with PMI (Platform Management Interrupt) before, see > commit 5ae5fbd21079 ("powerpc/perf: Fix handling of privilege level > checks in perf interrupt context"). While I can't see anything that > would suggest something like this happening here, the whole thing is > so foreign to me that I'm wary of making assumptions :) > > @Michael/PPC devs, can you confirm to us that xmon_is_locked_down() is > only called from normal syscall/interrupt context (as opposed to > something tricky like PMI)? I strongly suspect the answer will be just "Of course it is, why would you even ask such a silly question?", but please let's have it on record so we can finally get this patch merged... > > --- > > > > v3: > > - 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/ > > > > arch/powerpc/xmon/xmon.c | 4 ++-- > > arch/x86/kernel/ioport.c | 4 ++-- > > arch/x86/kernel/msr.c | 4 ++-- > > arch/x86/mm/testmmiotrace.c | 2 +- > > drivers/acpi/acpi_configfs.c | 2 +- > > drivers/acpi/custom_method.c | 2 +- > > drivers/acpi/osl.c | 3 ++- > > drivers/acpi/tables.c | 2 +- > > drivers/char/mem.c | 2 +- > > drivers/cxl/mem.c | 2 +- > > drivers/firmware/efi/efi.c | 2 +- > > drivers/firmware/efi/test/efi_test.c | 2 +- > > drivers/pci/pci-sysfs.c | 6 +++--- > > drivers/pci/proc.c | 6 +++--- > > drivers/pci/syscall.c | 2 +- > > drivers/pcmcia/cistpl.c | 2 +- > > drivers/tty/serial/serial_core.c | 2 +- > > fs/debugfs/file.c | 2 +- > > fs/debugfs/inode.c | 2 +- > > fs/proc/kcore.c | 2 +- > > fs/tracefs/inode.c | 2 +- > > include/linux/lsm_hook_defs.h | 2 +- > > include/linux/lsm_hooks.h | 1 + > > include/linux/security.h | 4 ++-- > > kernel/bpf/helpers.c | 10 ++++++---- > > kernel/events/core.c | 2 +- > > kernel/kexec.c | 2 +- > > kernel/kexec_file.c | 2 +- > > kernel/module.c | 2 +- > > kernel/params.c | 2 +- > > kernel/power/hibernate.c | 3 ++- > > kernel/trace/bpf_trace.c | 20 ++++++++++++-------- > > kernel/trace/ftrace.c | 4 ++-- > > kernel/trace/ring_buffer.c | 2 +- > > kernel/trace/trace.c | 10 +++++----- > > kernel/trace/trace_events.c | 2 +- > > kernel/trace/trace_events_hist.c | 4 ++-- > > kernel/trace/trace_events_synth.c | 2 +- > > kernel/trace/trace_events_trigger.c | 2 +- > > kernel/trace/trace_kprobe.c | 6 +++--- > > kernel/trace/trace_printk.c | 2 +- > > kernel/trace/trace_stack.c | 2 +- > > kernel/trace/trace_stat.c | 2 +- > > kernel/trace/trace_uprobe.c | 4 ++-- > > net/xfrm/xfrm_user.c | 11 +++++++++-- > > security/lockdown/lockdown.c | 3 ++- > > security/security.c | 4 ++-- > > security/selinux/hooks.c | 7 +++++-- > > 48 files changed, 97 insertions(+), 77 deletions(-) > > -- > paul moore > www.paul-moore.com > -- Ondrej Mosnacek Software Engineer, Linux Security - SELinux kernel Red Hat, Inc From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mKznK-001uRv-FP for kexec@lists.infradead.org; Tue, 31 Aug 2021 09:11:06 +0000 Received: by mail-yb1-f199.google.com with SMTP id p69-20020a254248000000b00598282d96ceso5617974yba.3 for ; Tue, 31 Aug 2021 02:08:20 -0700 (PDT) MIME-Version: 1.0 References: <20210616085118.1141101-1-omosnace@redhat.com> In-Reply-To: From: Ondrej Mosnacek Date: Tue, 31 Aug 2021 11:08:08 +0200 Message-ID: Subject: Re: [PATCH v3] lockdown,selinux: fix wrong subject in some SELinux lockdown checks List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kexec" Errors-To: kexec-bounces+dwmw2=infradead.org@lists.infradead.org To: Paul Moore Cc: Linux Security Module list , James Morris , Steven Rostedt , Ingo Molnar , Steffen Klassert , Herbert Xu , "David S . Miller" , Stephen Smalley , SElinux list , linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-acpi@vger.kernel.org, linux-cxl@vger.kernel.org, linux-efi@vger.kernel.org, Linux FS Devel , linux-pci@vger.kernel.org, linux-pm@vger.kernel.org, linux-serial@vger.kernel.org, bpf , network dev , kexec@lists.infradead.org, Linux kernel mailing list , Casey Schaufler , Michael Ellerman On Fri, Jun 18, 2021 at 5:40 AM Paul Moore wrote: > On Wed, Jun 16, 2021 at 4:51 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") > > Signed-off-by: Ondrej Mosnacek > > This seems reasonable to me, but before I merge it into the SELinux > tree I think it would be good to get some ACKs from the relevant > subsystem folks. I don't believe we ever saw a response to the last > question for the PPC folks, did we? Can we move this forward somehow, please? Quoting the yet-unanswered question from the v2 thread for convenience: > > > The callers migrated to the new hook, passing NULL as cred: > > > 1. arch/powerpc/xmon/xmon.c [...] > > > > This definitely sounds like kernel_t based on the description above. > > Here I'm a little concerned that the hook might be called from some > unusual interrupt, which is not masked by spin_lock_irqsave()... We > ran into this with PMI (Platform Management Interrupt) before, see > commit 5ae5fbd21079 ("powerpc/perf: Fix handling of privilege level > checks in perf interrupt context"). While I can't see anything that > would suggest something like this happening here, the whole thing is > so foreign to me that I'm wary of making assumptions :) > > @Michael/PPC devs, can you confirm to us that xmon_is_locked_down() is > only called from normal syscall/interrupt context (as opposed to > something tricky like PMI)? I strongly suspect the answer will be just "Of course it is, why would you even ask such a silly question?", but please let's have it on record so we can finally get this patch merged... > > --- > > > > v3: > > - 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/ > > > > arch/powerpc/xmon/xmon.c | 4 ++-- > > arch/x86/kernel/ioport.c | 4 ++-- > > arch/x86/kernel/msr.c | 4 ++-- > > arch/x86/mm/testmmiotrace.c | 2 +- > > drivers/acpi/acpi_configfs.c | 2 +- > > drivers/acpi/custom_method.c | 2 +- > > drivers/acpi/osl.c | 3 ++- > > drivers/acpi/tables.c | 2 +- > > drivers/char/mem.c | 2 +- > > drivers/cxl/mem.c | 2 +- > > drivers/firmware/efi/efi.c | 2 +- > > drivers/firmware/efi/test/efi_test.c | 2 +- > > drivers/pci/pci-sysfs.c | 6 +++--- > > drivers/pci/proc.c | 6 +++--- > > drivers/pci/syscall.c | 2 +- > > drivers/pcmcia/cistpl.c | 2 +- > > drivers/tty/serial/serial_core.c | 2 +- > > fs/debugfs/file.c | 2 +- > > fs/debugfs/inode.c | 2 +- > > fs/proc/kcore.c | 2 +- > > fs/tracefs/inode.c | 2 +- > > include/linux/lsm_hook_defs.h | 2 +- > > include/linux/lsm_hooks.h | 1 + > > include/linux/security.h | 4 ++-- > > kernel/bpf/helpers.c | 10 ++++++---- > > kernel/events/core.c | 2 +- > > kernel/kexec.c | 2 +- > > kernel/kexec_file.c | 2 +- > > kernel/module.c | 2 +- > > kernel/params.c | 2 +- > > kernel/power/hibernate.c | 3 ++- > > kernel/trace/bpf_trace.c | 20 ++++++++++++-------- > > kernel/trace/ftrace.c | 4 ++-- > > kernel/trace/ring_buffer.c | 2 +- > > kernel/trace/trace.c | 10 +++++----- > > kernel/trace/trace_events.c | 2 +- > > kernel/trace/trace_events_hist.c | 4 ++-- > > kernel/trace/trace_events_synth.c | 2 +- > > kernel/trace/trace_events_trigger.c | 2 +- > > kernel/trace/trace_kprobe.c | 6 +++--- > > kernel/trace/trace_printk.c | 2 +- > > kernel/trace/trace_stack.c | 2 +- > > kernel/trace/trace_stat.c | 2 +- > > kernel/trace/trace_uprobe.c | 4 ++-- > > net/xfrm/xfrm_user.c | 11 +++++++++-- > > security/lockdown/lockdown.c | 3 ++- > > security/security.c | 4 ++-- > > security/selinux/hooks.c | 7 +++++-- > > 48 files changed, 97 insertions(+), 77 deletions(-) > > -- > paul moore > www.paul-moore.com > -- Ondrej Mosnacek Software Engineer, Linux Security - SELinux kernel Red Hat, Inc _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec