sysctl_net_unix.c 1.1 KB

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