提交 d013db02 编写于 作者: T Tyler Hicks 提交者: Paul Moore

seccomp: Separate read and write code for actions_logged sysctl

Break the read and write paths of the kernel.seccomp.actions_logged
sysctl into separate functions to maintain readability. An upcoming
change will need to audit writes, but not reads, of this sysctl which
would introduce too many conditional code paths on whether or not the
'write' parameter evaluates to true.
Signed-off-by: NTyler Hicks <tyhicks@canonical.com>
Acked-by: NKees Cook <keescook@chromium.org>
Signed-off-by: NPaul Moore <paul@paul-moore.com>
上级 23bcc480
...@@ -1199,48 +1199,64 @@ static bool seccomp_actions_logged_from_names(u32 *actions_logged, char *names) ...@@ -1199,48 +1199,64 @@ static bool seccomp_actions_logged_from_names(u32 *actions_logged, char *names)
return true; return true;
} }
static int seccomp_actions_logged_handler(struct ctl_table *ro_table, int write, static int read_actions_logged(struct ctl_table *ro_table, void __user *buffer,
void __user *buffer, size_t *lenp, size_t *lenp, loff_t *ppos)
loff_t *ppos)
{ {
char names[sizeof(seccomp_actions_avail)]; char names[sizeof(seccomp_actions_avail)];
struct ctl_table table; struct ctl_table table;
int ret;
if (write && !capable(CAP_SYS_ADMIN))
return -EPERM;
memset(names, 0, sizeof(names)); memset(names, 0, sizeof(names));
if (!write) {
if (!seccomp_names_from_actions_logged(names, sizeof(names), if (!seccomp_names_from_actions_logged(names, sizeof(names),
seccomp_actions_logged)) seccomp_actions_logged))
return -EINVAL; return -EINVAL;
}
table = *ro_table; table = *ro_table;
table.data = names; table.data = names;
table.maxlen = sizeof(names); table.maxlen = sizeof(names);
ret = proc_dostring(&table, write, buffer, lenp, ppos); return proc_dostring(&table, 0, buffer, lenp, ppos);
if (ret) }
return ret;
if (write) { static int write_actions_logged(struct ctl_table *ro_table, void __user *buffer,
size_t *lenp, loff_t *ppos)
{
char names[sizeof(seccomp_actions_avail)];
struct ctl_table table;
u32 actions_logged; u32 actions_logged;
int ret;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
if (!seccomp_actions_logged_from_names(&actions_logged, memset(names, 0, sizeof(names));
table.data))
table = *ro_table;
table.data = names;
table.maxlen = sizeof(names);
ret = proc_dostring(&table, 1, buffer, lenp, ppos);
if (ret)
return ret;
if (!seccomp_actions_logged_from_names(&actions_logged, table.data))
return -EINVAL; return -EINVAL;
if (actions_logged & SECCOMP_LOG_ALLOW) if (actions_logged & SECCOMP_LOG_ALLOW)
return -EINVAL; return -EINVAL;
seccomp_actions_logged = actions_logged; seccomp_actions_logged = actions_logged;
}
return 0; return 0;
} }
static int seccomp_actions_logged_handler(struct ctl_table *ro_table, int write,
void __user *buffer, size_t *lenp,
loff_t *ppos)
{
if (write)
return write_actions_logged(ro_table, buffer, lenp, ppos);
else
return read_actions_logged(ro_table, buffer, lenp, ppos);
}
static struct ctl_path seccomp_sysctl_path[] = { static struct ctl_path seccomp_sysctl_path[] = {
{ .procname = "kernel", }, { .procname = "kernel", },
{ .procname = "seccomp", }, { .procname = "seccomp", },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册