Skip to content

Commit 942b296

Browse files
committed
sysctl: Move tainted ctl_table into kernel/panic.c
Move the ctl_table with the "tainted" proc_name into kernel/panic.c. With it moves the proc_tainted helper function. 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 79ac8df commit 942b296

File tree

2 files changed

+50
-49
lines changed

2 files changed

+50
-49
lines changed

kernel/panic.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,50 @@ ATOMIC_NOTIFIER_HEAD(panic_notifier_list);
8484
EXPORT_SYMBOL(panic_notifier_list);
8585

8686
#ifdef CONFIG_SYSCTL
87+
88+
/*
89+
* Taint values can only be increased
90+
* This means we can safely use a temporary.
91+
*/
92+
static int proc_taint(const struct ctl_table *table, int write,
93+
void *buffer, size_t *lenp, loff_t *ppos)
94+
{
95+
struct ctl_table t;
96+
unsigned long tmptaint = get_taint();
97+
int err;
98+
99+
if (write && !capable(CAP_SYS_ADMIN))
100+
return -EPERM;
101+
102+
t = *table;
103+
t.data = &tmptaint;
104+
err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
105+
if (err < 0)
106+
return err;
107+
108+
if (write) {
109+
int i;
110+
111+
/*
112+
* If we are relying on panic_on_taint not producing
113+
* false positives due to userspace input, bail out
114+
* before setting the requested taint flags.
115+
*/
116+
if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
117+
return -EINVAL;
118+
119+
/*
120+
* Poor man's atomic or. Not worth adding a primitive
121+
* to everyone's atomic.h for this
122+
*/
123+
for (i = 0; i < TAINT_FLAGS_COUNT; i++)
124+
if ((1UL << i) & tmptaint)
125+
add_taint(i, LOCKDEP_STILL_OK);
126+
}
127+
128+
return err;
129+
}
130+
87131
static const struct ctl_table kern_panic_table[] = {
88132
#ifdef CONFIG_SMP
89133
{
@@ -96,6 +140,12 @@ static const struct ctl_table kern_panic_table[] = {
96140
.extra2 = SYSCTL_ONE,
97141
},
98142
#endif
143+
{
144+
.procname = "tainted",
145+
.maxlen = sizeof(long),
146+
.mode = 0644,
147+
.proc_handler = proc_taint,
148+
},
99149
{
100150
.procname = "panic",
101151
.data = &panic_timeout,

kernel/sysctl.c

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -731,49 +731,6 @@ int proc_douintvec(const struct ctl_table *table, int write, void *buffer,
731731
do_proc_douintvec_conv, NULL);
732732
}
733733

734-
/*
735-
* Taint values can only be increased
736-
* This means we can safely use a temporary.
737-
*/
738-
static int proc_taint(const struct ctl_table *table, int write,
739-
void *buffer, size_t *lenp, loff_t *ppos)
740-
{
741-
struct ctl_table t;
742-
unsigned long tmptaint = get_taint();
743-
int err;
744-
745-
if (write && !capable(CAP_SYS_ADMIN))
746-
return -EPERM;
747-
748-
t = *table;
749-
t.data = &tmptaint;
750-
err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
751-
if (err < 0)
752-
return err;
753-
754-
if (write) {
755-
int i;
756-
757-
/*
758-
* If we are relying on panic_on_taint not producing
759-
* false positives due to userspace input, bail out
760-
* before setting the requested taint flags.
761-
*/
762-
if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
763-
return -EINVAL;
764-
765-
/*
766-
* Poor man's atomic or. Not worth adding a primitive
767-
* to everyone's atomic.h for this
768-
*/
769-
for (i = 0; i < TAINT_FLAGS_COUNT; i++)
770-
if ((1UL << i) & tmptaint)
771-
add_taint(i, LOCKDEP_STILL_OK);
772-
}
773-
774-
return err;
775-
}
776-
777734
/**
778735
* struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
779736
* @min: pointer to minimum allowable value
@@ -1557,12 +1514,6 @@ int proc_do_static_key(const struct ctl_table *table, int write,
15571514

15581515
static const struct ctl_table kern_table[] = {
15591516
#ifdef CONFIG_PROC_SYSCTL
1560-
{
1561-
.procname = "tainted",
1562-
.maxlen = sizeof(long),
1563-
.mode = 0644,
1564-
.proc_handler = proc_taint,
1565-
},
15661517
{
15671518
.procname = "sysctl_writes_strict",
15681519
.data = &sysctl_writes_strict,

0 commit comments

Comments
 (0)