Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4322672pxb; Tue, 31 Aug 2021 02:13:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSzSEHEs35ZfjksK1gaLGgcG9jGOQcQDsx0QVOWuE81sGJlqFizaTYqtfD84oxQiQjeWBI X-Received: by 2002:a05:6402:895:: with SMTP id e21mr29411837edy.54.1630401226618; Tue, 31 Aug 2021 02:13:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630401226; cv=none; d=google.com; s=arc-20160816; b=FauLZGFUDqMJ2nlRXTg2CV//pZMK/+r5I/p3RryN+eOxgE4BE/xF4hory96Hyr9nKS GA8ffsW3bOn6LgiDN9ic7cCzKDrijI0e+1nl9Fn+TNYr3dJKvxgmlkjr7eAtqxfUdjMY iT3u8VKmwmNTuinGgGjQrl0lRqkhCuQJJ5wzYlYe8cgzcDkRUICL4gjXmaSJftMLSlkF jIsq+EQn9TDBsz4nP8IOQ+XuK36PBxBdJ7u9FvIhcwgONI5opO5nE6aWdPzR7iDyeHzq 4SLq3b7dfkacFMG88bTcl6A2h8WpPDU4SE1xty1i5RiCzErRfhGUrknUpb9ahRyShH9D MB/Q== 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=KqIomsJD8qkvJRmtf6AOcHNJotQV38aV9t/Y65DfWRs=; b=hCO7eAXfw1GNVU02DmGgYhBlSgWUPZYalxzxym3uvpWYCY59PO5dQaycyPCjHdt90Z KUFfPbu+nLtPPx8xtZc+2Im5CqXDj4gSHRmB5prYDi7j2CWGOSQdbPaQw8VoOmPAWMA9 jj1JWB8LFAFDaCX2EmyYUrGdzT6WnHO5rWxRgBZGCOrrI9ru/25jY3tMG9uI6/F7vehx ilFK9ca3M/EB1r98vlQ9B0q58MNonf4byEdBCxdlSTKseyDmQWtInIQAI6Q29dpwh3Sw xSr2qnCF7OAfugampjTaIuY/utFq0WGo8Y+XNg67O8yOq59Iibb4DHquHTu/9ssV4xAO m2mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="LxeTv/7t"; 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 s23si16413622ejj.684.2021.08.31.02.13.03; Tue, 31 Aug 2021 02:13:46 -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="LxeTv/7t"; 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 S240607AbhHaJKj (ORCPT + 99 others); Tue, 31 Aug 2021 05:10:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23515 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240606AbhHaJKh (ORCPT ); Tue, 31 Aug 2021 05:10:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630400982; 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=KqIomsJD8qkvJRmtf6AOcHNJotQV38aV9t/Y65DfWRs=; b=LxeTv/7ttnAXoIUrv1ZolVKo2n7VM5GwGdLLbSyK4qohl1T3uPogKI+XdYYnG/UjWcRKHX BG/Ee/tZDGyg3Wz92TpFWxOW7j1IO2yzUUp7UrxCJkwLPaDqE6un2HANXZRqBSFSbsik5H VjRUYjzyf+h45xCxcuI5Ds88+ti0jcg= 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-553-LYBxs2cyPbGiJreZdgrAnQ-1; Tue, 31 Aug 2021 05:09:41 -0400 X-MC-Unique: LYBxs2cyPbGiJreZdgrAnQ-1 Received: by mail-yb1-f200.google.com with SMTP id w8-20020a259188000000b0059bf0bed21fso7872923ybl.18 for ; Tue, 31 Aug 2021 02:09:41 -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=KqIomsJD8qkvJRmtf6AOcHNJotQV38aV9t/Y65DfWRs=; b=P86Pi3foNFStoEFo9g+lirKnavet/3KnLTa+C9cfn8SQ5E3CyKHcNOFWe/z/wtyM9V xnzzK4uJEcUEsMoZ43JoSjd/1BvUh/369hcyiwC+t6jfQx6BuEPKzguozS7pqChIoKfX fO3jt/UcYwzASZK5au3Ug01Oi7nh+2wI0NXMtcasqWtyE7P8vwpQg/TQj4g/q4WwNeud bfQB26yRXgfrjVZ4y8UUQPA+turqhT+FcPYlKZ+YvfhFEl9obGxPyvyXj/V+FVcN175w BK1aVE9xQdY2wnlVdk0cDKYJhXz4Jlp4DtZnRdCjMV+WSkdS8zSZI/QI3e2R/jZ5D1z2 lTXg== X-Gm-Message-State: AOAM5315jHitNTDfnB26oXhiF211w5vPVU1mfpWw+IEfJAYMBmUUIhFQ yYnBuOCfNo12XNxU+AboVQIk7LuHK9M9PCKjU/94GWXAAKDyasDd7Lx78TZPKyV3PbHO1yVwace k00/Ur3IEF1485hyFlN6XHrcdN3LCzOCCoCwXuW61 X-Received: by 2002:a25:1d08:: with SMTP id d8mr29534406ybd.377.1630400980466; Tue, 31 Aug 2021 02:09:40 -0700 (PDT) X-Received: by 2002:a25:1d08:: with SMTP id d8mr29534365ybd.377.1630400980209; Tue, 31 Aug 2021 02:09:40 -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:09:29 +0200 Message-ID: Subject: Re: [PATCH v3] lockdown,selinux: fix wrong subject in some SELinux lockdown checks To: Dan Williams Cc: Linux Security Module list , James Morris , Steven Rostedt , Ingo Molnar , Steffen Klassert , Herbert Xu , "David S . Miller" , Paul Moore , Stephen Smalley , SElinux list , linuxppc-dev , X86 ML , Linux ACPI , linux-cxl@vger.kernel.org, linux-efi , linux-fsdevel , Linux PCI , Linux-pm mailing list , linux-serial@vger.kernel.org, bpf , Netdev , Kexec Mailing List , Linux Kernel Mailing List , Casey Schaufler Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Jun 19, 2021 at 12:18 AM Dan Williams wrote: > On Wed, Jun 16, 2021 at 1: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 > [..] > > diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c > > index 2acc6173da36..c1747b6555c7 100644 > > --- a/drivers/cxl/mem.c > > +++ b/drivers/cxl/mem.c > > @@ -568,7 +568,7 @@ static bool cxl_mem_raw_command_allowed(u16 opcode) > > if (!IS_ENABLED(CONFIG_CXL_MEM_RAW_COMMANDS)) > > return false; > > > > - if (security_locked_down(LOCKDOWN_NONE)) > > + if (security_locked_down(current_cred(), LOCKDOWN_NONE)) > > Acked-by: Dan Williams > > ...however that usage looks wrong. The expectation is that if kernel > integrity protections are enabled then raw command access should be > disabled. So I think that should be equivalent to LOCKDOWN_PCI_ACCESS > in terms of the command capabilities to filter. Yes, the LOCKDOWN_NONE seems wrong here... but it's a pre-existing bug and I didn't want to go down yet another rabbit hole trying to fix it. I'll look at this again once this patch is settled - it may indeed be as simple as replacing LOCKDOWN_NONE with LOCKDOWN_PCI_ACCESS. -- Ondrej Mosnacek Software Engineer, Linux Security - SELinux kernel Red Hat, Inc.