|
@@ -173,6 +173,13 @@ extern int no_unaligned_warning;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#ifdef CONFIG_PROC_SYSCTL
|
|
#ifdef CONFIG_PROC_SYSCTL
|
|
|
|
+
|
|
|
|
+#define SYSCTL_WRITES_LEGACY -1
|
|
|
|
+#define SYSCTL_WRITES_WARN 0
|
|
|
|
+#define SYSCTL_WRITES_STRICT 1
|
|
|
|
+
|
|
|
|
+static int sysctl_writes_strict = SYSCTL_WRITES_WARN;
|
|
|
|
+
|
|
static int proc_do_cad_pid(struct ctl_table *table, int write,
|
|
static int proc_do_cad_pid(struct ctl_table *table, int write,
|
|
void __user *buffer, size_t *lenp, loff_t *ppos);
|
|
void __user *buffer, size_t *lenp, loff_t *ppos);
|
|
static int proc_taint(struct ctl_table *table, int write,
|
|
static int proc_taint(struct ctl_table *table, int write,
|
|
@@ -495,6 +502,15 @@ static struct ctl_table kern_table[] = {
|
|
.mode = 0644,
|
|
.mode = 0644,
|
|
.proc_handler = proc_taint,
|
|
.proc_handler = proc_taint,
|
|
},
|
|
},
|
|
|
|
+ {
|
|
|
|
+ .procname = "sysctl_writes_strict",
|
|
|
|
+ .data = &sysctl_writes_strict,
|
|
|
|
+ .maxlen = sizeof(int),
|
|
|
|
+ .mode = 0644,
|
|
|
|
+ .proc_handler = proc_dointvec_minmax,
|
|
|
|
+ .extra1 = &neg_one,
|
|
|
|
+ .extra2 = &one,
|
|
|
|
+ },
|
|
#endif
|
|
#endif
|
|
#ifdef CONFIG_LATENCYTOP
|
|
#ifdef CONFIG_LATENCYTOP
|
|
{
|
|
{
|
|
@@ -1717,8 +1733,20 @@ static int _proc_do_string(char *data, int maxlen, int write,
|
|
}
|
|
}
|
|
|
|
|
|
if (write) {
|
|
if (write) {
|
|
- /* Start writing from beginning of buffer. */
|
|
|
|
- len = 0;
|
|
|
|
|
|
+ if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
|
|
|
|
+ /* Only continue writes not past the end of buffer. */
|
|
|
|
+ len = strlen(data);
|
|
|
|
+ if (len > maxlen - 1)
|
|
|
|
+ len = maxlen - 1;
|
|
|
|
+
|
|
|
|
+ if (*ppos > len)
|
|
|
|
+ return 0;
|
|
|
|
+ len = *ppos;
|
|
|
|
+ } else {
|
|
|
|
+ /* Start writing from beginning of buffer. */
|
|
|
|
+ len = 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
*ppos += *lenp;
|
|
*ppos += *lenp;
|
|
p = buffer;
|
|
p = buffer;
|
|
while ((p - buffer) < *lenp && len < maxlen - 1) {
|
|
while ((p - buffer) < *lenp && len < maxlen - 1) {
|
|
@@ -1758,6 +1786,14 @@ static int _proc_do_string(char *data, int maxlen, int write,
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static void warn_sysctl_write(struct ctl_table *table)
|
|
|
|
+{
|
|
|
|
+ pr_warn_once("%s wrote to %s when file position was not 0!\n"
|
|
|
|
+ "This will not be supported in the future. To silence this\n"
|
|
|
|
+ "warning, set kernel.sysctl_writes_strict = -1\n",
|
|
|
|
+ current->comm, table->procname);
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* proc_dostring - read a string sysctl
|
|
* proc_dostring - read a string sysctl
|
|
* @table: the sysctl table
|
|
* @table: the sysctl table
|
|
@@ -1778,6 +1814,9 @@ static int _proc_do_string(char *data, int maxlen, int write,
|
|
int proc_dostring(struct ctl_table *table, int write,
|
|
int proc_dostring(struct ctl_table *table, int write,
|
|
void __user *buffer, size_t *lenp, loff_t *ppos)
|
|
void __user *buffer, size_t *lenp, loff_t *ppos)
|
|
{
|
|
{
|
|
|
|
+ if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
|
|
|
|
+ warn_sysctl_write(table);
|
|
|
|
+
|
|
return _proc_do_string((char *)(table->data), table->maxlen, write,
|
|
return _proc_do_string((char *)(table->data), table->maxlen, write,
|
|
(char __user *)buffer, lenp, ppos);
|
|
(char __user *)buffer, lenp, ppos);
|
|
}
|
|
}
|
|
@@ -1953,6 +1992,18 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
|
|
conv = do_proc_dointvec_conv;
|
|
conv = do_proc_dointvec_conv;
|
|
|
|
|
|
if (write) {
|
|
if (write) {
|
|
|
|
+ if (*ppos) {
|
|
|
|
+ switch (sysctl_writes_strict) {
|
|
|
|
+ case SYSCTL_WRITES_STRICT:
|
|
|
|
+ goto out;
|
|
|
|
+ case SYSCTL_WRITES_WARN:
|
|
|
|
+ warn_sysctl_write(table);
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
if (left > PAGE_SIZE - 1)
|
|
if (left > PAGE_SIZE - 1)
|
|
left = PAGE_SIZE - 1;
|
|
left = PAGE_SIZE - 1;
|
|
page = __get_free_page(GFP_TEMPORARY);
|
|
page = __get_free_page(GFP_TEMPORARY);
|
|
@@ -2010,6 +2061,7 @@ free:
|
|
return err ? : -EINVAL;
|
|
return err ? : -EINVAL;
|
|
}
|
|
}
|
|
*lenp -= left;
|
|
*lenp -= left;
|
|
|
|
+out:
|
|
*ppos += *lenp;
|
|
*ppos += *lenp;
|
|
return err;
|
|
return err;
|
|
}
|
|
}
|
|
@@ -2202,6 +2254,18 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
|
|
left = *lenp;
|
|
left = *lenp;
|
|
|
|
|
|
if (write) {
|
|
if (write) {
|
|
|
|
+ if (*ppos) {
|
|
|
|
+ switch (sysctl_writes_strict) {
|
|
|
|
+ case SYSCTL_WRITES_STRICT:
|
|
|
|
+ goto out;
|
|
|
|
+ case SYSCTL_WRITES_WARN:
|
|
|
|
+ warn_sysctl_write(table);
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
if (left > PAGE_SIZE - 1)
|
|
if (left > PAGE_SIZE - 1)
|
|
left = PAGE_SIZE - 1;
|
|
left = PAGE_SIZE - 1;
|
|
page = __get_free_page(GFP_TEMPORARY);
|
|
page = __get_free_page(GFP_TEMPORARY);
|
|
@@ -2257,6 +2321,7 @@ free:
|
|
return err ? : -EINVAL;
|
|
return err ? : -EINVAL;
|
|
}
|
|
}
|
|
*lenp -= left;
|
|
*lenp -= left;
|
|
|
|
+out:
|
|
*ppos += *lenp;
|
|
*ppos += *lenp;
|
|
return err;
|
|
return err;
|
|
}
|
|
}
|