Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'sysctl-6.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctl

Pull sysctl updates from Joel Granados:
"sysctl ctl_table constification:

- Constifying ctl_table structs prevents the modification of
proc_handler function pointers. All ctl_table struct arguments are
const qualified in the sysctl API in such a way that the ctl_table
arrays being defined elsewhere and passed through sysctl can be
constified one-by-one.

We kick the constification off by qualifying user_table in
kernel/ucount.c and expect all the ctl_tables to be constified in
the coming releases.

Misc fixes:

- Adjust comments in two places to better reflect the code

- Remove superfluous dput calls

- Remove Luis from sysctl maintainership

- Replace comments about holding a lock with calls to
lockdep_assert_held"

* tag 'sysctl-6.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctl:
sysctl: Reduce dput(child) calls in proc_sys_fill_cache()
sysctl: Reorganize kerneldoc parameter names
ucounts: constify sysctl table user_table
sysctl: update comments to new registration APIs
MAINTAINERS: remove me from sysctl
sysctl: Convert locking comments to lockdep assertions
const_structs.checkpatch: add ctl_table
sysctl: make internal ctl_tables const
sysctl: allow registration of const struct ctl_table
sysctl: move internal interfaces to const struct ctl_table
bpf: Constify ctl_table argument of filter function

+73 -69
-1
MAINTAINERS
··· 18641 18641 F: tools/testing/selftests/proc/ 18642 18642 18643 18643 PROC SYSCTL 18644 - M: Luis Chamberlain <mcgrof@kernel.org> 18645 18644 M: Kees Cook <kees@kernel.org> 18646 18645 M: Joel Granados <joel.granados@kernel.org> 18647 18646 L: linux-kernel@vger.kernel.org
+1 -1
fs/proc/internal.h
··· 102 102 union proc_op op; 103 103 struct proc_dir_entry *pde; 104 104 struct ctl_table_header *sysctl; 105 - struct ctl_table *sysctl_entry; 105 + const struct ctl_table *sysctl_entry; 106 106 struct hlist_node sibling_inodes; 107 107 const struct proc_ns_operations *ns_ops; 108 108 struct inode vfs_inode;
+60 -53
fs/proc/proc_sysctl.c
··· 17 17 #include <linux/bpf-cgroup.h> 18 18 #include <linux/mount.h> 19 19 #include <linux/kmemleak.h> 20 + #include <linux/lockdep.h> 20 21 #include "internal.h" 21 22 22 23 #define list_for_each_table_entry(entry, header) \ ··· 34 33 * Support for permanently empty directories. 35 34 * Must be non-empty to avoid sharing an address with other tables. 36 35 */ 37 - static struct ctl_table sysctl_mount_point[] = { 36 + static const struct ctl_table sysctl_mount_point[] = { 38 37 { } 39 38 }; 40 39 ··· 68 67 wake_up_interruptible(&poll->wait); 69 68 } 70 69 71 - static struct ctl_table root_table[] = { 70 + static const struct ctl_table root_table[] = { 72 71 { 73 72 .procname = "", 74 73 .mode = S_IFDIR|S_IRUGO|S_IXUGO, ··· 89 88 90 89 static void drop_sysctl_table(struct ctl_table_header *header); 91 90 static int sysctl_follow_link(struct ctl_table_header **phead, 92 - struct ctl_table **pentry); 91 + const struct ctl_table **pentry); 93 92 static int insert_links(struct ctl_table_header *head); 94 93 static void put_links(struct ctl_table_header *header); 95 94 ··· 110 109 return cmp; 111 110 } 112 111 113 - /* Called under sysctl_lock */ 114 - static struct ctl_table *find_entry(struct ctl_table_header **phead, 112 + static const struct ctl_table *find_entry(struct ctl_table_header **phead, 115 113 struct ctl_dir *dir, const char *name, int namelen) 116 114 { 117 115 struct ctl_table_header *head; 118 - struct ctl_table *entry; 116 + const struct ctl_table *entry; 119 117 struct rb_node *node = dir->root.rb_node; 118 + 119 + lockdep_assert_held(&sysctl_lock); 120 120 121 121 while (node) 122 122 { ··· 143 141 return NULL; 144 142 } 145 143 146 - static int insert_entry(struct ctl_table_header *head, struct ctl_table *entry) 144 + static int insert_entry(struct ctl_table_header *head, const struct ctl_table *entry) 147 145 { 148 146 struct rb_node *node = &head->node[entry - head->ctl_table].node; 149 147 struct rb_node **p = &head->parent->root.rb_node; ··· 153 151 154 152 while (*p) { 155 153 struct ctl_table_header *parent_head; 156 - struct ctl_table *parent_entry; 154 + const struct ctl_table *parent_entry; 157 155 struct ctl_node *parent_node; 158 156 const char *parent_name; 159 157 int cmp; ··· 182 180 return 0; 183 181 } 184 182 185 - static void erase_entry(struct ctl_table_header *head, struct ctl_table *entry) 183 + static void erase_entry(struct ctl_table_header *head, const struct ctl_table *entry) 186 184 { 187 185 struct rb_node *node = &head->node[entry - head->ctl_table].node; 188 186 ··· 191 189 192 190 static void init_header(struct ctl_table_header *head, 193 191 struct ctl_table_root *root, struct ctl_table_set *set, 194 - struct ctl_node *node, struct ctl_table *table, size_t table_size) 192 + struct ctl_node *node, const struct ctl_table *table, size_t table_size) 195 193 { 196 194 head->ctl_table = table; 197 195 head->ctl_table_size = table_size; ··· 206 204 head->node = node; 207 205 INIT_HLIST_HEAD(&head->inodes); 208 206 if (node) { 209 - struct ctl_table *entry; 207 + const struct ctl_table *entry; 210 208 211 209 list_for_each_table_entry(entry, head) { 212 210 node->header = head; ··· 219 217 220 218 static void erase_header(struct ctl_table_header *head) 221 219 { 222 - struct ctl_table *entry; 220 + const struct ctl_table *entry; 223 221 224 222 list_for_each_table_entry(entry, head) 225 223 erase_entry(head, entry); ··· 227 225 228 226 static int insert_header(struct ctl_dir *dir, struct ctl_table_header *header) 229 227 { 230 - struct ctl_table *entry; 228 + const struct ctl_table *entry; 231 229 struct ctl_table_header *dir_h = &dir->header; 232 230 int err; 233 231 ··· 265 263 return err; 266 264 } 267 265 268 - /* called under sysctl_lock */ 269 266 static int use_table(struct ctl_table_header *p) 270 267 { 268 + lockdep_assert_held(&sysctl_lock); 269 + 271 270 if (unlikely(p->unregistering)) 272 271 return 0; 273 272 p->used++; 274 273 return 1; 275 274 } 276 275 277 - /* called under sysctl_lock */ 278 276 static void unuse_table(struct ctl_table_header *p) 279 277 { 278 + lockdep_assert_held(&sysctl_lock); 279 + 280 280 if (!--p->used) 281 281 if (unlikely(p->unregistering)) 282 282 complete(p->unregistering); ··· 289 285 proc_invalidate_siblings_dcache(&head->inodes, &sysctl_lock); 290 286 } 291 287 292 - /* called under sysctl_lock, will reacquire if has to wait */ 293 288 static void start_unregistering(struct ctl_table_header *p) 294 289 { 290 + /* will reacquire if has to wait */ 291 + lockdep_assert_held(&sysctl_lock); 292 + 295 293 /* 296 294 * if p->used is 0, nobody will ever touch that entry again; 297 295 * we'll eliminate all paths to it before dropping sysctl_lock ··· 350 344 return set; 351 345 } 352 346 353 - static struct ctl_table *lookup_entry(struct ctl_table_header **phead, 354 - struct ctl_dir *dir, 355 - const char *name, int namelen) 347 + static const struct ctl_table *lookup_entry(struct ctl_table_header **phead, 348 + struct ctl_dir *dir, 349 + const char *name, int namelen) 356 350 { 357 351 struct ctl_table_header *head; 358 - struct ctl_table *entry; 352 + const struct ctl_table *entry; 359 353 360 354 spin_lock(&sysctl_lock); 361 355 entry = find_entry(&head, dir, name, namelen); ··· 380 374 } 381 375 382 376 static void first_entry(struct ctl_dir *dir, 383 - struct ctl_table_header **phead, struct ctl_table **pentry) 377 + struct ctl_table_header **phead, const struct ctl_table **pentry) 384 378 { 385 379 struct ctl_table_header *head = NULL; 386 - struct ctl_table *entry = NULL; 380 + const struct ctl_table *entry = NULL; 387 381 struct ctl_node *ctl_node; 388 382 389 383 spin_lock(&sysctl_lock); ··· 397 391 *pentry = entry; 398 392 } 399 393 400 - static void next_entry(struct ctl_table_header **phead, struct ctl_table **pentry) 394 + static void next_entry(struct ctl_table_header **phead, const struct ctl_table **pentry) 401 395 { 402 396 struct ctl_table_header *head = *phead; 403 - struct ctl_table *entry = *pentry; 397 + const struct ctl_table *entry = *pentry; 404 398 struct ctl_node *ctl_node = &head->node[entry - head->ctl_table]; 405 399 406 400 spin_lock(&sysctl_lock); ··· 433 427 return -EACCES; 434 428 } 435 429 436 - static int sysctl_perm(struct ctl_table_header *head, struct ctl_table *table, int op) 430 + static int sysctl_perm(struct ctl_table_header *head, const struct ctl_table *table, int op) 437 431 { 438 432 struct ctl_table_root *root = head->root; 439 433 int mode; ··· 447 441 } 448 442 449 443 static struct inode *proc_sys_make_inode(struct super_block *sb, 450 - struct ctl_table_header *head, struct ctl_table *table) 444 + struct ctl_table_header *head, const struct ctl_table *table) 451 445 { 452 446 struct ctl_table_root *root = head->root; 453 447 struct inode *inode; ··· 518 512 struct ctl_table_header *head = grab_header(dir); 519 513 struct ctl_table_header *h = NULL; 520 514 const struct qstr *name = &dentry->d_name; 521 - struct ctl_table *p; 515 + const struct ctl_table *p; 522 516 struct inode *inode; 523 517 struct dentry *err = ERR_PTR(-ENOENT); 524 518 struct ctl_dir *ctl_dir; ··· 556 550 { 557 551 struct inode *inode = file_inode(iocb->ki_filp); 558 552 struct ctl_table_header *head = grab_header(inode); 559 - struct ctl_table *table = PROC_I(inode)->sysctl_entry; 553 + const struct ctl_table *table = PROC_I(inode)->sysctl_entry; 560 554 size_t count = iov_iter_count(iter); 561 555 char *kbuf; 562 556 ssize_t error; ··· 630 624 static int proc_sys_open(struct inode *inode, struct file *filp) 631 625 { 632 626 struct ctl_table_header *head = grab_header(inode); 633 - struct ctl_table *table = PROC_I(inode)->sysctl_entry; 627 + const struct ctl_table *table = PROC_I(inode)->sysctl_entry; 634 628 635 629 /* sysctl was unregistered */ 636 630 if (IS_ERR(head)) ··· 648 642 { 649 643 struct inode *inode = file_inode(filp); 650 644 struct ctl_table_header *head = grab_header(inode); 651 - struct ctl_table *table = PROC_I(inode)->sysctl_entry; 645 + const struct ctl_table *table = PROC_I(inode)->sysctl_entry; 652 646 __poll_t ret = DEFAULT_POLLMASK; 653 647 unsigned long event; 654 648 ··· 679 673 static bool proc_sys_fill_cache(struct file *file, 680 674 struct dir_context *ctx, 681 675 struct ctl_table_header *head, 682 - struct ctl_table *table) 676 + const struct ctl_table *table) 683 677 { 684 678 struct dentry *child, *dir = file->f_path.dentry; 685 679 struct inode *inode; ··· 704 698 res = d_splice_alias(inode, child); 705 699 d_lookup_done(child); 706 700 if (unlikely(res)) { 707 - if (IS_ERR(res)) { 708 - dput(child); 709 - return false; 710 - } 711 701 dput(child); 702 + 703 + if (IS_ERR(res)) 704 + return false; 705 + 712 706 child = res; 713 707 } 714 708 } ··· 723 717 static bool proc_sys_link_fill_cache(struct file *file, 724 718 struct dir_context *ctx, 725 719 struct ctl_table_header *head, 726 - struct ctl_table *table) 720 + const struct ctl_table *table) 727 721 { 728 722 bool ret = true; 729 723 ··· 741 735 return ret; 742 736 } 743 737 744 - static int scan(struct ctl_table_header *head, struct ctl_table *table, 738 + static int scan(struct ctl_table_header *head, const struct ctl_table *table, 745 739 unsigned long *pos, struct file *file, 746 740 struct dir_context *ctx) 747 741 { ··· 765 759 { 766 760 struct ctl_table_header *head = grab_header(file_inode(file)); 767 761 struct ctl_table_header *h = NULL; 768 - struct ctl_table *entry; 762 + const struct ctl_table *entry; 769 763 struct ctl_dir *ctl_dir; 770 764 unsigned long pos; 771 765 ··· 798 792 * are _NOT_ writeable, capabilities or not. 799 793 */ 800 794 struct ctl_table_header *head; 801 - struct ctl_table *table; 795 + const struct ctl_table *table; 802 796 int error; 803 797 804 798 /* Executable files are not allowed under /proc/sys/ */ ··· 842 836 { 843 837 struct inode *inode = d_inode(path->dentry); 844 838 struct ctl_table_header *head = grab_header(inode); 845 - struct ctl_table *table = PROC_I(inode)->sysctl_entry; 839 + const struct ctl_table *table = PROC_I(inode)->sysctl_entry; 846 840 847 841 if (IS_ERR(head)) 848 842 return PTR_ERR(head); ··· 941 935 const char *name, int namelen) 942 936 { 943 937 struct ctl_table_header *head; 944 - struct ctl_table *entry; 938 + const struct ctl_table *entry; 945 939 946 940 entry = find_entry(&head, dir, name, namelen); 947 941 if (!entry) ··· 1052 1046 } 1053 1047 1054 1048 static int sysctl_follow_link(struct ctl_table_header **phead, 1055 - struct ctl_table **pentry) 1049 + const struct ctl_table **pentry) 1056 1050 { 1057 1051 struct ctl_table_header *head; 1052 + const struct ctl_table *entry; 1058 1053 struct ctl_table_root *root; 1059 1054 struct ctl_table_set *set; 1060 - struct ctl_table *entry; 1061 1055 struct ctl_dir *dir; 1062 1056 int ret; 1063 1057 ··· 1084 1078 return ret; 1085 1079 } 1086 1080 1087 - static int sysctl_err(const char *path, struct ctl_table *table, char *fmt, ...) 1081 + static int sysctl_err(const char *path, const struct ctl_table *table, char *fmt, ...) 1088 1082 { 1089 1083 struct va_format vaf; 1090 1084 va_list args; ··· 1100 1094 return -EINVAL; 1101 1095 } 1102 1096 1103 - static int sysctl_check_table_array(const char *path, struct ctl_table *table) 1097 + static int sysctl_check_table_array(const char *path, const struct ctl_table *table) 1104 1098 { 1105 1099 unsigned int extra; 1106 1100 int err = 0; ··· 1139 1133 1140 1134 static int sysctl_check_table(const char *path, struct ctl_table_header *header) 1141 1135 { 1142 - struct ctl_table *entry; 1136 + const struct ctl_table *entry; 1143 1137 int err = 0; 1144 1138 list_for_each_table_entry(entry, header) { 1145 1139 if (!entry->procname) ··· 1175 1169 1176 1170 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table_header *head) 1177 1171 { 1178 - struct ctl_table *link_table, *entry, *link; 1172 + struct ctl_table *link_table, *link; 1179 1173 struct ctl_table_header *links; 1174 + const struct ctl_table *entry; 1180 1175 struct ctl_node *node; 1181 1176 char *link_name; 1182 1177 int name_bytes; ··· 1222 1215 struct ctl_table_root *link_root) 1223 1216 { 1224 1217 struct ctl_table_header *tmp_head; 1225 - struct ctl_table *entry, *link; 1218 + const struct ctl_table *entry, *link; 1226 1219 1227 1220 if (header->ctl_table_size == 0 || 1228 1221 sysctl_is_perm_empty_ctl_header(header)) ··· 1365 1358 */ 1366 1359 struct ctl_table_header *__register_sysctl_table( 1367 1360 struct ctl_table_set *set, 1368 - const char *path, struct ctl_table *table, size_t table_size) 1361 + const char *path, const struct ctl_table *table, size_t table_size) 1369 1362 { 1370 1363 struct ctl_table_root *root = set->dir.header.root; 1371 1364 struct ctl_table_header *header; ··· 1426 1419 * 1427 1420 * See __register_sysctl_table for more details. 1428 1421 */ 1429 - struct ctl_table_header *register_sysctl_sz(const char *path, struct ctl_table *table, 1422 + struct ctl_table_header *register_sysctl_sz(const char *path, const struct ctl_table *table, 1430 1423 size_t table_size) 1431 1424 { 1432 1425 return __register_sysctl_table(&sysctl_table_root.default_set, ··· 1455 1448 * 1456 1449 * Context: if your base directory does not exist it will be created for you. 1457 1450 */ 1458 - void __init __register_sysctl_init(const char *path, struct ctl_table *table, 1451 + void __init __register_sysctl_init(const char *path, const struct ctl_table *table, 1459 1452 const char *table_name, size_t table_size) 1460 1453 { 1461 1454 struct ctl_table_header *hdr = register_sysctl_sz(path, table, table_size); ··· 1473 1466 struct ctl_table_root *root = header->root; 1474 1467 struct ctl_dir *parent = header->parent; 1475 1468 struct ctl_dir *core_parent; 1476 - struct ctl_table *entry; 1469 + const struct ctl_table *entry; 1477 1470 1478 1471 if (header->set == root_set) 1479 1472 return; ··· 1484 1477 1485 1478 list_for_each_table_entry(entry, header) { 1486 1479 struct ctl_table_header *link_head; 1487 - struct ctl_table *link; 1480 + const struct ctl_table *link; 1488 1481 const char *name = entry->procname; 1489 1482 1490 1483 link = find_entry(&link_head, core_parent, name, strlen(name));
+1 -1
include/linux/bpf-cgroup.h
··· 138 138 short access, enum cgroup_bpf_attach_type atype); 139 139 140 140 int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head, 141 - struct ctl_table *table, int write, 141 + const struct ctl_table *table, int write, 142 142 char **buf, size_t *pcount, loff_t *ppos, 143 143 enum cgroup_bpf_attach_type atype); 144 144
+8 -10
include/linux/sysctl.h
··· 90 90 91 91 /* 92 92 * Register a set of sysctl names by calling register_sysctl 93 - * with an initialised array of struct ctl_table's. An entry with 94 - * NULL procname terminates the table. table->de will be 95 - * set up by the registration and need not be initialised in advance. 93 + * with an initialised array of struct ctl_table's. 96 94 * 97 95 * sysctl names can be mirrored automatically under /proc/sys. The 98 96 * procname supplied controls /proc naming. ··· 131 133 132 134 /* A sysctl table is an array of struct ctl_table: */ 133 135 struct ctl_table { 134 - const char *procname; /* Text ID for /proc/sys, or zero */ 136 + const char *procname; /* Text ID for /proc/sys */ 135 137 void *data; 136 138 int maxlen; 137 139 umode_t mode; ··· 160 162 struct ctl_table_header { 161 163 union { 162 164 struct { 163 - struct ctl_table *ctl_table; 165 + const struct ctl_table *ctl_table; 164 166 int ctl_table_size; 165 167 int used; 166 168 int count; ··· 221 223 222 224 struct ctl_table_header *__register_sysctl_table( 223 225 struct ctl_table_set *set, 224 - const char *path, struct ctl_table *table, size_t table_size); 225 - struct ctl_table_header *register_sysctl_sz(const char *path, struct ctl_table *table, 226 + const char *path, const struct ctl_table *table, size_t table_size); 227 + struct ctl_table_header *register_sysctl_sz(const char *path, const struct ctl_table *table, 226 228 size_t table_size); 227 229 void unregister_sysctl_table(struct ctl_table_header * table); 228 230 229 231 extern int sysctl_init_bases(void); 230 - extern void __register_sysctl_init(const char *path, struct ctl_table *table, 232 + extern void __register_sysctl_init(const char *path, const struct ctl_table *table, 231 233 const char *table_name, size_t table_size); 232 234 #define register_sysctl_init(path, table) \ 233 235 __register_sysctl_init(path, table, #table, ARRAY_SIZE(table)) ··· 249 251 250 252 #else /* CONFIG_SYSCTL */ 251 253 252 - static inline void register_sysctl_init(const char *path, struct ctl_table *table) 254 + static inline void register_sysctl_init(const char *path, const struct ctl_table *table) 253 255 { 254 256 } 255 257 ··· 259 261 } 260 262 261 263 static inline struct ctl_table_header *register_sysctl_sz(const char *path, 262 - struct ctl_table *table, 264 + const struct ctl_table *table, 263 265 size_t table_size) 264 266 { 265 267 return NULL;
+1 -1
kernel/bpf/cgroup.c
··· 1708 1708 * returned value != 1 during execution. In all other cases 0 is returned. 1709 1709 */ 1710 1710 int __cgroup_bpf_run_filter_sysctl(struct ctl_table_header *head, 1711 - struct ctl_table *table, int write, 1711 + const struct ctl_table *table, int write, 1712 1712 char **buf, size_t *pcount, loff_t *ppos, 1713 1713 enum cgroup_bpf_attach_type atype) 1714 1714 {
-1
kernel/sysctl.c
··· 1305 1305 * @write: %TRUE if this is a write to the sysctl file 1306 1306 * @buffer: the user buffer 1307 1307 * @lenp: the size of the user buffer 1308 - * @ppos: file position 1309 1308 * @ppos: the current position in the file 1310 1309 * 1311 1310 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
+1 -1
kernel/ucount.c
··· 70 70 .extra1 = &ue_zero, \ 71 71 .extra2 = &ue_int_max, \ 72 72 } 73 - static struct ctl_table user_table[] = { 73 + static const struct ctl_table user_table[] = { 74 74 UCOUNT_ENTRY("max_user_namespaces"), 75 75 UCOUNT_ENTRY("max_pid_namespaces"), 76 76 UCOUNT_ENTRY("max_uts_namespaces"),
+1
scripts/const_structs.checkpatch
··· 6 6 clk_ops 7 7 comedi_lrange 8 8 component_ops 9 + ctl_table 9 10 dentry_operations 10 11 dev_pm_ops 11 12 device_type