Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp563914pxj; Fri, 28 May 2021 10:02:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6Jz86ez7n1M48a+Z3pwbNofAbapFhvyhOl1esdO51zYigsTuVq1Uqjq7PAj0p9K9QHbev X-Received: by 2002:aa7:dd4f:: with SMTP id o15mr5211845edw.174.1622221349526; Fri, 28 May 2021 10:02:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622221349; cv=none; d=google.com; s=arc-20160816; b=zR0fgvGjo3LbT6tgCsAOLLrZ/PjjjuQmY+cusnS1cnh2WYMlLbsPFUpN9R1+F1Rwmd ogh7HZE+XvVXosQpALq0rnhEBrrNHuNmc49RzO6PXH0V+gA5SlCdeuJ5Y9q0f4h78ikZ mH/8KISj0piqg5fT7kKOROWC+VuZa6rBZdNqbg/7rSrk4O+Mv/sjndrYq/cZfWPgl9a8 Sj4IdOTMoDhHap+oEDZah2OuX7Zb3DaazOuRgzipW2tNM3SF/HoNAwQvvttWCgVpYZwA za8YnbEIr9H/22VLZPepiaBYIp9r1nojetKrEUkXtMPoQbHotEH8UUuwfF3JfwtMy4/A OzDg== 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=cedQ3gdQGSeryyIBkgL2iEXtO51+6C0BVmoVaS+PlM8=; b=yGCK9KzUPnOYJOlGv64R/Eryzrit7o9OfPXw3LlRLgWVM3zbMsXHZRn+YKKgzG856w GsWjO58PDfRPzDCu8RsQ6/zz1tmLnMdRUMlKvHyM79Acy+IZFRSqSmraT7XWTHL2+IjM +Si19OJ9MMbCfiJgF+8hbwElUah52CKcevw+uBOYri4qPV2uYC18fShTTFI+SNd9GLIh sbNxDwx85oXTEXYjkSCALlgZnfOubP/oybgi7htumwm0GJoas4waC1V2ShB5trJy5dYf V0YpAH2oFMJstAD/NIYcyox36+P9yBbgnTt7YM6aMn2VT6c+loaKr6RMWqPPCwLV8SY+ oeoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=cV3BLzZE; 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 t16si6733224edi.299.2021.05.28.09.59.16; Fri, 28 May 2021 10:02:29 -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.20150623.gappssmtp.com header.s=20150623 header.b=cV3BLzZE; 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 S236781AbhE1Pta (ORCPT + 99 others); Fri, 28 May 2021 11:49:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234326AbhE1Pt2 (ORCPT ); Fri, 28 May 2021 11:49:28 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92911C061763 for ; Fri, 28 May 2021 08:47:53 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id s22so5992747ejv.12 for ; Fri, 28 May 2021 08:47:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cedQ3gdQGSeryyIBkgL2iEXtO51+6C0BVmoVaS+PlM8=; b=cV3BLzZEFVqzScfaH+W2YK1IING9yBQLn3zs/n4gZ/1QFQkDsq4/sT+Oz99jSji5OB zMnYo8T2L2JzSDnjz3XCqMFWyADusnMnQUIYhGMPTz7q4lfwQiaODHEtfNCa3vdf1sUN qiVX84dZNOsQWGTudOMSBi3ad6uuqnawwLDXa8x2HKDGZ5kHWAcQUYPTvufJzA8W0211 2H79PEPxxkqVJMjWi2CozKYpkBJGsoo491sHWLofkgqkGyNujdcBqMelLZi4dmYHCj8b pOKX1NVawxYnhgJQJAJRofEZRnqYwlQwS4zBKPV3A/knri21lHjUHOk4+i++RwAMO6gZ ra4Q== 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=cedQ3gdQGSeryyIBkgL2iEXtO51+6C0BVmoVaS+PlM8=; b=TwTaXX7OkJ2sJ4yB3aUWDZcPDWhXb8ik7JHtjShcx3b8ovfKPWtfaWWIcDID49M9kD 2synlDjhiP13eHBsZ3nus/5FmzYlWcew8j2+SnwdG9/+9MkwJ22wPW7V5F6qlAmDNrQq NYb/Dm16VD4IsXW5QIH5xY2w31Tzmarkp7OZdinaJrBL9cv/C/PXX7q5fLpkDfLNU3Xs HZz3d6YAq37A438RLp2rLw2s1PMsjHKrG2ccO/crBXqUCebqC1HV7yKAg/YicKAgy/1l lFlnVBPURvtzRxjYnwu/NMvimOmwLwzoUPAQecKA7eh7Z71YTmbLaRP3U9i8Om9XGL9i 1dyQ== X-Gm-Message-State: AOAM5316x8A8EMuqfu2aohW4Ggpo/sQM6PzFFGTVZUXT7esqGsoQrwOP KyHvhDZuwsOe1E07Rpx2bGw1Zrj8X2sZZURfeVE+ X-Received: by 2002:a17:906:840c:: with SMTP id n12mr9552143ejx.431.1622216871579; Fri, 28 May 2021 08:47:51 -0700 (PDT) MIME-Version: 1.0 References: <20210517092006.803332-1-omosnace@redhat.com> <01135120-8bf7-df2e-cff0-1d73f1f841c3@iogearbox.net> In-Reply-To: <01135120-8bf7-df2e-cff0-1d73f1f841c3@iogearbox.net> From: Paul Moore Date: Fri, 28 May 2021 11:47:40 -0400 Message-ID: Subject: Re: [PATCH v2] lockdown,selinux: avoid bogus SELinux lockdown permission checks To: Daniel Borkmann Cc: Ondrej Mosnacek , linux-security-module@vger.kernel.org, James Morris , Steven Rostedt , Ingo Molnar , Stephen Smalley , selinux@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, bpf@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Casey Schaufler , jolsa@redhat.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 28, 2021 at 3:10 AM Daniel Borkmann wrote: > On 5/28/21 3:37 AM, Paul Moore wrote: > > On Mon, May 17, 2021 at 5:22 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 modifying the hook to accept a struct cred > >> pointer as argument, where NULL will be interpreted as a request for a > >> "global", task-independent lockdown decision only. Then modify SELinux > >> to ignore calls with cred == NULL. > > > > I'm not overly excited about skipping the access check when cred is > > NULL. Based on the description and the little bit that I've dug into > > thus far it looks like using SECINITSID_KERNEL as the subject would be > > much more appropriate. *Something* (the kernel in most of the > > relevant cases it looks like) is requesting that a potentially > > sensitive disclosure be made, and ignoring it seems like the wrong > > thing to do. Leaving the access control intact also provides a nice > > avenue to audit these requests should users want to do that. > > I think the rationale/workaround for ignoring calls with cred == NULL (or the previous > patch with the unimplemented hook) from Ondrej was two-fold, at least speaking for his > seen tracing cases: > > i) The audit events that are triggered due to calls to security_locked_down() > can OOM kill a machine, see below details [0]. > > ii) It seems to be causing a deadlock via slow_avc_audit() -> audit_log_end() > when presumingly trying to wake up kauditd [1]. > > How would your suggestion above solve both i) and ii)? First off, a bit of general commentary - I'm not sure if Ondrej was aware of this, but info like that is good to have in the commit description. Perhaps it was in the linked RHBZ but I try not to look at those when reviewing patches; the commit descriptions must be self-sufficient since we can't rely on the accessibility or the lifetime of external references. It's fine if people want to include external links in their commits, I would actually even encourage it in some cases, but the links shouldn't replace a proper description of the problem and why the proposed solution is The Best Solution. With that out of the way, it sounds like your issue isn't so much the access check, but rather the frequency of the access denials and the resulting audit records in your particular use case. My initial reaction is that you might want to understand why you are getting so many SELinux access denials, your loaded security policy clearly does not match with your intended use :) Beyond that, if you want to basically leave things as-is but quiet the high frequency audit records that result from these SELinux denials you might want to look into the SELinux "dontaudit" policy rule, it was created for things like this. Some info can be found in The SELinux Notebook, relevant link below: * https://github.com/SELinuxProject/selinux-notebook/blob/main/src/avc_rules.md#dontaudit The deadlock issue that was previously reported remains an open case as far as I'm concerned; I'm presently occupied trying to sort out a rather serious issue with respect to io_uring and LSM/audit (plus general stuff at $DAYJOB) so I haven't had time to investigate this any further. Of course anyone else is welcome to dive into it (I always want to encourage this, especially from "performance people" who just want to shut it all off), however if the answer is basically "disable LSM and/or audit checks" you have to know that it is going to result in a high degree of skepticism from me, so heavy documentation on why it is The Best Solution would be a very good thing :) Beyond that, I think the suggestions above of "why do you have so many policy denials?" and "have you looked into dontaudit?" are solid places to look for a solution in your particular case. > >> Since most callers will just want to pass current_cred() as the cred > >> parameter, rename the hook to security_cred_locked_down() and provide > >> the original security_locked_down() function as a simple wrapper around > >> the new hook. > > [...] > > > >> 3. kernel/trace/bpf_trace.c:bpf_probe_read_kernel{,_str}_common() > >> Called when a BPF program calls a helper that could leak kernel > >> memory. The task context is not relevant here, since the program > >> may very well be run in the context of a different task than the > >> consumer of the data. > >> See: https://bugzilla.redhat.com/show_bug.cgi?id=1955585 > > > > The access control check isn't so much who is consuming the data, but > > who is requesting a potential violation of a "lockdown", yes? For > > example, the SELinux policy rule for the current lockdown check looks > > something like this: > > > > allow : lockdown { }; > > > > It seems to me that the task context is relevant here and performing > > the access control check based on the task's domain is correct. > > This doesn't make much sense to me, it's /not/ the task 'requesting a potential > violation of a "lockdown"', but rather the running tracing program which is e.g. > inspecting kernel data structures around the triggered event. If I understood > you correctly, having an 'allow' check on, say, httpd would be rather odd since > things like perf/bcc/bpftrace/systemtap/etc is installing the tracing probe instead. > > Meaning, if we would /not/ trace such events (like in the prior mentioned syscall > example), then there is also no call to the security_locked_down() from that same/ > unmodified application. My turn to say that you don't make much sense to me :) Let's reset. What task_struct is running the BPF tracing program which is calling into security_locked_down()? My current feeling is that it is this context/domain/cred that should be used for the access control check; in the cases where it is a kernel thread, I think passing NULL is reasonable, but I think the proper thing for SELinux is to interpret NULL as kernel_t. -- paul moore www.paul-moore.com