staticstruct ctl_table_header *net_header;
__init int net_sysctl_init(void)
{ staticstruct ctl_table empty[1]; int ret = -ENOMEM; /* Avoid limitations in the sysctl implementation by * registering "/proc/sys/net" as an empty directory not in a * network namespace.
*/
net_header = register_sysctl_sz("net", empty, 0); if (!net_header) goto out;
ret = register_pernet_subsys(&sysctl_pernet_ops); if (ret) goto out1;
out: return ret;
out1:
unregister_sysctl_table(net_header);
net_header = NULL; goto out;
}
/* Verify that sysctls for non-init netns are safe by either: * 1) being read-only, or * 2) having a data pointer which points outside of the global kernel/module * data segment, and rather into the heap where a per-net object was * allocated.
*/ staticvoid ensure_safe_net_sysctl(struct net *net, constchar *path, struct ctl_table *table, size_t table_size)
{ struct ctl_table *ent;
pr_debug("Registering net sysctl (net %p): %s\n", net, path);
ent = table; for (size_t i = 0; i < table_size; ent++, i++) { unsignedlong addr; constchar *where;
/* If it's not writable inside the netns, then it can't hurt. */ if ((ent->mode & 0222) == 0) {
pr_debug(" Not writable by anyone\n"); continue;
}
/* Where does data point? */
addr = (unsignedlong)ent->data; if (is_module_address(addr))
where = "module"; elseif (is_kernel_core_data(addr))
where = "kernel"; else continue;
/* If it is writable and points to kernel/module global * data, then it's probably a netns leak.
*/
WARN(1, "sysctl %s/%s: data points to %s global data: %ps\n",
path, ent->procname, where, ent->data);
/* Make it "safe" by dropping writable perms */
ent->mode &= ~0222;
}
}
struct ctl_table_header *register_net_sysctl_sz(struct net *net, constchar *path, struct ctl_table *table,
size_t table_size)
{ if (!net_eq(net, &init_net))
ensure_safe_net_sysctl(net, path, table, table_size);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.