Skip to content

Commit 3292739

Browse files
Christoph HellwigAl Viro
Christoph Hellwig
authored and
Al Viro
committed
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;

drivers/macintosh/mac_hid.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ static void mac_hid_stop_emulation(void)
183183
}
184184

185185
static int mac_hid_toggle_emumouse(struct ctl_table *table, int write,
186-
void __user *buffer, size_t *lenp,
187-
loff_t *ppos)
186+
void *buffer, size_t *lenp, loff_t *ppos)
188187
{
189188
int *valp = table->data;
190189
int old_val = *valp;

drivers/parport/procfs.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#define PARPORT_MAX_SPINTIME_VALUE 1000
3535

3636
static int do_active_device(struct ctl_table *table, int write,
37-
void __user *result, size_t *lenp, loff_t *ppos)
37+
void *result, size_t *lenp, loff_t *ppos)
3838
{
3939
struct parport *port = (struct parport *)table->extra1;
4040
char buffer[256];
@@ -65,13 +65,13 @@ static int do_active_device(struct ctl_table *table, int write,
6565
*lenp = len;
6666

6767
*ppos += len;
68-
69-
return copy_to_user(result, buffer, len) ? -EFAULT : 0;
68+
memcpy(result, buffer, len);
69+
return 0;
7070
}
7171

7272
#ifdef CONFIG_PARPORT_1284
7373
static int do_autoprobe(struct ctl_table *table, int write,
74-
void __user *result, size_t *lenp, loff_t *ppos)
74+
void *result, size_t *lenp, loff_t *ppos)
7575
{
7676
struct parport_device_info *info = table->extra2;
7777
const char *str;
@@ -108,13 +108,13 @@ static int do_autoprobe(struct ctl_table *table, int write,
108108

109109
*ppos += len;
110110

111-
return copy_to_user (result, buffer, len) ? -EFAULT : 0;
111+
memcpy(result, buffer, len);
112+
return 0;
112113
}
113114
#endif /* IEEE1284.3 support. */
114115

115116
static int do_hardware_base_addr(struct ctl_table *table, int write,
116-
void __user *result,
117-
size_t *lenp, loff_t *ppos)
117+
void *result, size_t *lenp, loff_t *ppos)
118118
{
119119
struct parport *port = (struct parport *)table->extra1;
120120
char buffer[20];
@@ -136,13 +136,12 @@ static int do_hardware_base_addr(struct ctl_table *table, int write,
136136
*lenp = len;
137137

138138
*ppos += len;
139-
140-
return copy_to_user(result, buffer, len) ? -EFAULT : 0;
139+
memcpy(result, buffer, len);
140+
return 0;
141141
}
142142

143143
static int do_hardware_irq(struct ctl_table *table, int write,
144-
void __user *result,
145-
size_t *lenp, loff_t *ppos)
144+
void *result, size_t *lenp, loff_t *ppos)
146145
{
147146
struct parport *port = (struct parport *)table->extra1;
148147
char buffer[20];
@@ -164,13 +163,12 @@ static int do_hardware_irq(struct ctl_table *table, int write,
164163
*lenp = len;
165164

166165
*ppos += len;
167-
168-
return copy_to_user(result, buffer, len) ? -EFAULT : 0;
166+
memcpy(result, buffer, len);
167+
return 0;
169168
}
170169

171170
static int do_hardware_dma(struct ctl_table *table, int write,
172-
void __user *result,
173-
size_t *lenp, loff_t *ppos)
171+
void *result, size_t *lenp, loff_t *ppos)
174172
{
175173
struct parport *port = (struct parport *)table->extra1;
176174
char buffer[20];
@@ -192,13 +190,12 @@ static int do_hardware_dma(struct ctl_table *table, int write,
192190
*lenp = len;
193191

194192
*ppos += len;
195-
196-
return copy_to_user(result, buffer, len) ? -EFAULT : 0;
193+
memcpy(result, buffer, len);
194+
return 0;
197195
}
198196

199197
static int do_hardware_modes(struct ctl_table *table, int write,
200-
void __user *result,
201-
size_t *lenp, loff_t *ppos)
198+
void *result, size_t *lenp, loff_t *ppos)
202199
{
203200
struct parport *port = (struct parport *)table->extra1;
204201
char buffer[40];
@@ -231,8 +228,8 @@ static int do_hardware_modes(struct ctl_table *table, int write,
231228
*lenp = len;
232229

233230
*ppos += len;
234-
235-
return copy_to_user(result, buffer, len) ? -EFAULT : 0;
231+
memcpy(result, buffer, len);
232+
return 0;
236233
}
237234

238235
#define PARPORT_PORT_DIR(CHILD) { .procname = NULL, .mode = 0555, .child = CHILD }

fs/dcache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static long get_nr_dentry_negative(void)
165165
return sum < 0 ? 0 : sum;
166166
}
167167

168-
int proc_nr_dentry(struct ctl_table *table, int write, void __user *buffer,
168+
int proc_nr_dentry(struct ctl_table *table, int write, void *buffer,
169169
size_t *lenp, loff_t *ppos)
170170
{
171171
dentry_stat.nr_dentry = get_nr_dentry();

fs/drop_caches.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused)
4747
}
4848

4949
int drop_caches_sysctl_handler(struct ctl_table *table, int write,
50-
void __user *buffer, size_t *length, loff_t *ppos)
50+
void *buffer, size_t *length, loff_t *ppos)
5151
{
5252
int ret;
5353

fs/file_table.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ EXPORT_SYMBOL_GPL(get_max_files);
8080
*/
8181
#if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS)
8282
int proc_nr_files(struct ctl_table *table, int write,
83-
void __user *buffer, size_t *lenp, loff_t *ppos)
83+
void *buffer, size_t *lenp, loff_t *ppos)
8484
{
8585
files_stat.nr_files = get_nr_files();
8686
return proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
8787
}
8888
#else
8989
int proc_nr_files(struct ctl_table *table, int write,
90-
void __user *buffer, size_t *lenp, loff_t *ppos)
90+
void *buffer, size_t *lenp, loff_t *ppos)
9191
{
9292
return -ENOSYS;
9393
}

fs/fscache/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ static unsigned fscache_op_max_active = 2;
5151
static struct ctl_table_header *fscache_sysctl_header;
5252

5353
static int fscache_max_active_sysctl(struct ctl_table *table, int write,
54-
void __user *buffer,
55-
size_t *lenp, loff_t *ppos)
54+
void *buffer, size_t *lenp, loff_t *ppos)
5655
{
5756
struct workqueue_struct **wqp = table->extra1;
5857
unsigned int *datap = table->data;

fs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ long get_nr_dirty_inodes(void)
108108
*/
109109
#ifdef CONFIG_SYSCTL
110110
int proc_nr_inodes(struct ctl_table *table, int write,
111-
void __user *buffer, size_t *lenp, loff_t *ppos)
111+
void *buffer, size_t *lenp, loff_t *ppos)
112112
{
113113
inodes_stat.nr_inodes = get_nr_inodes();
114114
inodes_stat.nr_unused = get_nr_inodes_unused();

0 commit comments

Comments
 (0)