Skip to content

Commit d013db0

Browse files
tyhickspcmoore
authored andcommitted
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: Tyler Hicks <tyhicks@canonical.com> Acked-by: Kees Cook <keescook@chromium.org> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 23bcc48 commit d013db0

1 file changed

Lines changed: 38 additions & 22 deletions

File tree

‎kernel/seccomp.c‎

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,48 +1199,64 @@ static bool seccomp_actions_logged_from_names(u32 *actions_logged, char *names)
11991199
return true;
12001200
}
12011201

1202-
static int seccomp_actions_logged_handler(struct ctl_table *ro_table, int write,
1203-
void __user *buffer, size_t *lenp,
1204-
loff_t *ppos)
1202+
static int read_actions_logged(struct ctl_table *ro_table, void __user *buffer,
1203+
size_t *lenp, loff_t *ppos)
12051204
{
12061205
char names[sizeof(seccomp_actions_avail)];
12071206
struct ctl_table table;
1207+
1208+
memset(names, 0, sizeof(names));
1209+
1210+
if (!seccomp_names_from_actions_logged(names, sizeof(names),
1211+
seccomp_actions_logged))
1212+
return -EINVAL;
1213+
1214+
table = *ro_table;
1215+
table.data = names;
1216+
table.maxlen = sizeof(names);
1217+
return proc_dostring(&table, 0, buffer, lenp, ppos);
1218+
}
1219+
1220+
static int write_actions_logged(struct ctl_table *ro_table, void __user *buffer,
1221+
size_t *lenp, loff_t *ppos)
1222+
{
1223+
char names[sizeof(seccomp_actions_avail)];
1224+
struct ctl_table table;
1225+
u32 actions_logged;
12081226
int ret;
12091227

1210-
if (write && !capable(CAP_SYS_ADMIN))
1228+
if (!capable(CAP_SYS_ADMIN))
12111229
return -EPERM;
12121230

12131231
memset(names, 0, sizeof(names));
12141232

1215-
if (!write) {
1216-
if (!seccomp_names_from_actions_logged(names, sizeof(names),
1217-
seccomp_actions_logged))
1218-
return -EINVAL;
1219-
}
1220-
12211233
table = *ro_table;
12221234
table.data = names;
12231235
table.maxlen = sizeof(names);
1224-
ret = proc_dostring(&table, write, buffer, lenp, ppos);
1236+
ret = proc_dostring(&table, 1, buffer, lenp, ppos);
12251237
if (ret)
12261238
return ret;
12271239

1228-
if (write) {
1229-
u32 actions_logged;
1230-
1231-
if (!seccomp_actions_logged_from_names(&actions_logged,
1232-
table.data))
1233-
return -EINVAL;
1234-
1235-
if (actions_logged & SECCOMP_LOG_ALLOW)
1236-
return -EINVAL;
1240+
if (!seccomp_actions_logged_from_names(&actions_logged, table.data))
1241+
return -EINVAL;
12371242

1238-
seccomp_actions_logged = actions_logged;
1239-
}
1243+
if (actions_logged & SECCOMP_LOG_ALLOW)
1244+
return -EINVAL;
12401245

1246+
seccomp_actions_logged = actions_logged;
12411247
return 0;
12421248
}
12431249

1250+
static int seccomp_actions_logged_handler(struct ctl_table *ro_table, int write,
1251+
void __user *buffer, size_t *lenp,
1252+
loff_t *ppos)
1253+
{
1254+
if (write)
1255+
return write_actions_logged(ro_table, buffer, lenp, ppos);
1256+
else
1257+
return read_actions_logged(ro_table, buffer, lenp, ppos);
1258+
}
1259+
12441260
static struct ctl_path seccomp_sysctl_path[] = {
12451261
{ .procname = "kernel", },
12461262
{ .procname = "seccomp", },

0 commit comments

Comments
 (0)