Skip to content

Commit 3292739

Browse files
Christoph HellwigAl Viro
authored andcommitted
sysctl: pass kernel pointers to ->proc_handler
Instead of having all the sysctl handlers deal with user pointers, which is rather hairy in terms of the BPF interaction, copy the input to and from userspace in common code. This also means that the strings are always NUL-terminated by the common code, making the API a little bit safer. As most handler just pass through the data to one of the common handlers a lot of the changes are mechnical. Signed-off-by: Christoph Hellwig <[email protected]> Acked-by: Andrey Ignatov <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent f461d2d commit 3292739

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+458
-653
lines changed

arch/arm64/kernel/armv8_deprecated.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static void __init register_insn_emulation(struct insn_emulation_ops *ops)
203203
}
204204

205205
static int emulation_proc_handler(struct ctl_table *table, int write,
206-
void __user *buffer, size_t *lenp,
206+
void *buffer, size_t *lenp,
207207
loff_t *ppos)
208208
{
209209
int ret = 0;

arch/arm64/kernel/fpsimd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,7 @@ static unsigned int find_supported_vector_length(unsigned int vl)
341341
#ifdef CONFIG_SYSCTL
342342

343343
static int sve_proc_do_default_vl(struct ctl_table *table, int write,
344-
void __user *buffer, size_t *lenp,
345-
loff_t *ppos)
344+
void *buffer, size_t *lenp, loff_t *ppos)
346345
{
347346
int ret;
348347
int vl = sve_default_vl;

arch/mips/lasat/sysctl.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,15 @@ int proc_lasat_ip(struct ctl_table *table, int write,
9595
len = 0;
9696
p = buffer;
9797
while (len < *lenp) {
98-
if (get_user(c, p++))
99-
return -EFAULT;
98+
c = *p;
99+
p++;
100100
if (c == 0 || c == '\n')
101101
break;
102102
len++;
103103
}
104104
if (len >= sizeof(ipbuf)-1)
105105
len = sizeof(ipbuf) - 1;
106-
if (copy_from_user(ipbuf, buffer, len))
107-
return -EFAULT;
106+
memcpy(ipbuf, buffer, len);
108107
ipbuf[len] = 0;
109108
*ppos += *lenp;
110109
/* Now see if we can convert it to a valid IP */
@@ -122,11 +121,9 @@ int proc_lasat_ip(struct ctl_table *table, int write,
122121
if (len > *lenp)
123122
len = *lenp;
124123
if (len)
125-
if (copy_to_user(buffer, ipbuf, len))
126-
return -EFAULT;
124+
memcpy(buffer, ipbuf, len);
127125
if (len < *lenp) {
128-
if (put_user('\n', ((char *) buffer) + len))
129-
return -EFAULT;
126+
*((char *)buffer + len) = '\n';
130127
len++;
131128
}
132129
*lenp = len;

arch/s390/appldata/appldata_base.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ static struct platform_device *appldata_pdev;
5151
*/
5252
static const char appldata_proc_name[APPLDATA_PROC_NAME_LENGTH] = "appldata";
5353
static int appldata_timer_handler(struct ctl_table *ctl, int write,
54-
void __user *buffer, size_t *lenp, loff_t *ppos);
54+
void *buffer, size_t *lenp, loff_t *ppos);
5555
static int appldata_interval_handler(struct ctl_table *ctl, int write,
56-
void __user *buffer,
57-
size_t *lenp, loff_t *ppos);
56+
void *buffer, size_t *lenp, loff_t *ppos);
5857

5958
static struct ctl_table_header *appldata_sysctl_header;
6059
static struct ctl_table appldata_table[] = {
@@ -217,7 +216,7 @@ static void __appldata_vtimer_setup(int cmd)
217216
*/
218217
static int
219218
appldata_timer_handler(struct ctl_table *ctl, int write,
220-
void __user *buffer, size_t *lenp, loff_t *ppos)
219+
void *buffer, size_t *lenp, loff_t *ppos)
221220
{
222221
int timer_active = appldata_timer_active;
223222
int rc;
@@ -250,7 +249,7 @@ appldata_timer_handler(struct ctl_table *ctl, int write,
250249
*/
251250
static int
252251
appldata_interval_handler(struct ctl_table *ctl, int write,
253-
void __user *buffer, size_t *lenp, loff_t *ppos)
252+
void *buffer, size_t *lenp, loff_t *ppos)
254253
{
255254
int interval = appldata_interval;
256255
int rc;
@@ -280,7 +279,7 @@ appldata_interval_handler(struct ctl_table *ctl, int write,
280279
*/
281280
static int
282281
appldata_generic_handler(struct ctl_table *ctl, int write,
283-
void __user *buffer, size_t *lenp, loff_t *ppos)
282+
void *buffer, size_t *lenp, loff_t *ppos)
284283
{
285284
struct appldata_ops *ops = NULL, *tmp_ops;
286285
struct list_head *lh;

arch/s390/kernel/debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ static int debug_active = 1;
867867
* if debug_active is already off
868868
*/
869869
static int s390dbf_procactive(struct ctl_table *table, int write,
870-
void __user *buffer, size_t *lenp, loff_t *ppos)
870+
void *buffer, size_t *lenp, loff_t *ppos)
871871
{
872872
if (!write || debug_stoppable || !debug_active)
873873
return proc_dointvec(table, write, buffer, lenp, ppos);

arch/s390/kernel/topology.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ static int __init topology_setup(char *str)
594594
early_param("topology", topology_setup);
595595

596596
static int topology_ctl_handler(struct ctl_table *ctl, int write,
597-
void __user *buffer, size_t *lenp, loff_t *ppos)
597+
void *buffer, size_t *lenp, loff_t *ppos)
598598
{
599599
int enabled = topology_is_enabled();
600600
int new_mode;

arch/s390/mm/cmm.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ static int cmm_skip_blanks(char *cp, char **endp)
245245
}
246246

247247
static int cmm_pages_handler(struct ctl_table *ctl, int write,
248-
void __user *buffer, size_t *lenp, loff_t *ppos)
248+
void *buffer, size_t *lenp, loff_t *ppos)
249249
{
250250
long nr = cmm_get_pages();
251251
struct ctl_table ctl_entry = {
@@ -264,7 +264,7 @@ static int cmm_pages_handler(struct ctl_table *ctl, int write,
264264
}
265265

266266
static int cmm_timed_pages_handler(struct ctl_table *ctl, int write,
267-
void __user *buffer, size_t *lenp,
267+
void *buffer, size_t *lenp,
268268
loff_t *ppos)
269269
{
270270
long nr = cmm_get_timed_pages();
@@ -284,7 +284,7 @@ static int cmm_timed_pages_handler(struct ctl_table *ctl, int write,
284284
}
285285

286286
static int cmm_timeout_handler(struct ctl_table *ctl, int write,
287-
void __user *buffer, size_t *lenp, loff_t *ppos)
287+
void *buffer, size_t *lenp, loff_t *ppos)
288288
{
289289
char buf[64], *p;
290290
long nr, seconds;
@@ -297,8 +297,7 @@ static int cmm_timeout_handler(struct ctl_table *ctl, int write,
297297

298298
if (write) {
299299
len = min(*lenp, sizeof(buf));
300-
if (copy_from_user(buf, buffer, len))
301-
return -EFAULT;
300+
memcpy(buf, buffer, len);
302301
buf[len - 1] = '\0';
303302
cmm_skip_blanks(buf, &p);
304303
nr = simple_strtoul(p, &p, 0);
@@ -311,8 +310,7 @@ static int cmm_timeout_handler(struct ctl_table *ctl, int write,
311310
cmm_timeout_pages, cmm_timeout_seconds);
312311
if (len > *lenp)
313312
len = *lenp;
314-
if (copy_to_user(buffer, buf, len))
315-
return -EFAULT;
313+
memcpy(buffer, buf, len);
316314
*lenp = len;
317315
*ppos += len;
318316
}

arch/x86/kernel/itmt.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ static bool __read_mostly sched_itmt_capable;
3939
unsigned int __read_mostly sysctl_sched_itmt_enabled;
4040

4141
static int sched_itmt_update_handler(struct ctl_table *table, int write,
42-
void __user *buffer, size_t *lenp,
43-
loff_t *ppos)
42+
void *buffer, size_t *lenp, loff_t *ppos)
4443
{
4544
unsigned int old_sysctl;
4645
int ret;

drivers/cdrom/cdrom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3631,7 +3631,7 @@ static void cdrom_update_settings(void)
36313631
}
36323632

36333633
static int cdrom_sysctl_handler(struct ctl_table *ctl, int write,
3634-
void __user *buffer, size_t *lenp, loff_t *ppos)
3634+
void *buffer, size_t *lenp, loff_t *ppos)
36353635
{
36363636
int ret;
36373637

drivers/char/random.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,7 @@ static char sysctl_bootid[16];
20572057
* sysctl system call, as 16 bytes of binary data.
20582058
*/
20592059
static int proc_do_uuid(struct ctl_table *table, int write,
2060-
void __user *buffer, size_t *lenp, loff_t *ppos)
2060+
void *buffer, size_t *lenp, loff_t *ppos)
20612061
{
20622062
struct ctl_table fake_table;
20632063
unsigned char buf[64], tmp_uuid[16], *uuid;

0 commit comments

Comments
 (0)