sysctl.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* SCTP kernel implementation
  3. * (C) Copyright IBM Corp. 2002, 2004
  4. * Copyright (c) 2002 Intel Corp.
  5. *
  6. * This file is part of the SCTP kernel implementation
  7. *
  8. * Sysctl related interfaces for SCTP.
  9. *
  10. * Please send any bug reports or fixes you make to the
  11. * email address(es):
  12. * lksctp developers <linux-sctp@vger.kernel.org>
  13. *
  14. * Written or modified by:
  15. * Mingqin Liu <liuming@us.ibm.com>
  16. * Jon Grimm <jgrimm@us.ibm.com>
  17. * Ardelle Fan <ardelle.fan@intel.com>
  18. * Ryan Layer <rmlayer@us.ibm.com>
  19. * Sridhar Samudrala <sri@us.ibm.com>
  20. */
  21. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  22. #include <net/sctp/structs.h>
  23. #include <net/sctp/sctp.h>
  24. #include <linux/sysctl.h>
  25. static int timer_max = 86400000; /* ms in one day */
  26. static int sack_timer_min = 1;
  27. static int sack_timer_max = 500;
  28. static int addr_scope_max = SCTP_SCOPE_POLICY_MAX;
  29. static int rwnd_scale_max = 16;
  30. static int rto_alpha_min = 0;
  31. static int rto_beta_min = 0;
  32. static int rto_alpha_max = 1000;
  33. static int rto_beta_max = 1000;
  34. static int pf_expose_max = SCTP_PF_EXPOSE_MAX;
  35. static int ps_retrans_max = SCTP_PS_RETRANS_MAX;
  36. static unsigned long max_autoclose_min = 0;
  37. static unsigned long max_autoclose_max =
  38. (MAX_SCHEDULE_TIMEOUT / HZ > UINT_MAX)
  39. ? UINT_MAX : MAX_SCHEDULE_TIMEOUT / HZ;
  40. static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
  41. void *buffer, size_t *lenp, loff_t *ppos);
  42. static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
  43. void *buffer, size_t *lenp, loff_t *ppos);
  44. static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write, void *buffer,
  45. size_t *lenp, loff_t *ppos);
  46. static int proc_sctp_do_alpha_beta(struct ctl_table *ctl, int write,
  47. void *buffer, size_t *lenp, loff_t *ppos);
  48. static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
  49. void *buffer, size_t *lenp, loff_t *ppos);
  50. static struct ctl_table sctp_table[] = {
  51. {
  52. .procname = "sctp_mem",
  53. .data = &sysctl_sctp_mem,
  54. .maxlen = sizeof(sysctl_sctp_mem),
  55. .mode = 0644,
  56. .proc_handler = proc_doulongvec_minmax
  57. },
  58. {
  59. .procname = "sctp_rmem",
  60. .data = &sysctl_sctp_rmem,
  61. .maxlen = sizeof(sysctl_sctp_rmem),
  62. .mode = 0644,
  63. .proc_handler = proc_dointvec,
  64. },
  65. {
  66. .procname = "sctp_wmem",
  67. .data = &sysctl_sctp_wmem,
  68. .maxlen = sizeof(sysctl_sctp_wmem),
  69. .mode = 0644,
  70. .proc_handler = proc_dointvec,
  71. },
  72. { /* sentinel */ }
  73. };
  74. static struct ctl_table sctp_net_table[] = {
  75. {
  76. .procname = "rto_initial",
  77. .data = &init_net.sctp.rto_initial,
  78. .maxlen = sizeof(unsigned int),
  79. .mode = 0644,
  80. .proc_handler = proc_dointvec_minmax,
  81. .extra1 = SYSCTL_ONE,
  82. .extra2 = &timer_max
  83. },
  84. {
  85. .procname = "rto_min",
  86. .data = &init_net.sctp.rto_min,
  87. .maxlen = sizeof(unsigned int),
  88. .mode = 0644,
  89. .proc_handler = proc_sctp_do_rto_min,
  90. .extra1 = SYSCTL_ONE,
  91. .extra2 = &init_net.sctp.rto_max
  92. },
  93. {
  94. .procname = "rto_max",
  95. .data = &init_net.sctp.rto_max,
  96. .maxlen = sizeof(unsigned int),
  97. .mode = 0644,
  98. .proc_handler = proc_sctp_do_rto_max,
  99. .extra1 = &init_net.sctp.rto_min,
  100. .extra2 = &timer_max
  101. },
  102. {
  103. .procname = "rto_alpha_exp_divisor",
  104. .data = &init_net.sctp.rto_alpha,
  105. .maxlen = sizeof(int),
  106. .mode = 0644,
  107. .proc_handler = proc_sctp_do_alpha_beta,
  108. .extra1 = &rto_alpha_min,
  109. .extra2 = &rto_alpha_max,
  110. },
  111. {
  112. .procname = "rto_beta_exp_divisor",
  113. .data = &init_net.sctp.rto_beta,
  114. .maxlen = sizeof(int),
  115. .mode = 0644,
  116. .proc_handler = proc_sctp_do_alpha_beta,
  117. .extra1 = &rto_beta_min,
  118. .extra2 = &rto_beta_max,
  119. },
  120. {
  121. .procname = "max_burst",
  122. .data = &init_net.sctp.max_burst,
  123. .maxlen = sizeof(int),
  124. .mode = 0644,
  125. .proc_handler = proc_dointvec_minmax,
  126. .extra1 = SYSCTL_ZERO,
  127. .extra2 = SYSCTL_INT_MAX,
  128. },
  129. {
  130. .procname = "cookie_preserve_enable",
  131. .data = &init_net.sctp.cookie_preserve_enable,
  132. .maxlen = sizeof(int),
  133. .mode = 0644,
  134. .proc_handler = proc_dointvec,
  135. },
  136. {
  137. .procname = "cookie_hmac_alg",
  138. .data = &init_net.sctp.sctp_hmac_alg,
  139. .maxlen = 8,
  140. .mode = 0644,
  141. .proc_handler = proc_sctp_do_hmac_alg,
  142. },
  143. {
  144. .procname = "valid_cookie_life",
  145. .data = &init_net.sctp.valid_cookie_life,
  146. .maxlen = sizeof(unsigned int),
  147. .mode = 0644,
  148. .proc_handler = proc_dointvec_minmax,
  149. .extra1 = SYSCTL_ONE,
  150. .extra2 = &timer_max
  151. },
  152. {
  153. .procname = "sack_timeout",
  154. .data = &init_net.sctp.sack_timeout,
  155. .maxlen = sizeof(int),
  156. .mode = 0644,
  157. .proc_handler = proc_dointvec_minmax,
  158. .extra1 = &sack_timer_min,
  159. .extra2 = &sack_timer_max,
  160. },
  161. {
  162. .procname = "hb_interval",
  163. .data = &init_net.sctp.hb_interval,
  164. .maxlen = sizeof(unsigned int),
  165. .mode = 0644,
  166. .proc_handler = proc_dointvec_minmax,
  167. .extra1 = SYSCTL_ONE,
  168. .extra2 = &timer_max
  169. },
  170. {
  171. .procname = "association_max_retrans",
  172. .data = &init_net.sctp.max_retrans_association,
  173. .maxlen = sizeof(int),
  174. .mode = 0644,
  175. .proc_handler = proc_dointvec_minmax,
  176. .extra1 = SYSCTL_ONE,
  177. .extra2 = SYSCTL_INT_MAX,
  178. },
  179. {
  180. .procname = "path_max_retrans",
  181. .data = &init_net.sctp.max_retrans_path,
  182. .maxlen = sizeof(int),
  183. .mode = 0644,
  184. .proc_handler = proc_dointvec_minmax,
  185. .extra1 = SYSCTL_ONE,
  186. .extra2 = SYSCTL_INT_MAX,
  187. },
  188. {
  189. .procname = "max_init_retransmits",
  190. .data = &init_net.sctp.max_retrans_init,
  191. .maxlen = sizeof(int),
  192. .mode = 0644,
  193. .proc_handler = proc_dointvec_minmax,
  194. .extra1 = SYSCTL_ONE,
  195. .extra2 = SYSCTL_INT_MAX,
  196. },
  197. {
  198. .procname = "pf_retrans",
  199. .data = &init_net.sctp.pf_retrans,
  200. .maxlen = sizeof(int),
  201. .mode = 0644,
  202. .proc_handler = proc_dointvec_minmax,
  203. .extra1 = SYSCTL_ZERO,
  204. .extra2 = &init_net.sctp.ps_retrans,
  205. },
  206. {
  207. .procname = "ps_retrans",
  208. .data = &init_net.sctp.ps_retrans,
  209. .maxlen = sizeof(int),
  210. .mode = 0644,
  211. .proc_handler = proc_dointvec_minmax,
  212. .extra1 = &init_net.sctp.pf_retrans,
  213. .extra2 = &ps_retrans_max,
  214. },
  215. {
  216. .procname = "sndbuf_policy",
  217. .data = &init_net.sctp.sndbuf_policy,
  218. .maxlen = sizeof(int),
  219. .mode = 0644,
  220. .proc_handler = proc_dointvec,
  221. },
  222. {
  223. .procname = "rcvbuf_policy",
  224. .data = &init_net.sctp.rcvbuf_policy,
  225. .maxlen = sizeof(int),
  226. .mode = 0644,
  227. .proc_handler = proc_dointvec,
  228. },
  229. {
  230. .procname = "default_auto_asconf",
  231. .data = &init_net.sctp.default_auto_asconf,
  232. .maxlen = sizeof(int),
  233. .mode = 0644,
  234. .proc_handler = proc_dointvec,
  235. },
  236. {
  237. .procname = "addip_enable",
  238. .data = &init_net.sctp.addip_enable,
  239. .maxlen = sizeof(int),
  240. .mode = 0644,
  241. .proc_handler = proc_dointvec,
  242. },
  243. {
  244. .procname = "addip_noauth_enable",
  245. .data = &init_net.sctp.addip_noauth,
  246. .maxlen = sizeof(int),
  247. .mode = 0644,
  248. .proc_handler = proc_dointvec,
  249. },
  250. {
  251. .procname = "prsctp_enable",
  252. .data = &init_net.sctp.prsctp_enable,
  253. .maxlen = sizeof(int),
  254. .mode = 0644,
  255. .proc_handler = proc_dointvec,
  256. },
  257. {
  258. .procname = "reconf_enable",
  259. .data = &init_net.sctp.reconf_enable,
  260. .maxlen = sizeof(int),
  261. .mode = 0644,
  262. .proc_handler = proc_dointvec,
  263. },
  264. {
  265. .procname = "auth_enable",
  266. .data = &init_net.sctp.auth_enable,
  267. .maxlen = sizeof(int),
  268. .mode = 0644,
  269. .proc_handler = proc_sctp_do_auth,
  270. },
  271. {
  272. .procname = "intl_enable",
  273. .data = &init_net.sctp.intl_enable,
  274. .maxlen = sizeof(int),
  275. .mode = 0644,
  276. .proc_handler = proc_dointvec,
  277. },
  278. {
  279. .procname = "ecn_enable",
  280. .data = &init_net.sctp.ecn_enable,
  281. .maxlen = sizeof(int),
  282. .mode = 0644,
  283. .proc_handler = proc_dointvec,
  284. },
  285. {
  286. .procname = "addr_scope_policy",
  287. .data = &init_net.sctp.scope_policy,
  288. .maxlen = sizeof(int),
  289. .mode = 0644,
  290. .proc_handler = proc_dointvec_minmax,
  291. .extra1 = SYSCTL_ZERO,
  292. .extra2 = &addr_scope_max,
  293. },
  294. {
  295. .procname = "rwnd_update_shift",
  296. .data = &init_net.sctp.rwnd_upd_shift,
  297. .maxlen = sizeof(int),
  298. .mode = 0644,
  299. .proc_handler = &proc_dointvec_minmax,
  300. .extra1 = SYSCTL_ONE,
  301. .extra2 = &rwnd_scale_max,
  302. },
  303. {
  304. .procname = "max_autoclose",
  305. .data = &init_net.sctp.max_autoclose,
  306. .maxlen = sizeof(unsigned long),
  307. .mode = 0644,
  308. .proc_handler = &proc_doulongvec_minmax,
  309. .extra1 = &max_autoclose_min,
  310. .extra2 = &max_autoclose_max,
  311. },
  312. {
  313. .procname = "pf_enable",
  314. .data = &init_net.sctp.pf_enable,
  315. .maxlen = sizeof(int),
  316. .mode = 0644,
  317. .proc_handler = proc_dointvec,
  318. },
  319. {
  320. .procname = "pf_expose",
  321. .data = &init_net.sctp.pf_expose,
  322. .maxlen = sizeof(int),
  323. .mode = 0644,
  324. .proc_handler = proc_dointvec_minmax,
  325. .extra1 = SYSCTL_ZERO,
  326. .extra2 = &pf_expose_max,
  327. },
  328. { /* sentinel */ }
  329. };
  330. static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
  331. void *buffer, size_t *lenp, loff_t *ppos)
  332. {
  333. struct net *net = current->nsproxy->net_ns;
  334. struct ctl_table tbl;
  335. bool changed = false;
  336. char *none = "none";
  337. char tmp[8] = {0};
  338. int ret;
  339. memset(&tbl, 0, sizeof(struct ctl_table));
  340. if (write) {
  341. tbl.data = tmp;
  342. tbl.maxlen = sizeof(tmp);
  343. } else {
  344. tbl.data = net->sctp.sctp_hmac_alg ? : none;
  345. tbl.maxlen = strlen(tbl.data);
  346. }
  347. ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
  348. if (write && ret == 0) {
  349. #ifdef CONFIG_CRYPTO_MD5
  350. if (!strncmp(tmp, "md5", 3)) {
  351. net->sctp.sctp_hmac_alg = "md5";
  352. changed = true;
  353. }
  354. #endif
  355. #ifdef CONFIG_CRYPTO_SHA1
  356. if (!strncmp(tmp, "sha1", 4)) {
  357. net->sctp.sctp_hmac_alg = "sha1";
  358. changed = true;
  359. }
  360. #endif
  361. if (!strncmp(tmp, "none", 4)) {
  362. net->sctp.sctp_hmac_alg = NULL;
  363. changed = true;
  364. }
  365. if (!changed)
  366. ret = -EINVAL;
  367. }
  368. return ret;
  369. }
  370. static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
  371. void *buffer, size_t *lenp, loff_t *ppos)
  372. {
  373. struct net *net = current->nsproxy->net_ns;
  374. unsigned int min = *(unsigned int *) ctl->extra1;
  375. unsigned int max = *(unsigned int *) ctl->extra2;
  376. struct ctl_table tbl;
  377. int ret, new_value;
  378. memset(&tbl, 0, sizeof(struct ctl_table));
  379. tbl.maxlen = sizeof(unsigned int);
  380. if (write)
  381. tbl.data = &new_value;
  382. else
  383. tbl.data = &net->sctp.rto_min;
  384. ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
  385. if (write && ret == 0) {
  386. if (new_value > max || new_value < min)
  387. return -EINVAL;
  388. net->sctp.rto_min = new_value;
  389. }
  390. return ret;
  391. }
  392. static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
  393. void *buffer, size_t *lenp, loff_t *ppos)
  394. {
  395. struct net *net = current->nsproxy->net_ns;
  396. unsigned int min = *(unsigned int *) ctl->extra1;
  397. unsigned int max = *(unsigned int *) ctl->extra2;
  398. struct ctl_table tbl;
  399. int ret, new_value;
  400. memset(&tbl, 0, sizeof(struct ctl_table));
  401. tbl.maxlen = sizeof(unsigned int);
  402. if (write)
  403. tbl.data = &new_value;
  404. else
  405. tbl.data = &net->sctp.rto_max;
  406. ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
  407. if (write && ret == 0) {
  408. if (new_value > max || new_value < min)
  409. return -EINVAL;
  410. net->sctp.rto_max = new_value;
  411. }
  412. return ret;
  413. }
  414. static int proc_sctp_do_alpha_beta(struct ctl_table *ctl, int write,
  415. void *buffer, size_t *lenp, loff_t *ppos)
  416. {
  417. if (write)
  418. pr_warn_once("Changing rto_alpha or rto_beta may lead to "
  419. "suboptimal rtt/srtt estimations!\n");
  420. return proc_dointvec_minmax(ctl, write, buffer, lenp, ppos);
  421. }
  422. static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
  423. void *buffer, size_t *lenp, loff_t *ppos)
  424. {
  425. struct net *net = current->nsproxy->net_ns;
  426. struct ctl_table tbl;
  427. int new_value, ret;
  428. memset(&tbl, 0, sizeof(struct ctl_table));
  429. tbl.maxlen = sizeof(unsigned int);
  430. if (write)
  431. tbl.data = &new_value;
  432. else
  433. tbl.data = &net->sctp.auth_enable;
  434. ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
  435. if (write && ret == 0) {
  436. struct sock *sk = net->sctp.ctl_sock;
  437. net->sctp.auth_enable = new_value;
  438. /* Update the value in the control socket */
  439. lock_sock(sk);
  440. sctp_sk(sk)->ep->auth_enable = new_value;
  441. release_sock(sk);
  442. }
  443. return ret;
  444. }
  445. int sctp_sysctl_net_register(struct net *net)
  446. {
  447. struct ctl_table *table;
  448. int i;
  449. table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
  450. if (!table)
  451. return -ENOMEM;
  452. for (i = 0; table[i].data; i++)
  453. table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
  454. net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
  455. if (net->sctp.sysctl_header == NULL) {
  456. kfree(table);
  457. return -ENOMEM;
  458. }
  459. return 0;
  460. }
  461. void sctp_sysctl_net_unregister(struct net *net)
  462. {
  463. struct ctl_table *table;
  464. table = net->sctp.sysctl_header->ctl_table_arg;
  465. unregister_net_sysctl_table(net->sctp.sysctl_header);
  466. kfree(table);
  467. }
  468. static struct ctl_table_header *sctp_sysctl_header;
  469. /* Sysctl registration. */
  470. void sctp_sysctl_register(void)
  471. {
  472. sctp_sysctl_header = register_net_sysctl(&init_net, "net/sctp", sctp_table);
  473. }
  474. /* Sysctl deregistration. */
  475. void sctp_sysctl_unregister(void)
  476. {
  477. unregister_net_sysctl_table(sctp_sysctl_header);
  478. }