Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2599119pxb; Tue, 13 Apr 2021 06:00:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSCn0gQSfQi+1zLL8CLCnTJm5ZaHt+d5511eUGpMd7kX2+/mhpSxtjbA0D75zdnkjoiAyg X-Received: by 2002:a17:902:6949:b029:e8:c22d:17ae with SMTP id k9-20020a1709026949b02900e8c22d17aemr31008727plt.57.1618318800399; Tue, 13 Apr 2021 06:00:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618318800; cv=none; d=google.com; s=arc-20160816; b=YP8XJPWNJ1SFagmTh7l2Xr3UTgY2yHHp0Ihi9bN/V/6ouSzL3Icx6JhsuvUxEU3FK6 36K5DIacOHhFy//6PJ2SHiWgsEGawMbhYeRTRZjHaaioatoD+SMNZaW2IJl7WNhED9sI Bbb7wyuVZdlLy8l/A+uIsPxSHbf4KyKWdEq76DqnNspIT8Yiikt2R5NNNc74migi3DIt 6c8PRJdLXN8Eimfosvn97oiwgYS2z0qGItZFt5pINjf8bdDI3X87edaLXryH77Ta2Y/V 6Mct2kKqJSAg4f6mVSC8PhriiCbbONmIz90oOAypAyY9v6lgUGXcq1qM+nvjdcbkYu1d Uq2A== 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=KLyUzT5M5en0X4VIingKMBNaeYaSW+6rovobSSA9k74=; b=CoO1TC91nmxINKwzHhIrbHQR9VAgRZz6PZ/LsDp42HfEcRVjFAl0gqyLLcn3jzcBeR eNs2Ui8M4pq3t6yuA4q9EoxmRgMyURVsQuR8KKO8WOkFCVHmXfcpVzoJcaCf9ZVvNarW cVlEMVuiYly0/1UnpcEZ/idW/FB0vl0Q5ihReKcbjjMhkhMIcPbLOiz9jbCrqVkp56+e AMsX1hHAa21gdK64T5JJgin1PaIb0VCtKMde1Q55oMovLIc2FA7Z5PHJk1MaYk5+R7zl +GAgAL0+mP4csNSxJffObcCFLx/rrLL7Xa4+85gURVj7Ix2NIC1h7ZVpmj0RxW91Jabx aSAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Z+eQwLmJ; 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 y5si3590317pjp.126.2021.04.13.05.59.48; Tue, 13 Apr 2021 06:00:00 -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=Z+eQwLmJ; 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 S241607AbhDMINo (ORCPT + 99 others); Tue, 13 Apr 2021 04:13:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29140 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240786AbhDMINl (ORCPT ); Tue, 13 Apr 2021 04:13:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618301599; 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=KLyUzT5M5en0X4VIingKMBNaeYaSW+6rovobSSA9k74=; b=Z+eQwLmJH1wz9V3zvCulWMMFSTbzWCgT/QlvLMuqKMaThP5yU6AcT4WFZIyUAj42xF7ZEO DmjGXxxo1+N++bDORuiYc+1Frw6cKKsPTuUs2xiWveSvyqwtwrNz33WaqFf3nWgsLQ9wEx U/wAxph/ydqUBgaL+dc4ARruG555fUs= 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-303-FhJlnQLNPWWZgwwqOTAIxg-1; Tue, 13 Apr 2021 04:13:18 -0400 X-MC-Unique: FhJlnQLNPWWZgwwqOTAIxg-1 Received: by mail-yb1-f200.google.com with SMTP id k199so12714060ybf.0 for ; Tue, 13 Apr 2021 01:13:18 -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=KLyUzT5M5en0X4VIingKMBNaeYaSW+6rovobSSA9k74=; b=Tp6ArC7qbjVKUdMJHE1+FaHUdTu5Ci1XP8ToopIW4YGNWSjF9uLDAPuxntmWO9wcWT 2zjKb/hrga/FLmZKyNKOIUZaBF+V2ZO06ew+l37XUgFxQpBwc6NO4r8B9J3Mu1EBLErQ IR0lNP3GJfHWBixHNgTqyI3nErN4QMcMZvprqKlbzqh6aERaQLH9JecOAJOfKrU0l8dT 3bHBzKHMVN9DT7qWstvwWzxvtNHn9NX5v6kB1czzl0vDHEutonXecIVGJYIv/52PhWHi RwKC+4596GniROiqlLYQ22pVfp7F5V1+c2S36SgSzfVmDLcz+CTSIWtaPpToR06Ne68A gx+A== X-Gm-Message-State: AOAM533R0PJ/q60Tw0jXajzyZMNH/HE2KyfZlAGudlXWnOCluCvdvQBf ha79dlqQRUpJ3NoXAksUmL7Vk3lu7tJz4IKK6n2qJ2S4FP+tpHdrCns9ITT0gyEyl8cfx9veY9u yTfIAMveCdOSpareX0eZL6PaX69PDEUtwMhSLgWhA X-Received: by 2002:a25:ce09:: with SMTP id x9mr7099183ybe.81.1618301597499; Tue, 13 Apr 2021 01:13:17 -0700 (PDT) X-Received: by 2002:a25:ce09:: with SMTP id x9mr7099155ybe.81.1618301597217; Tue, 13 Apr 2021 01:13:17 -0700 (PDT) MIME-Version: 1.0 References: <20191012005747.210722465@goodmis.org> <20191012005921.580293464@goodmis.org> In-Reply-To: <20191012005921.580293464@goodmis.org> From: Ondrej Mosnacek Date: Tue, 13 Apr 2021 10:13:04 +0200 Message-ID: Subject: Re: [PATCH 7/7 v2] tracing: Do not create tracefs files if tracefs lockdown is in effect To: Steven Rostedt Cc: Linux kernel mailing list , Linus Torvalds , Ingo Molnar , Andrew Morton , Matthew Garrett , James Morris James Morris , LSM List , Linux API , Ben Hutchings , Al Viro , Stephen Smalley , SElinux list , Herton Krzesinski Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Oct 12, 2019 at 2:59 AM Steven Rostedt wrote: > From: "Steven Rostedt (VMware)" > > If on boot up, lockdown is activated for tracefs, don't even bother creating > the files. This can also prevent instances from being created if lockdown is > in effect. > > Link: http://lkml.kernel.org/r/CAHk-=whC6Ji=fWnjh2+eS4b15TnbsS4VPVtvBOwCy1jjEG_JHQ@mail.gmail.com > > Suggested-by: Linus Torvalds > Signed-off-by: Steven Rostedt (VMware) > --- > fs/tracefs/inode.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c > index eeeae0475da9..0caa151cae4e 100644 > --- a/fs/tracefs/inode.c > +++ b/fs/tracefs/inode.c > @@ -16,6 +16,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -390,6 +391,9 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode, > struct dentry *dentry; > struct inode *inode; > > + if (security_locked_down(LOCKDOWN_TRACEFS)) > + return NULL; > + > if (!(mode & S_IFMT)) > mode |= S_IFREG; > BUG_ON(!S_ISREG(mode)); > -- > 2.23.0 Hi all, sorry for coming back to an old thread, but it turns out that this patch doesn't play well with SELinux's implementation of the security_locked_down() hook, which was added a few months later (so not your fault :) in commit 59438b46471a ("security,lockdown,selinux: implement SELinux lockdown"). What SELinux does is it checks if the current task's creds are allowed the lockdown::integrity or lockdown::confidentiality permission in the policy whenever security_locked_down() is called. The idea is to be able to control at SELinux domain level which tasks can do these sensitive operations (when the kernel is not actually locked down by the Lockdown LSM). With this patch + the SELinux lockdown mechanism in use, when a userspace task loads a module that creates some tracefs nodes in its initcall SELinux will check if the task has the lockdown::confidentiality permission and if not, will report denials in audit log and prevent the tracefs entries from being created. But that is not a very logical behavior, since the task loading the module is itself not (explicitly) doing anything that would breach confidentiality. It just indirectly causes some tracefs nodes to be created, but doesn't actually use them at that point. Since it seems the other patches also added security_locked_down() calls to the tracefs nodes' open functions, I guess reverting this patch could be an acceptable way to fix this problem (please correct me if there is something that this call catches, which the other ones don't). However, even then I can understand that you (or someone else) might want to keep this as an optimization, in which case we could instead do this: 1. Add a new hook security_locked_down_permanently() (the name is open for discussion), which would be intended for situations when we want to avoid doing some pointless work when the kernel is in a "hard" lockdown that can't be taken back (except perhaps in some rescue scenario...). 2. This hook would be backed by the same implementation as security_locked_down() in the Lockdown LSM and left unimplemented by SELinux. 3. tracefs_create_file() would call this hook instead of security_locked_down(). This way it would work as before relative to the standard lockdown via the Lockdown LSM and would be simply ignored by SELinux. I went over all the security_locked_down() call in the kernel and I think this alternative hook could also fit better in arch/powerpc/xmon/xmon.c, where it seems to be called from interrupt context (so task creds are irrelevant, anyway...) and mainly causes some values to be redacted. (I also found a couple minor issues with how the hook is used in other places, for which I plan to send patches later.) Thoughts? -- Ondrej Mosnacek Software Engineer, Linux Security - SELinux kernel Red Hat, Inc.