Skip to content

Commit e054bcb

Browse files
committed
sysctl: move cad_pid into kernel/pid.c
Move cad_pid as well as supporting function proc_do_cad_pid into kernel/pic.c. Replaced call to __do_proc_dointvec with proc_dointvec inside proc_do_cad_pid which requires the copy of the ctl_table to handle the temp value. This is part of a greater effort to move ctl tables into their respective subsystems which will reduce the merge conflicts in kernel/sysctl.c. Reviewed-by: Luis Chamberlain <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Joel Granados <[email protected]>
1 parent 942b296 commit e054bcb

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

kernel/pid.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,29 @@ static struct ctl_table_root pid_table_root = {
713713
.set_ownership = pid_table_root_set_ownership,
714714
};
715715

716+
static int proc_do_cad_pid(const struct ctl_table *table, int write, void *buffer,
717+
size_t *lenp, loff_t *ppos)
718+
{
719+
struct pid *new_pid;
720+
pid_t tmp_pid;
721+
int r;
722+
struct ctl_table tmp_table = *table;
723+
724+
tmp_pid = pid_vnr(cad_pid);
725+
tmp_table.data = &tmp_pid;
726+
727+
r = proc_dointvec(&tmp_table, write, buffer, lenp, ppos);
728+
if (r || !write)
729+
return r;
730+
731+
new_pid = find_get_pid(tmp_pid);
732+
if (!new_pid)
733+
return -ESRCH;
734+
735+
put_pid(xchg(&cad_pid, new_pid));
736+
return 0;
737+
}
738+
716739
static const struct ctl_table pid_table[] = {
717740
{
718741
.procname = "pid_max",
@@ -723,6 +746,14 @@ static const struct ctl_table pid_table[] = {
723746
.extra1 = &pid_max_min,
724747
.extra2 = &pid_max_max,
725748
},
749+
#ifdef CONFIG_PROC_SYSCTL
750+
{
751+
.procname = "cad_pid",
752+
.maxlen = sizeof(int),
753+
.mode = 0600,
754+
.proc_handler = proc_do_cad_pid,
755+
},
756+
#endif
726757
};
727758
#endif
728759

kernel/sysctl.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,28 +1224,6 @@ int proc_dointvec_ms_jiffies(const struct ctl_table *table, int write, void *buf
12241224
do_proc_dointvec_ms_jiffies_conv, NULL);
12251225
}
12261226

1227-
static int proc_do_cad_pid(const struct ctl_table *table, int write, void *buffer,
1228-
size_t *lenp, loff_t *ppos)
1229-
{
1230-
struct pid *new_pid;
1231-
pid_t tmp;
1232-
int r;
1233-
1234-
tmp = pid_vnr(cad_pid);
1235-
1236-
r = __do_proc_dointvec(&tmp, table, write, buffer,
1237-
lenp, ppos, NULL, NULL);
1238-
if (r || !write)
1239-
return r;
1240-
1241-
new_pid = find_get_pid(tmp);
1242-
if (!new_pid)
1243-
return -ESRCH;
1244-
1245-
put_pid(xchg(&cad_pid, new_pid));
1246-
return 0;
1247-
}
1248-
12491227
/**
12501228
* proc_do_large_bitmap - read/write from/to a large bitmap
12511229
* @table: the sysctl table
@@ -1541,15 +1519,6 @@ static const struct ctl_table kern_table[] = {
15411519
.mode = 0644,
15421520
.proc_handler = proc_dostring,
15431521
},
1544-
#endif
1545-
#ifdef CONFIG_PROC_SYSCTL
1546-
{
1547-
.procname = "cad_pid",
1548-
.data = NULL,
1549-
.maxlen = sizeof (int),
1550-
.mode = 0600,
1551-
.proc_handler = proc_do_cad_pid,
1552-
},
15531522
#endif
15541523
{
15551524
.procname = "overflowuid",

0 commit comments

Comments
 (0)