From: Christian Brauner <brauner@kernel.org>
To: Zicheng Qu <quzicheng@huawei.com>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: Christian Brauner <brauner@kernel.org>,
jlayton@kernel.org, axboe@kernel.dk, joel.granados@kernel.org,
tglx@linutronix.de, viro@zeniv.linux.org.uk, hch@lst.de,
len.brown@intel.com, pavel@ucw.cz, pengfei.xu@intel.com,
rafael@kernel.org, tanghui20@huawei.com, zhangqiao22@huawei.com,
judy.chenhui@huawei.com, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org, syzkaller-bugs@googlegroups.com,
linux-pm@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH 2/2] acct: block access to kernel internal filesystems
Date: Tue, 11 Feb 2025 18:16:00 +0100 [thread overview]
Message-ID: <20250211-work-acct-v1-2-1c16aecab8b3@kernel.org> (raw)
In-Reply-To: <20250211-work-acct-v1-0-1c16aecab8b3@kernel.org>
There's no point in allowing anything kernel internal nor procfs or
sysfs.
Reported-by: Zicheng Qu <quzicheng@huawei.com>
Link: https://lore.kernel.org/r/20250127091811.3183623-1-quzicheng@huawei.com
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: <stable@vger.kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
kernel/acct.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/kernel/acct.c b/kernel/acct.c
index 48283efe8a12..6520baa13669 100644
--- a/kernel/acct.c
+++ b/kernel/acct.c
@@ -243,6 +243,20 @@ static int acct_on(struct filename *pathname)
return -EACCES;
}
+ /* Exclude kernel kernel internal filesystems. */
+ if (file_inode(file)->i_sb->s_flags & (SB_NOUSER | SB_KERNMOUNT)) {
+ kfree(acct);
+ filp_close(file, NULL);
+ return -EINVAL;
+ }
+
+ /* Exclude procfs and sysfs. */
+ if (file_inode(file)->i_sb->s_iflags & SB_I_USERNS_VISIBLE) {
+ kfree(acct);
+ filp_close(file, NULL);
+ return -EINVAL;
+ }
+
if (!(file->f_mode & FMODE_CAN_WRITE)) {
kfree(acct);
filp_close(file, NULL);
--
2.47.2
next prev parent reply other threads:[~2025-02-11 17:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20250210-unordnung-petersilie-90e37411db18@brauner>
2025-02-11 17:15 ` [PATCH 0/2] acct: don't allow access to internal filesystems Christian Brauner
2025-02-11 17:15 ` [PATCH 1/2] acct: perform last write from workqueue Christian Brauner
2025-02-11 17:16 ` Christian Brauner [this message]
2025-02-11 20:30 ` [PATCH 2/2] acct: block access to kernel internal filesystems Amir Goldstein
2025-02-11 20:54 ` Al Viro
2025-02-12 10:32 ` Christian Brauner
2025-02-11 18:56 ` [PATCH 0/2] acct: don't allow access to " Jeff Layton
2025-02-12 11:16 ` Christian Brauner
2025-02-13 14:56 ` Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250211-work-acct-v1-2-1c16aecab8b3@kernel.org \
--to=brauner@kernel.org \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=jlayton@kernel.org \
--cc=joel.granados@kernel.org \
--cc=judy.chenhui@huawei.com \
--cc=len.brown@intel.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=pengfei.xu@intel.com \
--cc=quzicheng@huawei.com \
--cc=rafael@kernel.org \
--cc=stable@vger.kernel.org \
--cc=syzkaller-bugs@googlegroups.com \
--cc=tanghui20@huawei.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
--cc=zhangqiao22@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).