Commit c899710f authored by Joel Granados's avatar Joel Granados Committed by Luis Chamberlain
Browse files

networking: Update to register_net_sysctl_sz



Move from register_net_sysctl to register_net_sysctl_sz for all the
networking related files. Do this while making sure to mirror the NULL
assignments with a table_size of zero for the unprivileged users.

We need to move to the new function in preparation for when we change
SIZE_MAX to ARRAY_SIZE() in the register_net_sysctl macro. Failing to do
so would erroneously allow ARRAY_SIZE() to be called on a pointer. We
hold off the SIZE_MAX to ARRAY_SIZE change until we have migrated all
the relevant net sysctl registering functions to register_net_sysctl_sz
in subsequent commits.

An additional size function was added to the following files in order to
calculate the size of an array that is defined in another file:
    include/net/ipv6.h
    net/ipv6/icmp.c
    net/ipv6/route.c
    net/ipv6/sysctl_net_ipv6.c

Signed-off-by: default avatarJoel Granados <j.granados@samsung.com>
Signed-off-by: default avatarLuis Chamberlain <mcgrof@kernel.org>
parent 385a5dc9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1274,7 +1274,9 @@ static inline int snmp6_unregister_dev(struct inet6_dev *idev) { return 0; }

#ifdef CONFIG_SYSCTL
struct ctl_table *ipv6_icmp_sysctl_init(struct net *net);
size_t ipv6_icmp_sysctl_table_size(void);
struct ctl_table *ipv6_route_sysctl_init(struct net *net);
size_t ipv6_route_sysctl_table_size(struct net *net);
int ipv6_sysctl_register(void);
void ipv6_sysctl_unregister(void);
#endif
+6 −2
Original line number Diff line number Diff line
@@ -3779,6 +3779,7 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
	const char *dev_name_source;
	char neigh_path[ sizeof("net//neigh/") + IFNAMSIZ + IFNAMSIZ ];
	char *p_name;
	size_t neigh_vars_size;

	t = kmemdup(&neigh_sysctl_template, sizeof(*t), GFP_KERNEL_ACCOUNT);
	if (!t)
@@ -3790,11 +3791,13 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
		t->neigh_vars[i].extra2 = p;
	}

	neigh_vars_size = ARRAY_SIZE(t->neigh_vars);
	if (dev) {
		dev_name_source = dev->name;
		/* Terminate the table early */
		memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
		       sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
		neigh_vars_size = NEIGH_VAR_BASE_REACHABLE_TIME_MS + 1;
	} else {
		struct neigh_table *tbl = p->tbl;
		dev_name_source = "default";
@@ -3841,8 +3844,9 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,

	snprintf(neigh_path, sizeof(neigh_path), "net/%s/neigh/%s",
		p_name, dev_name_source);
	t->sysctl_header =
		register_net_sysctl(neigh_parms_net(p), neigh_path, t->neigh_vars);
	t->sysctl_header = register_net_sysctl_sz(neigh_parms_net(p),
						  neigh_path, t->neigh_vars,
						  neigh_vars_size);
	if (!t->sysctl_header)
		goto free;

+2 −1
Original line number Diff line number Diff line
@@ -712,7 +712,8 @@ static __net_init int sysctl_core_net_init(struct net *net)
			tmp->data += (char *)net - (char *)&init_net;
	}

	net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
	net->core.sysctl_hdr = register_net_sysctl_sz(net, "net/core", tbl,
						      ARRAY_SIZE(netns_core_table));
	if (net->core.sysctl_hdr == NULL)
		goto err_reg;

+6 −2
Original line number Diff line number Diff line
@@ -360,6 +360,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
	struct ctl_table_header *hdr;
	struct netns_ieee802154_lowpan *ieee802154_lowpan =
		net_ieee802154_lowpan(net);
	size_t table_size = ARRAY_SIZE(lowpan_frags_ns_ctl_table);

	table = lowpan_frags_ns_ctl_table;
	if (!net_eq(net, &init_net)) {
@@ -369,8 +370,10 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
			goto err_alloc;

		/* Don't export sysctls to unprivileged users */
		if (net->user_ns != &init_user_ns)
		if (net->user_ns != &init_user_ns) {
			table[0].procname = NULL;
			table_size = 0;
		}
	}

	table[0].data	= &ieee802154_lowpan->fqdir->high_thresh;
@@ -379,7 +382,8 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
	table[1].extra2	= &ieee802154_lowpan->fqdir->high_thresh;
	table[2].data	= &ieee802154_lowpan->fqdir->timeout;

	hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
	hdr = register_net_sysctl_sz(net, "net/ieee802154/6lowpan", table,
				     table_size);
	if (hdr == NULL)
		goto err_reg;

+2 −1
Original line number Diff line number Diff line
@@ -2720,7 +2720,8 @@ static __net_init int devinet_init_net(struct net *net)
		goto err_reg_dflt;

	err = -ENOMEM;
	forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
	forw_hdr = register_net_sysctl_sz(net, "net/ipv4", tbl,
					  ARRAY_SIZE(ctl_forward_entry));
	if (!forw_hdr)
		goto err_reg_ctl;
	net->ipv4.forw_hdr = forw_hdr;
Loading