Lines Matching +full:write +full:- +full:1

1 // SPDX-License-Identifier: GPL-2.0-only
26 const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, 1000, 3000, INT_MAX, 65535, -1 };
29 const unsigned long sysctl_long_vals[] = { 0, 1, LONG_MAX };
41 * enum sysctl_writes_mode - supported sysctl write modes
43 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
51 * sent to the write syscall. If dealing with strings respect the file
56 * These write modes control how current file position affects the behavior of
58 * interface on each write.
61 SYSCTL_WRITES_LEGACY = -1,
63 SYSCTL_WRITES_STRICT = 1,
91 if (len > maxlen - 1) in _proc_do_string()
92 len = maxlen - 1; in _proc_do_string()
104 while ((p - buffer) < *lenp && len < maxlen - 1) { in _proc_do_string()
122 len -= *ppos; 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
175 * @dir: %TRUE if this is a write to the sysctl file
182 * string is truncated. The copied string is %NULL-terminated.
195 return _proc_do_string(table->data, table->maxlen, dir, buffer, lenp, in proc_dostring()
204 (*size)--; in proc_skip_spaces()
214 (*size)--; in proc_skip_char()
220 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
243 return -ERANGE; in strtoul_lenient()
256 * proc_get_long - reads an ASCII formatted integer from a user buffer
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
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()
303 * (e.g. 123...1). So lets not allow such large numbers. */ in proc_get_long()
304 if (len == TMPBUFLEN - 1) in proc_get_long()
305 return -EINVAL; in proc_get_long()
308 return -EINVAL; in proc_get_long()
314 *size -= len; in proc_get_long()
320 * proc_put_long - converts an integer to a decimal ASCII formatted string
335 sprintf(p, "%s%lu", neg ? "-" : "", val); in proc_put_long()
340 *size -= len; in proc_put_long()
351 (*size)--; in proc_put_char()
358 * proc_uint_u2k_conv_uop - Assign user value to a kernel pointer
376 return -EINVAL; in proc_uint_u2k_conv_uop()
382 * proc_uint_k2u_conv - Assign kernel value to a user space pointer
399 * proc_uint_conv - Change user or kernel pointer based on direction
403 * @dir: %TRUE if this is a write to the sysctl file
427 return -EINVAL; in proc_uint_conv()
431 if ((tbl->extra1 && in proc_uint_conv()
432 *(uint *)tbl->extra1 > tmp_k) || in proc_uint_conv()
433 (tbl->extra2 && in proc_uint_conv()
434 *(uint *)tbl->extra2 < tmp_k)) in proc_uint_conv()
435 return -ERANGE; in proc_uint_conv()
462 * proc_int_k2u_conv_kop - Assign kernel value to a user space pointer
481 *u_ptr = k_ptr_op ? -k_ptr_op((ulong)val) : -(ulong)val; in proc_int_k2u_conv_kop()
490 * proc_int_u2k_conv_uop - Assign user value to a kernel pointer
507 if (u > (ulong) INT_MAX + 1) in proc_int_u2k_conv_uop()
508 return -EINVAL; in proc_int_u2k_conv_uop()
509 WRITE_ONCE(*k_ptr, -u); in proc_int_u2k_conv_uop()
512 return -EINVAL; in proc_int_u2k_conv_uop()
530 return -EINVAL; in proc_int_conv()
534 if ((tbl->extra1 && *(int *)tbl->extra1 > tmp_k) || in proc_int_conv()
535 (tbl->extra2 && *(int *)tbl->extra2 < tmp_k)) in proc_int_conv()
536 return -EINVAL; in proc_int_conv()
580 int *i, vleft, first = 1, err = 0; in do_proc_dointvec()
584 if (!table->data || !table->maxlen || !*lenp || in do_proc_dointvec()
590 i = (int *) table->data; in do_proc_dointvec()
591 vleft = table->maxlen / sizeof(*i); in do_proc_dointvec()
601 if (left > PAGE_SIZE - 1) in do_proc_dointvec()
602 left = PAGE_SIZE - 1; in do_proc_dointvec()
606 for (; left && vleft--; i++, first=0) { in do_proc_dointvec()
620 if (conv(&neg, &lval, i, 1, table)) { in do_proc_dointvec()
621 err = -EINVAL; in do_proc_dointvec()
626 err = -EINVAL; in do_proc_dointvec()
640 return err ? : -EINVAL; in do_proc_dointvec()
641 *lenp -= left; in do_proc_dointvec()
664 if (left > PAGE_SIZE - 1) in do_proc_douintvec_w()
665 left = PAGE_SIZE - 1; in do_proc_douintvec_w()
669 err = -EINVAL; in do_proc_douintvec_w()
677 err = -EINVAL; in do_proc_douintvec_w()
681 if (conv(&lval, (unsigned int *) table->data, 1, table)) { in do_proc_douintvec_w()
682 err = -EINVAL; in do_proc_douintvec_w()
691 return -EINVAL; in do_proc_douintvec_w()
712 if (conv(&lval, (unsigned int *) table->data, 0, table)) { in do_proc_douintvec_r()
713 err = -EINVAL; in do_proc_douintvec_r()
724 *lenp -= left; in do_proc_douintvec_r()
738 if (!table->data || !table->maxlen || !*lenp || in do_proc_douintvec()
744 vleft = table->maxlen / sizeof(unsigned int); in do_proc_douintvec()
750 if (vleft != 1) { in do_proc_douintvec()
752 return -EINVAL; in do_proc_douintvec()
764 * proc_douintvec_conv - read a vector of unsigned ints with a custom converter
767 * @dir: %TRUE if this is a write to the sysctl file
773 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
788 * proc_dobool - read/write a bool
790 * @dir: %TRUE if this is a write to the sysctl file
798 * table->data must point to a bool variable and table->maxlen must
807 bool *data = table->data; in proc_dobool()
811 if (table->maxlen != sizeof(bool)) in proc_dobool()
812 return -EINVAL; in proc_dobool()
828 * proc_dointvec - read a vector of integers
830 * @dir: %TRUE if this is a write to the sysctl file
835 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
847 * proc_douintvec - read a vector of unsigned integers
849 * @dir: %TRUE if this is a write to the sysctl file
854 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
867 * proc_dointvec_minmax - read a vector of integers with min/max values
869 * @dir: %TRUE if this is a write to the sysctl file
874 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
878 * table->extra1 (min) and table->extra2 (max).
880 * Returns 0 on success or -EINVAL when the range check fails and
891 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
893 * @dir: %TRUE if this is a write to the sysctl file
898 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
903 * are within the range specified by table->extra1 (min) and table->extra2
907 * Returns 0 on success or -ERANGE when range check failes and
918 * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values
920 * @dir: %TRUE if this is a write to the sysctl file
925 * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars
930 * table->extra1 (min) and table->extra2 (max).
940 u8 *data = table->data; in proc_dou8vec_minmax()
944 if (table->maxlen != sizeof(u8)) in proc_dou8vec_minmax()
945 return -EINVAL; in proc_dou8vec_minmax()
973 int vleft, first = 1, err = 0; in do_proc_doulongvec_minmax()
977 if (!table->data || !table->maxlen || !*lenp || in do_proc_doulongvec_minmax()
983 i = table->data; in do_proc_doulongvec_minmax()
984 min = table->extra1; in do_proc_doulongvec_minmax()
985 max = table->extra2; in do_proc_doulongvec_minmax()
986 vleft = table->maxlen / sizeof(unsigned long); in do_proc_doulongvec_minmax()
993 if (left > PAGE_SIZE - 1) in do_proc_doulongvec_minmax()
994 left = PAGE_SIZE - 1; in do_proc_doulongvec_minmax()
998 for (; left && vleft--; i++, first = 0) { in do_proc_doulongvec_minmax()
1012 err = -EINVAL; in do_proc_doulongvec_minmax()
1018 err = -EINVAL; in do_proc_doulongvec_minmax()
1035 return err ? : -EINVAL; in do_proc_doulongvec_minmax()
1036 *lenp -= left; in do_proc_doulongvec_minmax()
1051 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1053 * @dir: %TRUE if this is a write to the sysctl file
1058 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1062 * table->extra1 (min) and table->extra2 (max).
1069 return proc_doulongvec_minmax_conv(table, dir, buffer, lenp, ppos, 1l, 1l); in proc_doulongvec_minmax()
1073 * proc_dointvec_conv - read a vector of ints with a custom converter
1075 * @dir: %TRUE if this is a write to the sysctl file
1081 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
1097 * proc_do_large_bitmap - read/write from/to a large bitmap
1099 * @dir: %TRUE if this is a write to the sysctl file
1104 * The bitmap is stored at table->data and the bitmap length (in bits)
1105 * in table->maxlen.
1107 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1118 unsigned long bitmap_len = table->maxlen; in proc_do_large_bitmap()
1119 unsigned long *bitmap = *(unsigned long **) table->data; in proc_do_large_bitmap()
1121 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c = 0; in proc_do_large_bitmap()
1132 if (left > PAGE_SIZE - 1) { in proc_do_large_bitmap()
1133 left = PAGE_SIZE - 1; in proc_do_large_bitmap()
1135 skipped = *lenp - left; in proc_do_large_bitmap()
1140 return -ENOMEM; in proc_do_large_bitmap()
1147 /* In case we stop parsing mid-number, we can reset */ in proc_do_large_bitmap()
1153 * only one char is left (may be a "-"), then stop here, in proc_do_large_bitmap()
1156 if ((left <= 1) && skipped) { in proc_do_large_bitmap()
1164 err = -EINVAL; in proc_do_large_bitmap()
1171 left--; in proc_do_large_bitmap()
1174 if (c == '-') { in proc_do_large_bitmap()
1191 err = -EINVAL; in proc_do_large_bitmap()
1196 left--; in proc_do_large_bitmap()
1200 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1); in proc_do_large_bitmap()
1206 bool first = 1; in proc_do_large_bitmap()
1213 bit_a + 1) - 1; in proc_do_large_bitmap()
1219 proc_put_char(&buffer, &left, '-'); in proc_do_large_bitmap()
1235 *lenp -= left; in proc_do_large_bitmap()
1248 return -ENOSYS; in proc_dostring()
1254 return -ENOSYS; in proc_dobool()
1260 return -ENOSYS; in proc_dointvec()
1266 return -ENOSYS; in proc_douintvec()
1272 return -ENOSYS; in proc_dointvec_minmax()
1278 return -ENOSYS; in proc_douintvec_minmax()
1281 int proc_douintvec_conv(const struct ctl_table *table, int write, void *buffer, in proc_douintvec_conv() argument
1284 int write, const struct ctl_table *table)) in proc_douintvec_conv()
1286 return -ENOSYS; in proc_douintvec_conv()
1291 return -ENOSYS; in proc_uint_k2u_conv()
1297 return -ENOSYS; in proc_uint_u2k_conv_uop()
1305 return -ENOSYS; in proc_uint_conv()
1311 return -ENOSYS; in proc_dou8vec_minmax()
1317 return -ENOSYS; in proc_doulongvec_minmax()
1324 return -ENOSYS; in proc_doulongvec_minmax_conv()
1332 return -ENOSYS; in proc_dointvec_conv()
1338 return -ENOSYS; in proc_do_large_bitmap()
1347 struct static_key *key = (struct static_key *)table->data; in proc_do_static_key()
1353 .mode = table->mode, in proc_do_static_key()
1359 return -EPERM; in proc_do_static_key()
1402 .procname = "unaligned-trap",
1411 .procname = "ignore-unaligned-usertrap",
1429 * exception granted :-)