Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3994104pxj; Tue, 8 Jun 2021 04:03:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNgvQQMys9c+JpCw/kOmQqMIxEpPa9/NZRgQR6O+L9FfqWxHRwTVq7FDCySa0cZE+oqC9E X-Received: by 2002:a17:906:7fc5:: with SMTP id r5mr23357915ejs.474.1623150209351; Tue, 08 Jun 2021 04:03:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623150209; cv=none; d=google.com; s=arc-20160816; b=V/4uykh2Mj6SQcac7Qt1vftzVDBS//+IPsa093Yir7YzDLEQ7lsk1Wk0Plll0Hexmo DLfbmk8Xz+2ZE3hwFBFASPoRd5asnylwKOyU8Bs6azfw1JMCKDBp3VSjj9vEe3Z69AAe hNmBGprQtKQG/zWokNDvE1kKubDO6rlhFOa2LBF8kkxgEr/XyEQ63SuMUrRS0x6vcxax o4+l0YwA89ODNlgZFUNfd3BRkGfAHNZ4O4yfTxRR5kqDhyxCYNcKLdDdl9VwEx4gP1ek Ddg+WaBiB+v02QeZpInMh49I3LINpIF/RBpUdHVkv0q0KDI/XSli0TlK6K7cvfH//qAI iSlg== 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=LH+kGGXvul4/VtBvp8swcElDLFMoCOqrADXXWgo8nOs=; b=o8QXl4Hnr8kQtsJQFBZO8VKCYNUOq/xehdxH/9ioLUTASsZVQTo/RGiZqLR2q/um+y ve9Jb69EKasxwcJyCdPLSJIRhKfB7i/9HtpZryLhfiHclyyNz9HkpOB46llab2PNCvEd xvYNsbCO9pIsiaO87Uk6bN0ouu/fIYGID9WvS9xkOkAOvMnRhBOrvf8/x+UjGj2RIMmw WLtOeX1todMI8IW9FxHbKBiseUSnEsGAZ9hBMj6MgcdzlDThqSnfGhocS7IfVCzUcgmH CLb/DmEp2BBb/0eVkPB+3gf0yzndRtiuzL8rGyIclqtvWgmM484fH/FFHIJDom2ry48K d4Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gVeHG8XX; 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 t12si17840490edc.33.2021.06.08.04.03.03; Tue, 08 Jun 2021 04:03: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=@redhat.com header.s=mimecast20190719 header.b=gVeHG8XX; 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 S231488AbhFHLEC (ORCPT + 99 others); Tue, 8 Jun 2021 07:04:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:45969 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231435AbhFHLEA (ORCPT ); Tue, 8 Jun 2021 07:04:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623150127; 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=LH+kGGXvul4/VtBvp8swcElDLFMoCOqrADXXWgo8nOs=; b=gVeHG8XXgfKJ1ayNAf2VUgL4KsZUCHxD8a8RZLyzNYraPeFXq9S/AxnoXOkSrto6EfvCdc SikPkf5xvKlx6L3tbj7JLMgeI1d7crkOmcrDD+trVBczhgpEkp9yFttubdriC634jc6zsr GH00Qdc0i8lHlOtCQy7kM6GMGglPnnE= Received: from mail-yb1-f198.google.com (mail-yb1-f198.google.com [209.85.219.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-514-UhgayfVnMvK1ZeZa4o-5AQ-1; Tue, 08 Jun 2021 07:02:06 -0400 X-MC-Unique: UhgayfVnMvK1ZeZa4o-5AQ-1 Received: by mail-yb1-f198.google.com with SMTP id n129-20020a2527870000b02904ed02e1aab5so26361646ybn.21 for ; Tue, 08 Jun 2021 04:02:06 -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=LH+kGGXvul4/VtBvp8swcElDLFMoCOqrADXXWgo8nOs=; b=Jwk8pqyPt/3zikpsry7CSAas4pdvMVfMNxazNexPUo6ZDu+w/gv/EKZiDackba/FT5 rLleki/HC0CfkUPlVS+wJfgfqMnRNa5HhFoG3cF/cGnw/MBhei5O5K121Jm9dGBBArq2 mx41vtQpgbFIhRWr4r6i+gN+A8PPmXl+2mUXcbGCVX63uH3SDWmZw0inczop/im3xjxe f7gW+a5C61APK3ZgB7YLcY1LHXt5NAyChp4MszhQsMcLqdvLSk+VDsp3WfnMbXEUD+qb qVlPlOQoCz7QhoIIo6ogqvQZ4/iHo3yw/39+kHUcgDnme5V8w+eR5u1STpvMXKhSVG0w RZUg== X-Gm-Message-State: AOAM531FabnLNClFNJm2rHj+6rexX8OzUitTSRTscLdEAP9zoXulMoLS qfnzKbtiKzFFAnEgn+2E3sisVZcappDbFpX7ea8s20xDDFY9AEHgnpkLyAYdm94Tz8a8204hmCj HjMsCNyMEC7bl+ZtJ8rYFZkTyIABJHxu0kci10q67 X-Received: by 2002:a25:a289:: with SMTP id c9mr32424317ybi.26.1623150125802; Tue, 08 Jun 2021 04:02:05 -0700 (PDT) X-Received: by 2002:a25:a289:: with SMTP id c9mr32424289ybi.26.1623150125563; Tue, 08 Jun 2021 04:02:05 -0700 (PDT) MIME-Version: 1.0 References: <20210517092006.803332-1-omosnace@redhat.com> In-Reply-To: From: Ondrej Mosnacek Date: Tue, 8 Jun 2021 13:01:54 +0200 Message-ID: Subject: Re: [PATCH v2] lockdown,selinux: avoid bogus SELinux lockdown permission checks To: Paul Moore Cc: Linux Security Module list , James Morris , Steven Rostedt , Ingo Molnar , Stephen Smalley , SElinux list , linuxppc-dev@lists.ozlabs.org, Linux FS Devel , bpf , network dev , Linux kernel mailing list , Casey Schaufler , Michael Ellerman Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 3, 2021 at 7:46 PM Paul Moore wrote: > On Wed, Jun 2, 2021 at 9:40 AM Ondrej Mosnacek wrote: > > On Fri, May 28, 2021 at 3:37 AM Paul Moore wrote: [...] > > > I know you and Casey went back and forth on this in v1, but I agree > > > with Casey that having two LSM hooks here is a mistake. I know it > > > makes backports hard, but spoiler alert: maintaining complex software > > > over any non-trivial period of time is hard, reeeeally hard sometimes > > > ;) > > > > Do you mean having two slots in lsm_hook_defs.h or also having two > > security_*() functions? (It's not clear to me if you're just > > reiterating disagreement with v1 or if you dislike the simplified v2 > > as well.) > > To be clear I don't think there should be two functions for this, just > make whatever changes are necessary to the existing > security_locked_down() LSM hook. Yes, the backport is hard. Yes, it > will touch a lot of code. Yes, those are lame excuses to not do the > right thing. OK, I guess I'll just go with the bigger patch. > > > > The callers migrated to the new hook, passing NULL as cred: > > > > 1. arch/powerpc/xmon/xmon.c > > > > Here the hook seems to be called from non-task context and is only > > > > used for redacting some sensitive values from output sent to > > > > userspace. > > > > > > 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)? > > You did submit the code change so I assumed you weren't concerned > about it :) If it is a bad hook placement that is something else > entirely. What I submitted effectively avoided the SELinux hook to be called, so I didn't bother checking deeper in what context those hook calls would occur. > Hopefully we'll get some guidance from the PPC folks. > > > > > 4. 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. > > > > > > If the task context is relevant we should use it. > > > > Yes, but as I said it would create an asymmetry with case b), which > > I'll expand on below... > > > > > > b) When deleting an SA via XFRM_MSG_DELSA, the dumped SAs are > > > > broadcasted to tasks subscribed to XFRM events - here the > > > > SELinux check is not meningful as the current task's creds do > > > > not represent the tasks that could potentially see the secret. > > > > > > This looks very similar to the BPF hook discussed above, I believe my > > > comments above apply here as well. > > > > Using the current task is just logically wrong in this case. The > > current task here is just simply deleting an SA that happens to have > > some secret value in it. When deleting an SA, a notification is sent > > to a group of subscribers (some group of other tasks), which includes > > a dump of the secret value. The current task isn't doing any attempt > > to breach lockdown, it's just deleting an SA. > > > > It also makes it really awkward to make policy decisions around this. > > Suppose that domains A, B, and C need to be able to add/delete SAs and > > domains D, E, and F need to receive notifications about changes in > > SAs. Then if, say, domain E actually needs to see the secret values in > > the notifications, you must grant the confidentiality permission to > > all of A, B, C to keep things working. And now you have opened up the > > door for A, B, C to do other lockdown-confidentiality stuff, even > > though these domains themselves actually don't request/need any > > confidential data from the kernel. That's just not logical and you may > > actually end up (slightly) worse security-wise than if you just > > skipped checking for XFRM secrets altogether, because you need to > > allow confidentiality to domains for which it may be excessive. > > It sounds an awful lot like the lockdown hook is in the wrong spot. > It sounds like it would be a lot better to relocate the hook than > remove it. I don't see how you would solve this by moving the hook. Where do you want to relocate it? The main obstacle is that the message containing the SA dump is sent to consumers via a simple netlink broadcast, which doesn't provide a facility to redact the SA secret on a per-consumer basis. I can't see any way to make the checks meaningful for SELinux without a major overhaul of the broadcast logic. IMO, switching the subject to kernel_t either in both cases or at least in case b) is the best compromise between usability, security, and developers' time / code complexity. I don't think controlling which of the CAP_NET_ADMIN domains can/can't see/leak SA secrets is worth obsessing about. -- Ondrej Mosnacek Software Engineer, Linux Security - SELinux kernel Red Hat, Inc.