const qualify the struct ctl_table argument in the proc_handler function signatures. This is a prerequisite to moving the static ctl_table structs into .rodata data which will ensure that proc_handler function pointers cannot be modified. This patch has been generated by the following coccinelle script: ``` virtual patch @r1@ identifier ctl, write, buffer, lenp, ppos; identifier func !~ "appldata_(timer|interval)_handler|sched_(rt|rr)_handler|rds_tcp_skbuf_handler|proc_sctp_do_(hmac_alg|rto_min|rto_max|udp_port|alpha_beta|auth|probe_interval)"; @@ int func( - struct ctl_table *ctl + const struct ctl_table *ctl ,int write, void *buffer, size_t *lenp, loff_t *ppos); @r2@ identifier func, ctl, write, buffer, lenp, ppos; @@ int func( - struct ctl_table *ctl + const struct ctl_table *ctl ,int write, void *buffer, size_t *lenp, loff_t *ppos) { ... } @r3@ identifier func; @@ int func( - struct ctl_table * + const struct ctl_table * ,int , void *, size_t *, loff_t *); @r4@ identifier func, ctl; @@ int func( - struct ctl_table *ctl + const struct ctl_table *ctl ,int , void *, size_t *, loff_t *); @r5@ identifier func, write, buffer, lenp, ppos; @@ int func( - struct ctl_table * + const struct ctl_table * ,int write, void *buffer, size_t *lenp, loff_t *ppos); ``` * Code formatting was adjusted in xfs_sysctl.c to comply with code conventions. The xfs_stats_clear_proc_handler, xfs_panic_mask_proc_handler and xfs_deprecated_dointvec_minmax where adjusted. * The ctl_table argument in proc_watchdog_common was const qualified. This is called from a proc_handler itself and is calling back into another proc_handler, making it necessary to change it as part of the proc_handler migration.
Showing the changes to kernel/sysctl.c (1 of 93 files). Show all
Unified · Split
| @@ -256,7 +256,7 @@ static bool proc_first_pos_non_zero_ignore(loff_t *ppos, · 255 unmodified lines | |||
| 256 | * | 256 | * |
| 257 | * Returns 0 on success. | 257 | * Returns 0 on success. |
| 258 | */ | 258 | */ |
| 259 | int proc_dostring(struct ctl_table *table, int write, | 259 | int proc_dostring(const struct ctl_table *table, int write, |
| 260 | void *buffer, size_t *lenp, loff_t *ppos) | 260 | void *buffer, size_t *lenp, loff_t *ppos) |
| 261 | { | 261 | { |
| 262 | if (write) | 262 | if (write) |
| @@ -702,7 +702,7 @@ int do_proc_douintvec(const struct ctl_table *table, int write, · 439 unmodified lines | |||
| 702 | * | 702 | * |
| 703 | * Returns 0 on success. | 703 | * Returns 0 on success. |
| 704 | */ | 704 | */ |
| 705 | int proc_dobool(struct ctl_table *table, int write, void *buffer, | 705 | int proc_dobool(const struct ctl_table *table, int write, void *buffer, |
| 706 | size_t *lenp, loff_t *ppos) | 706 | size_t *lenp, loff_t *ppos) |
| 707 | { | 707 | { |
| 708 | struct ctl_table tmp; | 708 | struct ctl_table tmp; |
| @@ -739,7 +739,7 @@ int proc_dobool(struct ctl_table *table, int write, void *buffer, · 30 unmodified lines | |||
| 739 | * | 739 | * |
| 740 | * Returns 0 on success. | 740 | * Returns 0 on success. |
| 741 | */ | 741 | */ |
| 742 | int proc_dointvec(struct ctl_table *table, int write, void *buffer, | 742 | int proc_dointvec(const struct ctl_table *table, int write, void *buffer, |
| 743 | size_t *lenp, loff_t *ppos) | 743 | size_t *lenp, loff_t *ppos) |
| 744 | { | 744 | { |
| 745 | return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL); | 745 | return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL); |
| @@ -758,7 +758,7 @@ int proc_dointvec(struct ctl_table *table, int write, void *buffer, · 12 unmodified lines | |||
| 758 | * | 758 | * |
| 759 | * Returns 0 on success. | 759 | * Returns 0 on success. |
| 760 | */ | 760 | */ |
| 761 | int proc_douintvec(struct ctl_table *table, int write, void *buffer, | 761 | int proc_douintvec(const struct ctl_table *table, int write, void *buffer, |
| 762 | size_t *lenp, loff_t *ppos) | 762 | size_t *lenp, loff_t *ppos) |
| 763 | { | 763 | { |
| 764 | return do_proc_douintvec(table, write, buffer, lenp, ppos, | 764 | return do_proc_douintvec(table, write, buffer, lenp, ppos, |
| @@ -769,7 +769,7 @@ int proc_douintvec(struct ctl_table *table, int write, void *buffer, · 4 unmodified lines | |||
| 769 | * Taint values can only be increased | 769 | * Taint values can only be increased |
| 770 | * This means we can safely use a temporary. | 770 | * This means we can safely use a temporary. |
| 771 | */ | 771 | */ |
| 772 | static int proc_taint(struct ctl_table *table, int write, | 772 | static int proc_taint(const struct ctl_table *table, int write, |
| 773 | void *buffer, size_t *lenp, loff_t *ppos) | 773 | void *buffer, size_t *lenp, loff_t *ppos) |
| 774 | { | 774 | { |
| 775 | struct ctl_table t; | 775 | struct ctl_table t; |
| @@ -864,7 +864,7 @@ static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp, · 88 unmodified lines | |||
| 864 | * | 864 | * |
| 865 | * Returns 0 on success or -EINVAL on write when the range check fails. | 865 | * Returns 0 on success or -EINVAL on write when the range check fails. |
| 866 | */ | 866 | */ |
| 867 | int proc_dointvec_minmax(struct ctl_table *table, int write, | 867 | int proc_dointvec_minmax(const struct ctl_table *table, int write, |
| 868 | void *buffer, size_t *lenp, loff_t *ppos) | 868 | void *buffer, size_t *lenp, loff_t *ppos) |
| 869 | { | 869 | { |
| 870 | struct do_proc_dointvec_minmax_conv_param param = { | 870 | struct do_proc_dointvec_minmax_conv_param param = { |
| @@ -933,7 +933,7 @@ static int do_proc_douintvec_minmax_conv(unsigned long *lvalp, · 62 unmodified lines | |||
| 933 | * | 933 | * |
| 934 | * Returns 0 on success or -ERANGE on write when the range check fails. | 934 | * Returns 0 on success or -ERANGE on write when the range check fails. |
| 935 | */ | 935 | */ |
| 936 | int proc_douintvec_minmax(struct ctl_table *table, int write, | 936 | int proc_douintvec_minmax(const struct ctl_table *table, int write, |
| 937 | void *buffer, size_t *lenp, loff_t *ppos) | 937 | void *buffer, size_t *lenp, loff_t *ppos) |
| 938 | { | 938 | { |
| 939 | struct do_proc_douintvec_minmax_conv_param param = { | 939 | struct do_proc_douintvec_minmax_conv_param param = { |
| @@ -961,7 +961,7 @@ int proc_douintvec_minmax(struct ctl_table *table, int write, · 21 unmodified lines | |||
| 961 | * | 961 | * |
| 962 | * Returns 0 on success or an error on write when the range check fails. | 962 | * Returns 0 on success or an error on write when the range check fails. |
| 963 | */ | 963 | */ |
| 964 | int proc_dou8vec_minmax(struct ctl_table *table, int write, | 964 | int proc_dou8vec_minmax(const struct ctl_table *table, int write, |
| 965 | void *buffer, size_t *lenp, loff_t *ppos) | 965 | void *buffer, size_t *lenp, loff_t *ppos) |
| 966 | { | 966 | { |
| 967 | struct ctl_table tmp; | 967 | struct ctl_table tmp; |
| @@ -998,7 +998,7 @@ int proc_dou8vec_minmax(struct ctl_table *table, int write, · 30 unmodified lines | |||
| 998 | EXPORT_SYMBOL_GPL(proc_dou8vec_minmax); | 998 | EXPORT_SYMBOL_GPL(proc_dou8vec_minmax); |
| 999 | 999 | ||
| 1000 | #ifdef CONFIG_MAGIC_SYSRQ | 1000 | #ifdef CONFIG_MAGIC_SYSRQ |
| 1001 | static int sysrq_sysctl_handler(struct ctl_table *table, int write, | 1001 | static int sysrq_sysctl_handler(const struct ctl_table *table, int write, |
| 1002 | void *buffer, size_t *lenp, loff_t *ppos) | 1002 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1003 | { | 1003 | { |
| 1004 | int tmp, ret; | 1004 | int tmp, ret; |
| @@ -1115,7 +1115,7 @@ static int do_proc_doulongvec_minmax(const struct ctl_table *table, int write, · 110 unmodified lines | |||
| 1115 | * | 1115 | * |
| 1116 | * Returns 0 on success. | 1116 | * Returns 0 on success. |
| 1117 | */ | 1117 | */ |
| 1118 | int proc_doulongvec_minmax(struct ctl_table *table, int write, | 1118 | int proc_doulongvec_minmax(const struct ctl_table *table, int write, |
| 1119 | void *buffer, size_t *lenp, loff_t *ppos) | 1119 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1120 | { | 1120 | { |
| 1121 | return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l); | 1121 | return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l); |
| @@ -1138,7 +1138,7 @@ int proc_doulongvec_minmax(struct ctl_table *table, int write, · 16 unmodified lines | |||
| 1138 | * | 1138 | * |
| 1139 | * Returns 0 on success. | 1139 | * Returns 0 on success. |
| 1140 | */ | 1140 | */ |
| 1141 | int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, | 1141 | int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int write, |
| 1142 | void *buffer, size_t *lenp, loff_t *ppos) | 1142 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1143 | { | 1143 | { |
| 1144 | return do_proc_doulongvec_minmax(table, write, buffer, | 1144 | return do_proc_doulongvec_minmax(table, write, buffer, |
| @@ -1259,14 +1259,14 @@ static int do_proc_dointvec_ms_jiffies_minmax_conv(bool *negp, unsigned long *lv · 114 unmodified lines | |||
| 1259 | * | 1259 | * |
| 1260 | * Returns 0 on success. | 1260 | * Returns 0 on success. |
| 1261 | */ | 1261 | */ |
| 1262 | int proc_dointvec_jiffies(struct ctl_table *table, int write, | 1262 | int proc_dointvec_jiffies(const struct ctl_table *table, int write, |
| 1263 | void *buffer, size_t *lenp, loff_t *ppos) | 1263 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1264 | { | 1264 | { |
| 1265 | return do_proc_dointvec(table,write,buffer,lenp,ppos, | 1265 | return do_proc_dointvec(table,write,buffer,lenp,ppos, |
| 1266 | do_proc_dointvec_jiffies_conv,NULL); | 1266 | do_proc_dointvec_jiffies_conv,NULL); |
| 1267 | } | 1267 | } |
| 1268 | 1268 | ||
| 1269 | int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write, | 1269 | int proc_dointvec_ms_jiffies_minmax(const struct ctl_table *table, int write, |
| 1270 | void *buffer, size_t *lenp, loff_t *ppos) | 1270 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1271 | { | 1271 | { |
| 1272 | struct do_proc_dointvec_minmax_conv_param param = { | 1272 | struct do_proc_dointvec_minmax_conv_param param = { |
| @@ -1292,7 +1292,7 @@ int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write, · 19 unmodified lines | |||
| 1292 | * | 1292 | * |
| 1293 | * Returns 0 on success. | 1293 | * Returns 0 on success. |
| 1294 | */ | 1294 | */ |
| 1295 | int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, | 1295 | int proc_dointvec_userhz_jiffies(const struct ctl_table *table, int write, |
| 1296 | void *buffer, size_t *lenp, loff_t *ppos) | 1296 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1297 | { | 1297 | { |
| 1298 | return do_proc_dointvec(table, write, buffer, lenp, ppos, | 1298 | return do_proc_dointvec(table, write, buffer, lenp, ppos, |
| @@ -1315,14 +1315,14 @@ int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, · 16 unmodified lines | |||
| 1315 | * | 1315 | * |
| 1316 | * Returns 0 on success. | 1316 | * Returns 0 on success. |
| 1317 | */ | 1317 | */ |
| 1318 | int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer, | 1318 | int proc_dointvec_ms_jiffies(const struct ctl_table *table, int write, void *buffer, |
| 1319 | size_t *lenp, loff_t *ppos) | 1319 | size_t *lenp, loff_t *ppos) |
| 1320 | { | 1320 | { |
| 1321 | return do_proc_dointvec(table, write, buffer, lenp, ppos, | 1321 | return do_proc_dointvec(table, write, buffer, lenp, ppos, |
| 1322 | do_proc_dointvec_ms_jiffies_conv, NULL); | 1322 | do_proc_dointvec_ms_jiffies_conv, NULL); |
| 1323 | } | 1323 | } |
| 1324 | 1324 | ||
| 1325 | static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer, | 1325 | static int proc_do_cad_pid(const struct ctl_table *table, int write, void *buffer, |
| 1326 | size_t *lenp, loff_t *ppos) | 1326 | size_t *lenp, loff_t *ppos) |
| 1327 | { | 1327 | { |
| 1328 | struct pid *new_pid; | 1328 | struct pid *new_pid; |
| @@ -1361,7 +1361,7 @@ static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer, · 32 unmodified lines | |||
| 1361 | * | 1361 | * |
| 1362 | * Returns 0 on success. | 1362 | * Returns 0 on success. |
| 1363 | */ | 1363 | */ |
| 1364 | int proc_do_large_bitmap(struct ctl_table *table, int write, | 1364 | int proc_do_large_bitmap(const struct ctl_table *table, int write, |
| 1365 | void *buffer, size_t *lenp, loff_t *ppos) | 1365 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1366 | { | 1366 | { |
| 1367 | int err = 0; | 1367 | int err = 0; |
| @@ -1493,85 +1493,85 @@ int proc_do_large_bitmap(struct ctl_table *table, int write, · 125 unmodified lines | |||
| 1493 | 1493 | ||
| 1494 | #else /* CONFIG_PROC_SYSCTL */ | 1494 | #else /* CONFIG_PROC_SYSCTL */ |
| 1495 | 1495 | ||
| 1496 | int proc_dostring(struct ctl_table *table, int write, | 1496 | int proc_dostring(const struct ctl_table *table, int write, |
| 1497 | void *buffer, size_t *lenp, loff_t *ppos) | 1497 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1498 | { | 1498 | { |
| 1499 | return -ENOSYS; | 1499 | return -ENOSYS; |
| 1500 | } | 1500 | } |
| 1501 | 1501 | ||
| 1502 | int proc_dobool(struct ctl_table *table, int write, | 1502 | int proc_dobool(const struct ctl_table *table, int write, |
| 1503 | void *buffer, size_t *lenp, loff_t *ppos) | 1503 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1504 | { | 1504 | { |
| 1505 | return -ENOSYS; | 1505 | return -ENOSYS; |
| 1506 | } | 1506 | } |
| 1507 | 1507 | ||
| 1508 | int proc_dointvec(struct ctl_table *table, int write, | 1508 | int proc_dointvec(const struct ctl_table *table, int write, |
| 1509 | void *buffer, size_t *lenp, loff_t *ppos) | 1509 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1510 | { | 1510 | { |
| 1511 | return -ENOSYS; | 1511 | return -ENOSYS; |
| 1512 | } | 1512 | } |
| 1513 | 1513 | ||
| 1514 | int proc_douintvec(struct ctl_table *table, int write, | 1514 | int proc_douintvec(const struct ctl_table *table, int write, |
| 1515 | void *buffer, size_t *lenp, loff_t *ppos) | 1515 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1516 | { | 1516 | { |
| 1517 | return -ENOSYS; | 1517 | return -ENOSYS; |
| 1518 | } | 1518 | } |
| 1519 | 1519 | ||
| 1520 | int proc_dointvec_minmax(struct ctl_table *table, int write, | 1520 | int proc_dointvec_minmax(const struct ctl_table *table, int write, |
| 1521 | void *buffer, size_t *lenp, loff_t *ppos) | 1521 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1522 | { | 1522 | { |
| 1523 | return -ENOSYS; | 1523 | return -ENOSYS; |
| 1524 | } | 1524 | } |
| 1525 | 1525 | ||
| 1526 | int proc_douintvec_minmax(struct ctl_table *table, int write, | 1526 | int proc_douintvec_minmax(const struct ctl_table *table, int write, |
| 1527 | void *buffer, size_t *lenp, loff_t *ppos) | 1527 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1528 | { | 1528 | { |
| 1529 | return -ENOSYS; | 1529 | return -ENOSYS; |
| 1530 | } | 1530 | } |
| 1531 | 1531 | ||
| 1532 | int proc_dou8vec_minmax(struct ctl_table *table, int write, | 1532 | int proc_dou8vec_minmax(const struct ctl_table *table, int write, |
| 1533 | void *buffer, size_t *lenp, loff_t *ppos) | 1533 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1534 | { | 1534 | { |
| 1535 | return -ENOSYS; | 1535 | return -ENOSYS; |
| 1536 | } | 1536 | } |
| 1537 | 1537 | ||
| 1538 | int proc_dointvec_jiffies(struct ctl_table *table, int write, | 1538 | int proc_dointvec_jiffies(const struct ctl_table *table, int write, |
| 1539 | void *buffer, size_t *lenp, loff_t *ppos) | 1539 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1540 | { | 1540 | { |
| 1541 | return -ENOSYS; | 1541 | return -ENOSYS; |
| 1542 | } | 1542 | } |
| 1543 | 1543 | ||
| 1544 | int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write, | 1544 | int proc_dointvec_ms_jiffies_minmax(const struct ctl_table *table, int write, |
| 1545 | void *buffer, size_t *lenp, loff_t *ppos) | 1545 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1546 | { | 1546 | { |
| 1547 | return -ENOSYS; | 1547 | return -ENOSYS; |
| 1548 | } | 1548 | } |
| 1549 | 1549 | ||
| 1550 | int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, | 1550 | int proc_dointvec_userhz_jiffies(const struct ctl_table *table, int write, |
| 1551 | void *buffer, size_t *lenp, loff_t *ppos) | 1551 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1552 | { | 1552 | { |
| 1553 | return -ENOSYS; | 1553 | return -ENOSYS; |
| 1554 | } | 1554 | } |
| 1555 | 1555 | ||
| 1556 | int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, | 1556 | int proc_dointvec_ms_jiffies(const struct ctl_table *table, int write, |
| 1557 | void *buffer, size_t *lenp, loff_t *ppos) | 1557 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1558 | { | 1558 | { |
| 1559 | return -ENOSYS; | 1559 | return -ENOSYS; |
| 1560 | } | 1560 | } |
| 1561 | 1561 | ||
| 1562 | int proc_doulongvec_minmax(struct ctl_table *table, int write, | 1562 | int proc_doulongvec_minmax(const struct ctl_table *table, int write, |
| 1563 | void *buffer, size_t *lenp, loff_t *ppos) | 1563 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1564 | { | 1564 | { |
| 1565 | return -ENOSYS; | 1565 | return -ENOSYS; |
| 1566 | } | 1566 | } |
| 1567 | 1567 | ||
| 1568 | int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, | 1568 | int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int write, |
| 1569 | void *buffer, size_t *lenp, loff_t *ppos) | 1569 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1570 | { | 1570 | { |
| 1571 | return -ENOSYS; | 1571 | return -ENOSYS; |
| 1572 | } | 1572 | } |
| 1573 | 1573 | ||
| 1574 | int proc_do_large_bitmap(struct ctl_table *table, int write, | 1574 | int proc_do_large_bitmap(const struct ctl_table *table, int write, |
| 1575 | void *buffer, size_t *lenp, loff_t *ppos) | 1575 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1576 | { | 1576 | { |
| 1577 | return -ENOSYS; | 1577 | return -ENOSYS; |
| @@ -1580,7 +1580,7 @@ int proc_do_large_bitmap(struct ctl_table *table, int write, · 2 unmodified lines | |||
| 1580 | #endif /* CONFIG_PROC_SYSCTL */ | 1580 | #endif /* CONFIG_PROC_SYSCTL */ |
| 1581 | 1581 | ||
| 1582 | #if defined(CONFIG_SYSCTL) | 1582 | #if defined(CONFIG_SYSCTL) |
| 1583 | int proc_do_static_key(struct ctl_table *table, int write, | 1583 | int proc_do_static_key(const struct ctl_table *table, int write, |
| 1584 | void *buffer, size_t *lenp, loff_t *ppos) | 1584 | void *buffer, size_t *lenp, loff_t *ppos) |
| 1585 | { | 1585 | { |
| 1586 | struct static_key *key = (struct static_key *)table->data; | 1586 | struct static_key *key = (struct static_key *)table->data; |