From: menglong8.dong@gmail.com
To: mcgrof@kernel.org
Cc: keescook@chromium.org, yzaikin@google.com,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Yang Yang <yang.yang29@zte.com.cn>,
Zeal Robot <zealci@zte.com.cn>
Subject: [PATCH] sysctl: fix permission check while owner isn't GLOBAL_ROOT_UID
Date: Fri, 25 Jun 2021 01:33:38 -0700 [thread overview]
Message-ID: <20210625083338.384184-1-yang.yang29@zte.com.cn> (raw)
From: Yang Yang <yang.yang29@zte.com.cn>
With user namespace enabled, root in container can't modify
/proc/sys/net/ipv4/ip_forward. While /proc/sys/net/ipv4/ip_forward
belongs to root and mode is 644. Since root in container may
be non-root in host, but test_perm() doesn't consider about it.
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com.cn>
---
fs/proc/proc_sysctl.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index dea0f5ee540c..71d7b2c2c8e3 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -400,18 +400,19 @@ static void next_entry(struct ctl_table_header **phead, struct ctl_table **pentr
* some sysctl variables are readonly even to root.
*/
-static int test_perm(int mode, int op)
+static int test_perm(struct inode *inode, int mode, int op)
{
- if (uid_eq(current_euid(), GLOBAL_ROOT_UID))
+ if (uid_eq(current_euid(), inode->i_uid))
mode >>= 6;
- else if (in_egroup_p(GLOBAL_ROOT_GID))
+ else if (in_egroup_p(inode->i_gid))
mode >>= 3;
if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
return 0;
return -EACCES;
}
-static int sysctl_perm(struct ctl_table_header *head, struct ctl_table *table, int op)
+static int sysctl_perm(struct inode *inode,
+ struct ctl_table_header *head, struct ctl_table *table, int op)
{
struct ctl_table_root *root = head->root;
int mode;
@@ -421,7 +422,7 @@ static int sysctl_perm(struct ctl_table_header *head, struct ctl_table *table, i
else
mode = table->mode;
- return test_perm(mode, op);
+ return test_perm(inode, mode, op);
}
static struct inode *proc_sys_make_inode(struct super_block *sb,
@@ -554,7 +555,7 @@ static ssize_t proc_sys_call_handler(struct kiocb *iocb, struct iov_iter *iter,
* and won't be until we finish.
*/
error = -EPERM;
- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
+ if (sysctl_perm(inode, head, table, write ? MAY_WRITE : MAY_READ))
goto out;
/* if that can happen at all, it should be -EINVAL, not -EISDIR */
@@ -803,7 +804,7 @@ static int proc_sys_permission(struct user_namespace *mnt_userns,
if (!table) /* global root - r-xr-xr-x */
error = mask & MAY_WRITE ? -EACCES : 0;
else /* Use the permissions on the sysctl table entry */
- error = sysctl_perm(head, table, mask & ~MAY_NOT_BLOCK);
+ error = sysctl_perm(inode, head, table, mask & ~MAY_NOT_BLOCK);
sysctl_head_finish(head);
return error;
--
2.25.1
next reply other threads:[~2021-06-25 8:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-25 8:33 menglong8.dong [this message]
2021-06-28 12:17 ` Christian Brauner
[not found] ` <202106282114107052565@zte.com.cn>
2021-06-29 13:40 ` 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=20210625083338.384184-1-yang.yang29@zte.com.cn \
--to=menglong8.dong@gmail.com \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=yang.yang29@zte.com.cn \
--cc=yzaikin@google.com \
--cc=zealci@zte.com.cn \
/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
all inboxes | Powered by JetHome®