Lines Matching +full:buffer +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0-only
27 const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, 1000, 3000, INT_MAX, 65535, -1 };
42 * enum sysctl_writes_mode - supported sysctl write modes
51 * file position 0 and the value must be fully contained in the buffer
53 * position, but restrict this to the max length of the buffer, anything
55 * to the buffer.
61 SYSCTL_WRITES_LEGACY = -1,
77 char *buffer, size_t *lenp, loff_t *ppos) in _proc_do_string() argument
89 /* Only continue writes not past the end of buffer. */ in _proc_do_string()
91 if (len > maxlen - 1) in _proc_do_string()
92 len = maxlen - 1; in _proc_do_string()
98 /* Start writing from beginning of buffer. */ in _proc_do_string()
103 p = buffer; in _proc_do_string()
104 while ((p - buffer) < *lenp && len < maxlen - 1) { in _proc_do_string()
122 len -= *ppos; in _proc_do_string()
127 memcpy(buffer, data, len); in _proc_do_string()
129 buffer[len] = '\n'; in _proc_do_string()
142 "warning, set kernel.sysctl_writes_strict = -1\n", in warn_sysctl_write()
143 current->comm, table->procname); in warn_sysctl_write()
147 * proc_first_pos_non_zero_ignore - check if first position is allowed
151 * Returns true if the first position is non-zero and the sysctl_writes_strict
173 * proc_dostring - read a string sysctl
176 * @buffer: the user buffer
177 * @lenp: the size of the user buffer
180 * Reads/writes a string from/to the user buffer. If the kernel
181 * buffer provided is not large enough to hold the string, the
182 * string is truncated. The copied string is %NULL-terminated.
184 * and a newline '\n' is added. It is truncated if the buffer is
190 void *buffer, size_t *lenp, loff_t *ppos) in proc_dostring() argument
195 return _proc_do_string(table->data, table->maxlen, write, buffer, lenp, in proc_dostring()
199 static void proc_skip_spaces(char **buf, size_t *size) in proc_skip_spaces() argument
201 while (*size) { in proc_skip_spaces()
204 (*size)--; in proc_skip_spaces()
209 static void proc_skip_char(char **buf, size_t *size, const char v) in proc_skip_char() argument
211 while (*size) { in proc_skip_char()
214 (*size)--; in proc_skip_char()
220 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
223 * @cp: kernel buffer containing the string to parse
243 return -ERANGE; in strtoul_lenient()
256 * proc_get_long - reads an ASCII formatted integer from a user buffer
258 * @buf: a kernel buffer
259 * @size: size of the kernel buffer
263 * @perm_tr_len: size of the perm_tr vector
266 * In case of success %0 is returned and @buf and @size are updated with
267 * the amount of bytes read. If @tr is non-NULL and a trailing
268 * character exists (size is non-zero after returning from this
271 static int proc_get_long(char **buf, size_t *size, in proc_get_long() argument
276 ssize_t len = *size; in proc_get_long()
279 return -EINVAL; in proc_get_long()
281 if (len > TMPBUFLEN - 1) in proc_get_long()
282 len = TMPBUFLEN - 1; in proc_get_long()
288 if (*p == '-' && *size > 1) { in proc_get_long()
294 return -EINVAL; in proc_get_long()
297 return -EINVAL; in proc_get_long()
299 len = p - tmp; in proc_get_long()
304 if (len == TMPBUFLEN - 1) in proc_get_long()
305 return -EINVAL; in proc_get_long()
307 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len)) in proc_get_long()
308 return -EINVAL; in proc_get_long()
310 if (tr && (len < *size)) in proc_get_long()
314 *size -= len; in proc_get_long()
320 * proc_put_long - converts an integer to a decimal ASCII formatted string
322 * @buf: the user buffer
323 * @size: the size of the user buffer
327 * In case of success @buf and @size are updated with the amount of bytes
330 static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg) in proc_put_long() argument
335 sprintf(p, "%s%lu", neg ? "-" : "", val); in proc_put_long()
337 if (len > *size) in proc_put_long()
338 len = *size; in proc_put_long()
340 *size -= len; in proc_put_long()
345 static void proc_put_char(void **buf, size_t *size, char c) in proc_put_char() argument
347 if (*size) { in proc_put_char()
348 char **buffer = (char **)buf; in proc_put_char() local
349 **buffer = c; in proc_put_char()
351 (*size)--; in proc_put_char()
352 (*buffer)++; in proc_put_char()
353 *buf = *buffer; in proc_put_char()
364 return -EINVAL; in do_proc_dointvec_conv()
365 WRITE_ONCE(*valp, -*lvalp); in do_proc_dointvec_conv()
368 return -EINVAL; in do_proc_dointvec_conv()
375 *lvalp = -(unsigned long)val; in do_proc_dointvec_conv()
390 return -EINVAL; in do_proc_douintvec_conv()
402 int write, void *buffer, in __do_proc_dointvec() argument
412 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { in __do_proc_dointvec()
418 vleft = table->maxlen / sizeof(*i); in __do_proc_dointvec()
428 if (left > PAGE_SIZE - 1) in __do_proc_dointvec()
429 left = PAGE_SIZE - 1; in __do_proc_dointvec()
430 p = buffer; in __do_proc_dointvec()
433 for (; left && vleft--; i++, first=0) { in __do_proc_dointvec()
448 err = -EINVAL; in __do_proc_dointvec()
453 err = -EINVAL; in __do_proc_dointvec()
457 proc_put_char(&buffer, &left, '\t'); in __do_proc_dointvec()
458 proc_put_long(&buffer, &left, lval, neg); in __do_proc_dointvec()
463 proc_put_char(&buffer, &left, '\n'); in __do_proc_dointvec()
467 return err ? : -EINVAL; in __do_proc_dointvec()
468 *lenp -= left; in __do_proc_dointvec()
475 void *buffer, size_t *lenp, loff_t *ppos, in do_proc_dointvec() argument
480 return __do_proc_dointvec(table->data, table, write, in do_proc_dointvec()
481 buffer, lenp, ppos, conv, data); in do_proc_dointvec()
486 void *buffer, in do_proc_douintvec_w() argument
497 char *p = buffer; in do_proc_douintvec_w()
504 if (left > PAGE_SIZE - 1) in do_proc_douintvec_w()
505 left = PAGE_SIZE - 1; in do_proc_douintvec_w()
509 err = -EINVAL; in do_proc_douintvec_w()
517 err = -EINVAL; in do_proc_douintvec_w()
522 err = -EINVAL; in do_proc_douintvec_w()
531 return -EINVAL; in do_proc_douintvec_w()
541 static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer, in do_proc_douintvec_r() argument
555 err = -EINVAL; in do_proc_douintvec_r()
559 proc_put_long(&buffer, &left, lval, false); in do_proc_douintvec_r()
563 proc_put_char(&buffer, &left, '\n'); in do_proc_douintvec_r()
566 *lenp -= left; in do_proc_douintvec_r()
573 int write, void *buffer, in __do_proc_douintvec() argument
582 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { in __do_proc_douintvec()
588 vleft = table->maxlen / sizeof(*i); in __do_proc_douintvec()
596 return -EINVAL; in __do_proc_douintvec()
603 return do_proc_douintvec_w(i, table, buffer, lenp, ppos, in __do_proc_douintvec()
605 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data); in __do_proc_douintvec()
609 void *buffer, size_t *lenp, loff_t *ppos, in do_proc_douintvec() argument
615 return __do_proc_douintvec(table->data, table, write, in do_proc_douintvec()
616 buffer, lenp, ppos, conv, data); in do_proc_douintvec()
620 * proc_dobool - read/write a bool
623 * @buffer: the user buffer
624 * @lenp: the size of the user buffer
627 * Reads/writes one integer value from/to the user buffer,
630 * table->data must point to a bool variable and table->maxlen must
635 int proc_dobool(const struct ctl_table *table, int write, void *buffer, in proc_dobool() argument
639 bool *data = table->data; in proc_dobool()
643 if (table->maxlen != sizeof(bool)) in proc_dobool()
644 return -EINVAL; in proc_dobool()
651 res = proc_dointvec(&tmp, write, buffer, lenp, ppos); in proc_dobool()
660 * proc_dointvec - read a vector of integers
663 * @buffer: the user buffer
664 * @lenp: the size of the user buffer
667 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
668 * values from/to the user buffer, treated as an ASCII string.
672 int proc_dointvec(const struct ctl_table *table, int write, void *buffer, in proc_dointvec() argument
675 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL); in proc_dointvec()
679 * proc_douintvec - read a vector of unsigned integers
682 * @buffer: the user buffer
683 * @lenp: the size of the user buffer
686 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
687 * values from/to the user buffer, treated as an ASCII string.
691 int proc_douintvec(const struct ctl_table *table, int write, void *buffer, in proc_douintvec() argument
694 return do_proc_douintvec(table, write, buffer, lenp, ppos, in proc_douintvec()
699 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
720 * bounds-check it before touching *valp. in do_proc_dointvec_minmax_conv()
729 if ((param->min && *param->min > tmp) || in do_proc_dointvec_minmax_conv()
730 (param->max && *param->max < tmp)) in do_proc_dointvec_minmax_conv()
731 return -EINVAL; in do_proc_dointvec_minmax_conv()
739 * proc_dointvec_minmax - read a vector of integers with min/max values
742 * @buffer: the user buffer
743 * @lenp: the size of the user buffer
746 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
747 * values from/to the user buffer, treated as an ASCII string.
750 * table->extra1 (min) and table->extra2 (max).
752 * Returns 0 on success or -EINVAL on write when the range check fails.
755 void *buffer, size_t *lenp, loff_t *ppos) in proc_dointvec_minmax() argument
758 .min = (int *) table->extra1, in proc_dointvec_minmax()
759 .max = (int *) table->extra2, in proc_dointvec_minmax()
761 return do_proc_dointvec(table, write, buffer, lenp, ppos, in proc_dointvec_minmax()
766 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
786 /* write via temporary local uint for bounds-checking */ in do_proc_douintvec_minmax_conv()
794 if ((param->min && *param->min > tmp) || in do_proc_douintvec_minmax_conv()
795 (param->max && *param->max < tmp)) in do_proc_douintvec_minmax_conv()
796 return -ERANGE; in do_proc_douintvec_minmax_conv()
805 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
808 * @buffer: the user buffer
809 * @lenp: the size of the user buffer
812 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
813 * values from/to the user buffer, treated as an ASCII string. Negative
817 * table->extra1 (min) and table->extra2 (max). There is a final sanity
821 * Returns 0 on success or -ERANGE on write when the range check fails.
824 void *buffer, size_t *lenp, loff_t *ppos) in proc_douintvec_minmax() argument
827 .min = (unsigned int *) table->extra1, in proc_douintvec_minmax()
828 .max = (unsigned int *) table->extra2, in proc_douintvec_minmax()
830 return do_proc_douintvec(table, write, buffer, lenp, ppos, in proc_douintvec_minmax()
835 * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values
838 * @buffer: the user buffer
839 * @lenp: the size of the user buffer
842 * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars
843 * values from/to the user buffer, treated as an ASCII string. Negative
847 * table->extra1 (min) and table->extra2 (max).
852 void *buffer, size_t *lenp, loff_t *ppos) in proc_dou8vec_minmax() argument
856 u8 *data = table->data; in proc_dou8vec_minmax()
864 if (table->maxlen != sizeof(u8)) in proc_dou8vec_minmax()
865 return -EINVAL; in proc_dou8vec_minmax()
867 if (table->extra1) in proc_dou8vec_minmax()
868 min = *(unsigned int *) table->extra1; in proc_dou8vec_minmax()
869 if (table->extra2) in proc_dou8vec_minmax()
870 max = *(unsigned int *) table->extra2; in proc_dou8vec_minmax()
877 res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos, in proc_dou8vec_minmax()
889 void *buffer, size_t *lenp, loff_t *ppos, in __do_proc_doulongvec_minmax() argument
897 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) { in __do_proc_doulongvec_minmax()
903 min = table->extra1; in __do_proc_doulongvec_minmax()
904 max = table->extra2; in __do_proc_doulongvec_minmax()
905 vleft = table->maxlen / sizeof(unsigned long); in __do_proc_doulongvec_minmax()
912 if (left > PAGE_SIZE - 1) in __do_proc_doulongvec_minmax()
913 left = PAGE_SIZE - 1; in __do_proc_doulongvec_minmax()
914 p = buffer; in __do_proc_doulongvec_minmax()
917 for (; left && vleft--; i++, first = 0) { in __do_proc_doulongvec_minmax()
931 err = -EINVAL; in __do_proc_doulongvec_minmax()
937 err = -EINVAL; in __do_proc_doulongvec_minmax()
944 proc_put_char(&buffer, &left, '\t'); in __do_proc_doulongvec_minmax()
945 proc_put_long(&buffer, &left, val, false); in __do_proc_doulongvec_minmax()
950 proc_put_char(&buffer, &left, '\n'); in __do_proc_doulongvec_minmax()
954 return err ? : -EINVAL; in __do_proc_doulongvec_minmax()
955 *lenp -= left; in __do_proc_doulongvec_minmax()
962 void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul, in do_proc_doulongvec_minmax() argument
965 return __do_proc_doulongvec_minmax(table->data, table, write, in do_proc_doulongvec_minmax()
966 buffer, lenp, ppos, convmul, convdiv); in do_proc_doulongvec_minmax()
970 * proc_doulongvec_minmax - read a vector of long integers with min/max values
973 * @buffer: the user buffer
974 * @lenp: the size of the user buffer
977 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
978 * values from/to the user buffer, treated as an ASCII string.
981 * table->extra1 (min) and table->extra2 (max).
986 void *buffer, size_t *lenp, loff_t *ppos) in proc_doulongvec_minmax() argument
988 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l); in proc_doulongvec_minmax()
992 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
995 * @buffer: the user buffer
996 * @lenp: the size of the user buffer
999 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1000 * values from/to the user buffer, treated as an ASCII string. The values
1004 * table->extra1 (min) and table->extra2 (max).
1009 void *buffer, size_t *lenp, loff_t *ppos) in proc_doulongvec_ms_jiffies_minmax() argument
1011 return do_proc_doulongvec_minmax(table, write, buffer, in proc_doulongvec_ms_jiffies_minmax()
1024 WRITE_ONCE(*valp, -*lvalp * HZ); in do_proc_dointvec_jiffies_conv()
1032 lval = -(unsigned long)val; in do_proc_dointvec_jiffies_conv()
1049 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); in do_proc_dointvec_userhz_jiffies_conv()
1055 lval = -(unsigned long)val; in do_proc_dointvec_userhz_jiffies_conv()
1070 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); in do_proc_dointvec_ms_jiffies_conv()
1080 lval = -(unsigned long)val; in do_proc_dointvec_ms_jiffies_conv()
1097 * bounds-check it before touching *valp. in do_proc_dointvec_ms_jiffies_minmax_conv()
1106 if ((param->min && *param->min > tmp) || in do_proc_dointvec_ms_jiffies_minmax_conv()
1107 (param->max && *param->max < tmp)) in do_proc_dointvec_ms_jiffies_minmax_conv()
1108 return -EINVAL; in do_proc_dointvec_ms_jiffies_minmax_conv()
1115 * proc_dointvec_jiffies - read a vector of integers as seconds
1118 * @buffer: the user buffer
1119 * @lenp: the size of the user buffer
1122 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1123 * values from/to the user buffer, treated as an ASCII string.
1130 void *buffer, size_t *lenp, loff_t *ppos) in proc_dointvec_jiffies() argument
1132 return do_proc_dointvec(table,write,buffer,lenp,ppos, in proc_dointvec_jiffies()
1137 void *buffer, size_t *lenp, loff_t *ppos) in proc_dointvec_ms_jiffies_minmax() argument
1140 .min = (int *) table->extra1, in proc_dointvec_ms_jiffies_minmax()
1141 .max = (int *) table->extra2, in proc_dointvec_ms_jiffies_minmax()
1143 return do_proc_dointvec(table, write, buffer, lenp, ppos, in proc_dointvec_ms_jiffies_minmax()
1148 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1151 * @buffer: the user buffer
1152 * @lenp: the size of the user buffer
1155 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1156 * values from/to the user buffer, treated as an ASCII string.
1163 void *buffer, size_t *lenp, loff_t *ppos) in proc_dointvec_userhz_jiffies() argument
1165 return do_proc_dointvec(table, write, buffer, lenp, ppos, in proc_dointvec_userhz_jiffies()
1170 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1173 * @buffer: the user buffer
1174 * @lenp: the size of the user buffer
1177 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1178 * values from/to the user buffer, treated as an ASCII string.
1184 int proc_dointvec_ms_jiffies(const struct ctl_table *table, int write, void *buffer, in proc_dointvec_ms_jiffies() argument
1187 return do_proc_dointvec(table, write, buffer, lenp, ppos, in proc_dointvec_ms_jiffies()
1192 * proc_do_large_bitmap - read/write from/to a large bitmap
1195 * @buffer: the user buffer
1196 * @lenp: the size of the user buffer
1199 * The bitmap is stored at table->data and the bitmap length (in bits)
1200 * in table->maxlen.
1202 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1209 void *buffer, size_t *lenp, loff_t *ppos) in proc_do_large_bitmap() argument
1213 unsigned long bitmap_len = table->maxlen; in proc_do_large_bitmap()
1214 unsigned long *bitmap = *(unsigned long **) table->data; in proc_do_large_bitmap()
1216 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c; in proc_do_large_bitmap()
1224 char *p = buffer; in proc_do_large_bitmap()
1227 if (left > PAGE_SIZE - 1) { in proc_do_large_bitmap()
1228 left = PAGE_SIZE - 1; in proc_do_large_bitmap()
1229 /* How much of the buffer we'll skip this pass */ in proc_do_large_bitmap()
1230 skipped = *lenp - left; in proc_do_large_bitmap()
1235 return -ENOMEM; in proc_do_large_bitmap()
1242 /* In case we stop parsing mid-number, we can reset */ in proc_do_large_bitmap()
1247 * If we consumed the entirety of a truncated buffer or in proc_do_large_bitmap()
1248 * only one char is left (may be a "-"), then stop here, in proc_do_large_bitmap()
1259 err = -EINVAL; in proc_do_large_bitmap()
1266 left--; in proc_do_large_bitmap()
1269 if (c == '-') { in proc_do_large_bitmap()
1274 * If we consumed all of a truncated buffer or in proc_do_large_bitmap()
1286 err = -EINVAL; in proc_do_large_bitmap()
1291 left--; in proc_do_large_bitmap()
1295 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1); in proc_do_large_bitmap()
1308 bit_a + 1) - 1; in proc_do_large_bitmap()
1311 proc_put_char(&buffer, &left, ','); in proc_do_large_bitmap()
1312 proc_put_long(&buffer, &left, bit_a, false); in proc_do_large_bitmap()
1314 proc_put_char(&buffer, &left, '-'); in proc_do_large_bitmap()
1315 proc_put_long(&buffer, &left, bit_b, false); in proc_do_large_bitmap()
1320 proc_put_char(&buffer, &left, '\n'); in proc_do_large_bitmap()
1330 *lenp -= left; in proc_do_large_bitmap()
1341 void *buffer, size_t *lenp, loff_t *ppos) in proc_dostring() argument
1343 return -ENOSYS; in proc_dostring()
1347 void *buffer, size_t *lenp, loff_t *ppos) in proc_dobool() argument
1349 return -ENOSYS; in proc_dobool()
1353 void *buffer, size_t *lenp, loff_t *ppos) in proc_dointvec() argument
1355 return -ENOSYS; in proc_dointvec()
1359 void *buffer, size_t *lenp, loff_t *ppos) in proc_douintvec() argument
1361 return -ENOSYS; in proc_douintvec()
1365 void *buffer, size_t *lenp, loff_t *ppos) in proc_dointvec_minmax() argument
1367 return -ENOSYS; in proc_dointvec_minmax()
1371 void *buffer, size_t *lenp, loff_t *ppos) in proc_douintvec_minmax() argument
1373 return -ENOSYS; in proc_douintvec_minmax()
1377 void *buffer, size_t *lenp, loff_t *ppos) in proc_dou8vec_minmax() argument
1379 return -ENOSYS; in proc_dou8vec_minmax()
1383 void *buffer, size_t *lenp, loff_t *ppos) in proc_dointvec_jiffies() argument
1385 return -ENOSYS; in proc_dointvec_jiffies()
1389 void *buffer, size_t *lenp, loff_t *ppos) in proc_dointvec_ms_jiffies_minmax() argument
1391 return -ENOSYS; in proc_dointvec_ms_jiffies_minmax()
1395 void *buffer, size_t *lenp, loff_t *ppos) in proc_dointvec_userhz_jiffies() argument
1397 return -ENOSYS; in proc_dointvec_userhz_jiffies()
1401 void *buffer, size_t *lenp, loff_t *ppos) in proc_dointvec_ms_jiffies() argument
1403 return -ENOSYS; in proc_dointvec_ms_jiffies()
1407 void *buffer, size_t *lenp, loff_t *ppos) in proc_doulongvec_minmax() argument
1409 return -ENOSYS; in proc_doulongvec_minmax()
1413 void *buffer, size_t *lenp, loff_t *ppos) in proc_doulongvec_ms_jiffies_minmax() argument
1415 return -ENOSYS; in proc_doulongvec_ms_jiffies_minmax()
1419 void *buffer, size_t *lenp, loff_t *ppos) in proc_do_large_bitmap() argument
1421 return -ENOSYS; in proc_do_large_bitmap()
1428 void *buffer, size_t *lenp, loff_t *ppos) in proc_do_static_key() argument
1430 struct static_key *key = (struct static_key *)table->data; in proc_do_static_key()
1436 .mode = table->mode, in proc_do_static_key()
1442 return -EPERM; in proc_do_static_key()
1446 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); in proc_do_static_key()
1485 .procname = "unaligned-trap",
1494 .procname = "ignore-unaligned-usertrap",
1512 * exception granted :-)