]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
net: ipv{6,4}: Remove the now superfluous sentinel elements from ctl_table array
authorJoel Granados <j.granados@samsung.com>
Wed, 1 May 2024 09:29:26 +0000 (11:29 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 3 May 2024 12:29:42 +0000 (13:29 +0100)
This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/ZO5Yx5JFogGi%2FcBo@bombadil.infradead.org/)

* Remove sentinel element from ctl_table structs.
* Remove the zeroing out of an array element (to make it look like a
  sentinel) in sysctl_route_net_init And ipv6_route_sysctl_init.
  This is not longer needed and is safe after commit c899710fe7f9
  ("networking: Update to register_net_sysctl_sz") added the array size
  to the ctl_table registration.
* Remove extra sentinel element in the declaration of devinet_vars.
* Removed the "-1" in __devinet_sysctl_register, sysctl_route_net_init,
  ipv6_sysctl_net_init and ipv4_sysctl_init_net that adjusted for having
  an extra empty element when looping over ctl_table arrays
* Replace the for loop stop condition in __addrconf_sysctl_register that
  tests for procname == NULL with one that depends on array size
* Removing the unprivileged user check in ipv6_route_sysctl_init is
  safe as it is replaced by calling ipv6_route_sysctl_table_size;
  introduced in commit c899710fe7f9 ("networking: Update to
  register_net_sysctl_sz")
* Use a table_size variable to keep the value of ARRAY_SIZE

Signed-off-by: Joel Granados <j.granados@samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/devinet.c
net/ipv4/ip_fragment.c
net/ipv4/route.c
net/ipv4/sysctl_net_ipv4.c
net/ipv4/xfrm4_policy.c
net/ipv6/addrconf.c
net/ipv6/icmp.c
net/ipv6/reassembly.c
net/ipv6/route.c
net/ipv6/sysctl_net_ipv6.c
net/ipv6/xfrm6_policy.c

index 364dbf0cd9bf2f6e96a221317c88dad965209659..a612c57b61c5f6910e3f09eb0670753deaa53a04 100644 (file)
@@ -2520,7 +2520,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
 
 static struct devinet_sysctl_table {
        struct ctl_table_header *sysctl_header;
-       struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
+       struct ctl_table devinet_vars[IPV4_DEVCONF_MAX];
 } devinet_sysctl = {
        .devinet_vars = {
                DEVINET_SYSCTL_COMPLEX_ENTRY(FORWARDING, "forwarding",
@@ -2583,7 +2583,7 @@ static int __devinet_sysctl_register(struct net *net, char *dev_name,
        if (!t)
                goto out;
 
-       for (i = 0; i < ARRAY_SIZE(t->devinet_vars) - 1; i++) {
+       for (i = 0; i < ARRAY_SIZE(t->devinet_vars); i++) {
                t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf;
                t->devinet_vars[i].extra1 = p;
                t->devinet_vars[i].extra2 = net;
@@ -2657,7 +2657,6 @@ static struct ctl_table ctl_forward_entry[] = {
                .extra1         = &ipv4_devconf,
                .extra2         = &init_net,
        },
-       { },
 };
 #endif
 
index 534b98a0744a70706a5bff47612f17f1f30795d0..08e2c92e25ab5626a0fb84bbe39c4e4d85cf41db 100644 (file)
@@ -580,7 +580,6 @@ static struct ctl_table ip4_frags_ns_ctl_table[] = {
                .proc_handler   = proc_dointvec_minmax,
                .extra1         = &dist_min,
        },
-       { }
 };
 
 /* secret interval has been deprecated */
@@ -593,7 +592,6 @@ static struct ctl_table ip4_frags_ctl_table[] = {
                .mode           = 0644,
                .proc_handler   = proc_dointvec_jiffies,
        },
-       { }
 };
 
 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
index 0fd9a3d7ac4ab44962c0f254d9fa2a7964143443..5fd54103174f72d24d8015ad69029cebdd50740f 100644 (file)
@@ -3496,7 +3496,6 @@ static struct ctl_table ipv4_route_table[] = {
                .mode           = 0644,
                .proc_handler   = proc_dointvec,
        },
-       { }
 };
 
 static const char ipv4_route_flush_procname[] = "flush";
@@ -3530,7 +3529,6 @@ static struct ctl_table ipv4_route_netns_table[] = {
                .mode       = 0644,
                .proc_handler   = proc_dointvec,
        },
-       { },
 };
 
 static __net_init int sysctl_route_net_init(struct net *net)
@@ -3548,16 +3546,14 @@ static __net_init int sysctl_route_net_init(struct net *net)
 
                /* Don't export non-whitelisted sysctls to unprivileged users */
                if (net->user_ns != &init_user_ns) {
-                       if (tbl[0].procname != ipv4_route_flush_procname) {
-                               tbl[0].procname = NULL;
+                       if (tbl[0].procname != ipv4_route_flush_procname)
                                table_size = 0;
-                       }
                }
 
                /* Update the variables to point into the current struct net
                 * except for the first element flush
                 */
-               for (i = 1; i < ARRAY_SIZE(ipv4_route_netns_table) - 1; i++)
+               for (i = 1; i < table_size; i++)
                        tbl[i].data += (void *)net - (void *)&init_net;
        }
        tbl[0].extra1 = net;
index ce5d19978a2608eebd77f03b4c83f4f47794c01d..162a0a3b6ba52b6c5893dc403c615f407ae9bbf3 100644 (file)
@@ -575,7 +575,6 @@ static struct ctl_table ipv4_table[] = {
                .extra1         = &sysctl_fib_sync_mem_min,
                .extra2         = &sysctl_fib_sync_mem_max,
        },
-       { }
 };
 
 static struct ctl_table ipv4_net_table[] = {
@@ -1502,11 +1501,11 @@ static struct ctl_table ipv4_net_table[] = {
                .proc_handler   = proc_dou8vec_minmax,
                .extra1         = SYSCTL_ONE,
        },
-       { }
 };
 
 static __net_init int ipv4_sysctl_init_net(struct net *net)
 {
+       size_t table_size = ARRAY_SIZE(ipv4_net_table);
        struct ctl_table *table;
 
        table = ipv4_net_table;
@@ -1517,7 +1516,7 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
                if (!table)
                        goto err_alloc;
 
-               for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) {
+               for (i = 0; i < table_size; i++) {
                        if (table[i].data) {
                                /* Update the variables to point into
                                 * the current struct net
@@ -1533,7 +1532,7 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
        }
 
        net->ipv4.ipv4_hdr = register_net_sysctl_sz(net, "net/ipv4", table,
-                                                   ARRAY_SIZE(ipv4_net_table));
+                                                   table_size);
        if (!net->ipv4.ipv4_hdr)
                goto err_reg;
 
index fccbbd3e1a4b60671e468ef67737f21519aecaf7..0294fef577fab134c451d6180cd8aab87fc8ab01 100644 (file)
@@ -152,7 +152,6 @@ static struct ctl_table xfrm4_policy_table[] = {
                .mode           = 0644,
                .proc_handler   = proc_dointvec,
        },
-       { }
 };
 
 static __net_init int xfrm4_net_sysctl_init(struct net *net)
index 9aa0900abfa1731ae361eb0ed355a5874e449861..5c424a0e7232faa854f5b661319b8f7f182a60b8 100644 (file)
@@ -7184,14 +7184,12 @@ static const struct ctl_table addrconf_sysctl[] = {
                .extra1         = SYSCTL_ZERO,
                .extra2         = SYSCTL_TWO,
        },
-       {
-               /* sentinel */
-       }
 };
 
 static int __addrconf_sysctl_register(struct net *net, char *dev_name,
                struct inet6_dev *idev, struct ipv6_devconf *p)
 {
+       size_t table_size = ARRAY_SIZE(addrconf_sysctl);
        int i, ifindex;
        struct ctl_table *table;
        char path[sizeof("net/ipv6/conf/") + IFNAMSIZ];
@@ -7200,7 +7198,7 @@ static int __addrconf_sysctl_register(struct net *net, char *dev_name,
        if (!table)
                goto out;
 
-       for (i = 0; table[i].data; i++) {
+       for (i = 0; i < table_size; i++) {
                table[i].data += (char *)p - (char *)&ipv6_devconf;
                /* If one of these is already set, then it is not safe to
                 * overwrite either of them: this makes proc_dointvec_minmax
@@ -7215,7 +7213,7 @@ static int __addrconf_sysctl_register(struct net *net, char *dev_name,
        snprintf(path, sizeof(path), "net/ipv6/conf/%s", dev_name);
 
        p->sysctl_header = register_net_sysctl_sz(net, path, table,
-                                                 ARRAY_SIZE(addrconf_sysctl));
+                                                 table_size);
        if (!p->sysctl_header)
                goto free;
 
index d285c1f6f1a618e430148167fb0f40de5b7dd72e..7b31674644efc338ec458d92dfe495480825b0fd 100644 (file)
@@ -1206,7 +1206,6 @@ static struct ctl_table ipv6_icmp_table_template[] = {
                .extra1         = SYSCTL_ZERO,
                .extra2         = SYSCTL_ONE,
        },
-       { },
 };
 
 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
index ee95cdcc87479817a4cafe8268af65ead7b617be..439f93512b0ab98a5edab8910714e4f1d8cdaaec 100644 (file)
@@ -436,7 +436,6 @@ static struct ctl_table ip6_frags_ns_ctl_table[] = {
                .mode           = 0644,
                .proc_handler   = proc_dointvec_jiffies,
        },
-       { }
 };
 
 /* secret interval has been deprecated */
@@ -449,7 +448,6 @@ static struct ctl_table ip6_frags_ctl_table[] = {
                .mode           = 0644,
                .proc_handler   = proc_dointvec_jiffies,
        },
-       { }
 };
 
 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
index 3e0b2cb20fd201fd6a4da68817adaf3f0b349a42..c43b0616742ebafff841a491c26c7a56c0f20735 100644 (file)
@@ -6428,7 +6428,6 @@ static struct ctl_table ipv6_route_table_template[] = {
                .extra1         =       SYSCTL_ZERO,
                .extra2         =       SYSCTL_ONE,
        },
-       { }
 };
 
 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
@@ -6452,10 +6451,6 @@ struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
                table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss;
                table[9].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval;
                table[10].data = &net->ipv6.sysctl.skip_notify_on_dev_down;
-
-               /* Don't export sysctls to unprivileged users */
-               if (net->user_ns != &init_user_ns)
-                       table[1].procname = NULL;
        }
 
        return table;
index 75de55f907b079788cb8d0588069940d411920d4..c060285ff47f1d3b6fb73b9f1bb904d36043348d 100644 (file)
@@ -213,7 +213,6 @@ static struct ctl_table ipv6_table_template[] = {
                .proc_handler   = proc_doulongvec_minmax,
                .extra2         = &ioam6_id_wide_max,
        },
-       { }
 };
 
 static struct ctl_table ipv6_rotable[] = {
@@ -248,11 +247,11 @@ static struct ctl_table ipv6_rotable[] = {
                .proc_handler   = proc_dointvec,
        },
 #endif /* CONFIG_NETLABEL */
-       { }
 };
 
 static int __net_init ipv6_sysctl_net_init(struct net *net)
 {
+       size_t table_size = ARRAY_SIZE(ipv6_table_template);
        struct ctl_table *ipv6_table;
        struct ctl_table *ipv6_route_table;
        struct ctl_table *ipv6_icmp_table;
@@ -264,7 +263,7 @@ static int __net_init ipv6_sysctl_net_init(struct net *net)
        if (!ipv6_table)
                goto out;
        /* Update the variables to point into the current struct net */
-       for (i = 0; i < ARRAY_SIZE(ipv6_table_template) - 1; i++)
+       for (i = 0; i < table_size; i++)
                ipv6_table[i].data += (void *)net - (void *)&init_net;
 
        ipv6_route_table = ipv6_route_sysctl_init(net);
@@ -276,8 +275,7 @@ static int __net_init ipv6_sysctl_net_init(struct net *net)
                goto out_ipv6_route_table;
 
        net->ipv6.sysctl.hdr = register_net_sysctl_sz(net, "net/ipv6",
-                                                     ipv6_table,
-                                                     ARRAY_SIZE(ipv6_table_template));
+                                                     ipv6_table, table_size);
        if (!net->ipv6.sysctl.hdr)
                goto out_ipv6_icmp_table;
 
index 7924e08ee142d136954b3388568354628435db29..cc885d3aa9e5947b0f087d599c97a020ba6fe385 100644 (file)
@@ -184,7 +184,6 @@ static struct ctl_table xfrm6_policy_table[] = {
                .mode           = 0644,
                .proc_handler   = proc_dointvec,
        },
-       { }
 };
 
 static int __net_init xfrm6_net_sysctl_init(struct net *net)