Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2021589pxj; Sat, 19 Jun 2021 00:19:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy41/lxD9B5M3t8WjacTwmU23St75boGe9Tg7X1xYyWoSMXBA0nXS6bgPDxOQ7xNajnjiNF X-Received: by 2002:a05:6402:35d3:: with SMTP id z19mr9280007edc.324.1624087177736; Sat, 19 Jun 2021 00:19:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624087177; cv=none; d=google.com; s=arc-20160816; b=Wwp1+KjQAmyHlDpebIveYCF3ofsuGjEbM0rKoKYPVkoh5LCjQ8sYTUWkCEJxz6TQBs Z3L1Pq3botd5GX7+i120xUcUfgndQt95ua5kv7doqDtUEwMWi4WAJrQ0Tvs15GbuzvoY ZWp/JlA9tbrUAqHyBHxm1nLg/7oegLEiTt7cbNBnhOl4Ky4CszpHInytOZ6scWbuC9LE P19q6L/p0/1o2pqLKH7xeYNFKL7QJy4TDx8vwm1PWHrsyKvarBQ3kpSvnkUge5q+l28X Vo9Sn2NzpMnU86fXafs4JehKHvSbGILjF8d9DzTw4pC3qmIdjXph31ky4CmvXv0iggRA hTuQ== 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=FE3ige4IUrzO4rZznPTG12clkaJsue7K7FUGlSBMAfs=; b=nVfDw080yTZikjo2zu0Wy0ogSA9TbuUKNKD2zFxdx41EEoFx4ja04g/zkSE8SQlNHn B4JiHYObKqZFWQIA+26xTSVrtm5Q7xmP7wRquXqXF4r6Yz9W3UwEDEqLQ1K+bk/32+8z dwD6FQkl9Oy7p8FaFDK+5Ep7ScDG5jwqGO45i2QorqNqcTzL0yac8HbvUOjVDngAR2Jj DqIAFdq9TAmfbf37eF+ZUyZNtcGbtWPAi4dym+6/Y4mY0qzOWqhWfpTAfH0EP+0ozxx/ 8/XugcoRL2L+rSgF4g1iSvUvDCV4y7NW0NfkZtZLCiD5HFO1zkvvislC7O26U6amOfgJ ln8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b="Yf/hd/nv"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t23si141605ejs.446.2021.06.19.00.19.14; Sat, 19 Jun 2021 00:19:37 -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=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b="Yf/hd/nv"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234920AbhFRWU2 (ORCPT + 99 others); Fri, 18 Jun 2021 18:20:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234907AbhFRWU0 (ORCPT ); Fri, 18 Jun 2021 18:20:26 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1396C0617AF for ; Fri, 18 Jun 2021 15:18:15 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id 69so5426397plc.5 for ; Fri, 18 Jun 2021 15:18:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FE3ige4IUrzO4rZznPTG12clkaJsue7K7FUGlSBMAfs=; b=Yf/hd/nvGltzFs93oV+O815gndRr0N0A4GD+hlEjUljs8fR/r42/5waH+foBbKS7WR 4ieWebjxoeI31qMYukpCCF4suivtuw0KIX1kY4xCHCyeA8Pd+qdR2kMIky/pA2j/9n1z T5UtTANEkuiNSh3GT2iBd2oGjOT4PXXJ8YxOU/uBtqj1IiaNYwuRoT9AQFd4bB3iGSod 26qHtN9qmDpGolnh/MwXPQ8M2sR3UfA7xZml5iJWrbGghC/MI1rSVb3r8vzpAHp9WgHN rQlO7Wfj93/2gQ031V5AE3UWSmVQEAXyZXRDPtXzUcgRjadraLTfDfG3fXk5uJ+V0D/n TtDw== 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=FE3ige4IUrzO4rZznPTG12clkaJsue7K7FUGlSBMAfs=; b=ZczhOQzH6oHCEeyzSVZ/fk7baM9LQVQKDit7VPsPl86o/pY1A+KfByS7wx9Zze8LCG y6YT9rbDwyxfp5tljI1kaMRSlTtohx9scya+odZRcB5JYRx5pAq9XvgH4IkUVR4zdo36 OjNzzOTOHp7S7h8r0BdA2jtQLs/I0QLj2FzpQ+j+0sF5NjyCNPSQXrPsz+SCO4v4uOgr h9NUKhS+aeMYzUwaTjluydF5YNK5zif2wwEdF5KOptahTFSif79da3oMZx0WKQkgUmf/ pt/szPNDaMG71kWImWV3ZIsG0laRAmCdMMwZyfctNEmfY3nHN9PeOhn82TsH22aAZ1yK WTmg== X-Gm-Message-State: AOAM531y21SVUqKK1M+/0WttlvU45yiB2w3H5lKRxAQHApblJV6bKG9E kg6HjnGd9ZT5nXDXX5JHZl4JMmnOAYLOAOaAtaaWPg== X-Received: by 2002:a17:90a:fc88:: with SMTP id ci8mr24404565pjb.13.1624054695229; Fri, 18 Jun 2021 15:18:15 -0700 (PDT) MIME-Version: 1.0 References: <20210616085118.1141101-1-omosnace@redhat.com> In-Reply-To: <20210616085118.1141101-1-omosnace@redhat.com> From: Dan Williams Date: Fri, 18 Jun 2021 15:18:04 -0700 Message-ID: Subject: Re: [PATCH v3] 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" , Paul Moore , Stephen Smalley , selinux@vger.kernel.org, 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@vger.kernel.org, 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 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.