Skip to content

Commit fcc77d7

Browse files
committed
Merge tag 'sysctl-6.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux
Pull sysctl update from Luis Chamberlain: "Just one fix which just came in. Sadly the eager beavers willing to help with the sysctl moves have slowed" * tag 'sysctl-6.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux: sysctl: fix proc_dobool() usability
2 parents c538944 + f1aa2eb commit fcc77d7

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

fs/lockd/svc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ static struct ctl_table nlm_sysctls[] = {
496496
{
497497
.procname = "nsm_use_hostnames",
498498
.data = &nsm_use_hostnames,
499-
.maxlen = sizeof(int),
499+
.maxlen = sizeof(bool),
500500
.mode = 0644,
501501
.proc_handler = proc_dobool,
502502
},

fs/proc/proc_sysctl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,11 @@ static int sysctl_check_table_array(const char *path, struct ctl_table *table)
11241124
err |= sysctl_err(path, table, "array not allowed");
11251125
}
11261126

1127+
if (table->proc_handler == proc_dobool) {
1128+
if (table->maxlen != sizeof(bool))
1129+
err |= sysctl_err(path, table, "array not allowed");
1130+
}
1131+
11271132
return err;
11281133
}
11291134

@@ -1136,6 +1141,7 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
11361141
err |= sysctl_err(path, entry, "Not a file");
11371142

11381143
if ((entry->proc_handler == proc_dostring) ||
1144+
(entry->proc_handler == proc_dobool) ||
11391145
(entry->proc_handler == proc_dointvec) ||
11401146
(entry->proc_handler == proc_douintvec) ||
11411147
(entry->proc_handler == proc_douintvec_minmax) ||

kernel/sysctl.c

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -425,21 +425,6 @@ static void proc_put_char(void **buf, size_t *size, char c)
425425
}
426426
}
427427

428-
static int do_proc_dobool_conv(bool *negp, unsigned long *lvalp,
429-
int *valp,
430-
int write, void *data)
431-
{
432-
if (write) {
433-
*(bool *)valp = *lvalp;
434-
} else {
435-
int val = *(bool *)valp;
436-
437-
*lvalp = (unsigned long)val;
438-
*negp = false;
439-
}
440-
return 0;
441-
}
442-
443428
static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
444429
int *valp,
445430
int write, void *data)
@@ -710,16 +695,36 @@ int do_proc_douintvec(struct ctl_table *table, int write,
710695
* @lenp: the size of the user buffer
711696
* @ppos: file position
712697
*
713-
* Reads/writes up to table->maxlen/sizeof(unsigned int) integer
714-
* values from/to the user buffer, treated as an ASCII string.
698+
* Reads/writes one integer value from/to the user buffer,
699+
* treated as an ASCII string.
700+
*
701+
* table->data must point to a bool variable and table->maxlen must
702+
* be sizeof(bool).
715703
*
716704
* Returns 0 on success.
717705
*/
718706
int proc_dobool(struct ctl_table *table, int write, void *buffer,
719707
size_t *lenp, loff_t *ppos)
720708
{
721-
return do_proc_dointvec(table, write, buffer, lenp, ppos,
722-
do_proc_dobool_conv, NULL);
709+
struct ctl_table tmp;
710+
bool *data = table->data;
711+
int res, val;
712+
713+
/* Do not support arrays yet. */
714+
if (table->maxlen != sizeof(bool))
715+
return -EINVAL;
716+
717+
tmp = *table;
718+
tmp.maxlen = sizeof(val);
719+
tmp.data = &val;
720+
721+
val = READ_ONCE(*data);
722+
res = proc_dointvec(&tmp, write, buffer, lenp, ppos);
723+
if (res)
724+
return res;
725+
if (write)
726+
WRITE_ONCE(*data, val);
727+
return 0;
723728
}
724729

725730
/**

mm/hugetlb_vmemmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ static struct ctl_table hugetlb_vmemmap_sysctls[] = {
581581
{
582582
.procname = "hugetlb_optimize_vmemmap",
583583
.data = &vmemmap_optimize_enabled,
584-
.maxlen = sizeof(int),
584+
.maxlen = sizeof(vmemmap_optimize_enabled),
585585
.mode = 0644,
586586
.proc_handler = proc_dobool,
587587
},

0 commit comments

Comments
 (0)