^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * NET4: Sysctl interface to net af_unix subsystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Authors: Mike Shaver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/sysctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <net/af_unix.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) static struct ctl_table unix_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) .procname = "max_dgram_qlen",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) .data = &init_net.unx.sysctl_max_dgram_qlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) .maxlen = sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) .mode = 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) .proc_handler = proc_dointvec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) int __net_init unix_sysctl_register(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct ctl_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) if (table == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) goto err_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* Don't export sysctls to unprivileged users */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if (net->user_ns != &init_user_ns)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) table[0].procname = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) table[0].data = &net->unx.sysctl_max_dgram_qlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) net->unx.ctl = register_net_sysctl(net, "net/unix", table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (net->unx.ctl == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) goto err_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) err_reg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) kfree(table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) err_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) void unix_sysctl_unregister(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct ctl_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) table = net->unx.ctl->ctl_table_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) unregister_net_sysctl_table(net->unx.ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) kfree(table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }