Skip to content

Commit 890ed45

Browse files
committed
acct: block access to kernel internal filesystems
There's no point in allowing anything kernel internal nor procfs or sysfs. Link: https://lore.kernel.org/r/20250127091811.3183623-1-quzicheng@huawei.com Link: https://lore.kernel.org/r/20250211-work-acct-v1-2-1c16aecab8b3@kernel.org Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reviewed-by: Amir Goldstein <amir73il@gmail.com> Reported-by: Zicheng Qu <quzicheng@huawei.com> Cc: stable@vger.kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 56d5f3e commit 890ed45

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

kernel/acct.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,20 @@ static int acct_on(struct filename *pathname)
243243
return -EACCES;
244244
}
245245

246+
/* Exclude kernel kernel internal filesystems. */
247+
if (file_inode(file)->i_sb->s_flags & (SB_NOUSER | SB_KERNMOUNT)) {
248+
kfree(acct);
249+
filp_close(file, NULL);
250+
return -EINVAL;
251+
}
252+
253+
/* Exclude procfs and sysfs. */
254+
if (file_inode(file)->i_sb->s_iflags & SB_I_USERNS_VISIBLE) {
255+
kfree(acct);
256+
filp_close(file, NULL);
257+
return -EINVAL;
258+
}
259+
246260
if (!(file->f_mode & FMODE_CAN_WRITE)) {
247261
kfree(acct);
248262
filp_close(file, NULL);

0 commit comments

Comments
 (0)