902-debloat_proc.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. From 9e3f1d0805b2d919904dd9a4ff0d956314cc3cba Mon Sep 17 00:00:00 2001
  2. From: Felix Fietkau <[email protected]>
  3. Date: Sat, 8 Jul 2017 08:20:09 +0200
  4. Subject: debloat: procfs
  5. Signed-off-by: Felix Fietkau <[email protected]>
  6. ---
  7. fs/locks.c | 2 ++
  8. fs/proc/Kconfig | 5 +++++
  9. fs/proc/consoles.c | 3 +++
  10. fs/proc/proc_tty.c | 11 ++++++++++-
  11. include/net/snmp.h | 18 +++++++++++++++++-
  12. ipc/msg.c | 3 +++
  13. ipc/sem.c | 2 ++
  14. ipc/shm.c | 2 ++
  15. ipc/util.c | 3 +++
  16. kernel/exec_domain.c | 2 ++
  17. kernel/irq/proc.c | 9 +++++++++
  18. kernel/time/timer_list.c | 2 ++
  19. mm/vmalloc.c | 2 ++
  20. mm/vmstat.c | 8 +++++---
  21. net/8021q/vlanproc.c | 6 ++++++
  22. net/core/net-procfs.c | 18 ++++++++++++------
  23. net/core/sock.c | 2 ++
  24. net/ipv4/fib_trie.c | 18 ++++++++++++------
  25. net/ipv4/proc.c | 3 +++
  26. net/ipv4/route.c | 3 +++
  27. 20 files changed, 105 insertions(+), 17 deletions(-)
  28. --- a/fs/locks.c
  29. +++ b/fs/locks.c
  30. @@ -2786,6 +2786,8 @@ static const struct seq_operations locks
  31. static int __init proc_locks_init(void)
  32. {
  33. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  34. + return 0;
  35. proc_create_seq_private("locks", 0, NULL, &locks_seq_operations,
  36. sizeof(struct locks_iterator), NULL);
  37. return 0;
  38. --- a/fs/proc/Kconfig
  39. +++ b/fs/proc/Kconfig
  40. @@ -97,3 +97,8 @@ config PROC_CHILDREN
  41. Say Y if you are running any user-space software which takes benefit from
  42. this interface. For example, rkt is such a piece of software.
  43. +
  44. +config PROC_STRIPPED
  45. + default n
  46. + depends on EXPERT
  47. + bool "Strip non-essential /proc functionality to reduce code size"
  48. --- a/fs/proc/consoles.c
  49. +++ b/fs/proc/consoles.c
  50. @@ -93,6 +93,9 @@ static const struct seq_operations conso
  51. static int __init proc_consoles_init(void)
  52. {
  53. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  54. + return 0;
  55. +
  56. proc_create_seq("consoles", 0, NULL, &consoles_op);
  57. return 0;
  58. }
  59. --- a/fs/proc/proc_tty.c
  60. +++ b/fs/proc/proc_tty.c
  61. @@ -133,7 +133,10 @@ static const struct seq_operations tty_d
  62. void proc_tty_register_driver(struct tty_driver *driver)
  63. {
  64. struct proc_dir_entry *ent;
  65. -
  66. +
  67. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  68. + return;
  69. +
  70. if (!driver->driver_name || driver->proc_entry ||
  71. !driver->ops->proc_show)
  72. return;
  73. @@ -150,6 +153,9 @@ void proc_tty_unregister_driver(struct t
  74. {
  75. struct proc_dir_entry *ent;
  76. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  77. + return;
  78. +
  79. ent = driver->proc_entry;
  80. if (!ent)
  81. return;
  82. @@ -164,6 +170,9 @@ void proc_tty_unregister_driver(struct t
  83. */
  84. void __init proc_tty_init(void)
  85. {
  86. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  87. + return;
  88. +
  89. if (!proc_mkdir("tty", NULL))
  90. return;
  91. proc_mkdir("tty/ldisc", NULL); /* Preserved: it's userspace visible */
  92. --- a/include/net/snmp.h
  93. +++ b/include/net/snmp.h
  94. @@ -123,6 +123,21 @@ struct linux_xfrm_mib {
  95. #define DECLARE_SNMP_STAT(type, name) \
  96. extern __typeof__(type) __percpu *name
  97. +#ifdef CONFIG_PROC_STRIPPED
  98. +#define __SNMP_STATS_DUMMY(mib) \
  99. + do { (void) mib->mibs[0]; } while(0)
  100. +
  101. +#define __SNMP_INC_STATS(mib, field) __SNMP_STATS_DUMMY(mib)
  102. +#define SNMP_INC_STATS_ATOMIC_LONG(mib, field) __SNMP_STATS_DUMMY(mib)
  103. +#define SNMP_INC_STATS(mib, field) __SNMP_STATS_DUMMY(mib)
  104. +#define SNMP_DEC_STATS(mib, field) __SNMP_STATS_DUMMY(mib)
  105. +#define __SNMP_ADD_STATS(mib, field, addend) __SNMP_STATS_DUMMY(mib)
  106. +#define SNMP_ADD_STATS(mib, field, addend) __SNMP_STATS_DUMMY(mib)
  107. +#define SNMP_UPD_PO_STATS(mib, basefield, addend) __SNMP_STATS_DUMMY(mib)
  108. +#define __SNMP_UPD_PO_STATS(mib, basefield, addend) __SNMP_STATS_DUMMY(mib)
  109. +
  110. +#else
  111. +
  112. #define __SNMP_INC_STATS(mib, field) \
  113. __this_cpu_inc(mib->mibs[field])
  114. @@ -153,8 +168,9 @@ struct linux_xfrm_mib {
  115. __this_cpu_add(ptr[basefield##OCTETS], addend); \
  116. } while (0)
  117. +#endif
  118. -#if BITS_PER_LONG==32
  119. +#if (BITS_PER_LONG==32) && !defined(CONFIG_PROC_STRIPPED)
  120. #define __SNMP_ADD_STATS64(mib, field, addend) \
  121. do { \
  122. --- a/ipc/msg.c
  123. +++ b/ipc/msg.c
  124. @@ -1291,6 +1291,9 @@ void __init msg_init(void)
  125. {
  126. msg_init_ns(&init_ipc_ns);
  127. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  128. + return;
  129. +
  130. ipc_init_proc_interface("sysvipc/msg",
  131. " key msqid perms cbytes qnum lspid lrpid uid gid cuid cgid stime rtime ctime\n",
  132. IPC_MSG_IDS, sysvipc_msg_proc_show);
  133. --- a/ipc/sem.c
  134. +++ b/ipc/sem.c
  135. @@ -243,6 +243,8 @@ void sem_exit_ns(struct ipc_namespace *n
  136. void __init sem_init(void)
  137. {
  138. sem_init_ns(&init_ipc_ns);
  139. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  140. + return;
  141. ipc_init_proc_interface("sysvipc/sem",
  142. " key semid perms nsems uid gid cuid cgid otime ctime\n",
  143. IPC_SEM_IDS, sysvipc_sem_proc_show);
  144. --- a/ipc/shm.c
  145. +++ b/ipc/shm.c
  146. @@ -144,6 +144,8 @@ pure_initcall(ipc_ns_init);
  147. void __init shm_init(void)
  148. {
  149. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  150. + return;
  151. ipc_init_proc_interface("sysvipc/shm",
  152. #if BITS_PER_LONG <= 32
  153. " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime rss swap\n",
  154. --- a/ipc/util.c
  155. +++ b/ipc/util.c
  156. @@ -140,6 +140,9 @@ void __init ipc_init_proc_interface(cons
  157. struct proc_dir_entry *pde;
  158. struct ipc_proc_iface *iface;
  159. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  160. + return;
  161. +
  162. iface = kmalloc(sizeof(*iface), GFP_KERNEL);
  163. if (!iface)
  164. return;
  165. --- a/kernel/exec_domain.c
  166. +++ b/kernel/exec_domain.c
  167. @@ -29,6 +29,8 @@ static int execdomains_proc_show(struct
  168. static int __init proc_execdomains_init(void)
  169. {
  170. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  171. + return 0;
  172. proc_create_single("execdomains", 0, NULL, execdomains_proc_show);
  173. return 0;
  174. }
  175. --- a/kernel/irq/proc.c
  176. +++ b/kernel/irq/proc.c
  177. @@ -333,6 +333,9 @@ void register_irq_proc(unsigned int irq,
  178. void __maybe_unused *irqp = (void *)(unsigned long) irq;
  179. char name [MAX_NAMELEN];
  180. + if (IS_ENABLED(CONFIG_PROC_STRIPPED) && !IS_ENABLED(CONFIG_SMP))
  181. + return;
  182. +
  183. if (!root_irq_dir || (desc->irq_data.chip == &no_irq_chip))
  184. return;
  185. @@ -386,6 +389,9 @@ void unregister_irq_proc(unsigned int ir
  186. {
  187. char name [MAX_NAMELEN];
  188. + if (IS_ENABLED(CONFIG_PROC_STRIPPED) && !IS_ENABLED(CONFIG_SMP))
  189. + return;
  190. +
  191. if (!root_irq_dir || !desc->dir)
  192. return;
  193. #ifdef CONFIG_SMP
  194. @@ -424,6 +430,9 @@ void init_irq_proc(void)
  195. unsigned int irq;
  196. struct irq_desc *desc;
  197. + if (IS_ENABLED(CONFIG_PROC_STRIPPED) && !IS_ENABLED(CONFIG_SMP))
  198. + return;
  199. +
  200. /* create /proc/irq */
  201. root_irq_dir = proc_mkdir("irq", NULL);
  202. if (!root_irq_dir)
  203. --- a/kernel/time/timer_list.c
  204. +++ b/kernel/time/timer_list.c
  205. @@ -374,6 +374,8 @@ static int __init init_timer_list_procfs
  206. {
  207. struct proc_dir_entry *pe;
  208. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  209. + return 0;
  210. pe = proc_create_seq_private("timer_list", 0400, NULL, &timer_list_sops,
  211. sizeof(struct timer_list_iter), NULL);
  212. if (!pe)
  213. --- a/mm/vmalloc.c
  214. +++ b/mm/vmalloc.c
  215. @@ -2740,6 +2740,8 @@ static const struct seq_operations vmall
  216. static int __init proc_vmalloc_init(void)
  217. {
  218. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  219. + return 0;
  220. if (IS_ENABLED(CONFIG_NUMA))
  221. proc_create_seq_private("vmallocinfo", 0400, NULL,
  222. &vmalloc_op,
  223. --- a/mm/vmstat.c
  224. +++ b/mm/vmstat.c
  225. @@ -1972,10 +1972,12 @@ void __init init_mm_internals(void)
  226. start_shepherd_timer();
  227. #endif
  228. #ifdef CONFIG_PROC_FS
  229. - proc_create_seq("buddyinfo", 0444, NULL, &fragmentation_op);
  230. - proc_create_seq("pagetypeinfo", 0444, NULL, &pagetypeinfo_op);
  231. + if (!IS_ENABLED(CONFIG_PROC_STRIPPED)) {
  232. + proc_create_seq("buddyinfo", 0444, NULL, &fragmentation_op);
  233. + proc_create_seq("pagetypeinfo", 0444, NULL, &pagetypeinfo_op);
  234. + proc_create_seq("zoneinfo", 0444, NULL, &zoneinfo_op);
  235. + }
  236. proc_create_seq("vmstat", 0444, NULL, &vmstat_op);
  237. - proc_create_seq("zoneinfo", 0444, NULL, &zoneinfo_op);
  238. #endif
  239. }
  240. --- a/net/8021q/vlanproc.c
  241. +++ b/net/8021q/vlanproc.c
  242. @@ -96,6 +96,9 @@ void vlan_proc_cleanup(struct net *net)
  243. {
  244. struct vlan_net *vn = net_generic(net, vlan_net_id);
  245. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  246. + return;
  247. +
  248. if (vn->proc_vlan_conf)
  249. remove_proc_entry(name_conf, vn->proc_vlan_dir);
  250. @@ -115,6 +118,9 @@ int __net_init vlan_proc_init(struct net
  251. {
  252. struct vlan_net *vn = net_generic(net, vlan_net_id);
  253. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  254. + return 0;
  255. +
  256. vn->proc_vlan_dir = proc_net_mkdir(net, name_root, net->proc_net);
  257. if (!vn->proc_vlan_dir)
  258. goto err;
  259. --- a/net/core/net-procfs.c
  260. +++ b/net/core/net-procfs.c
  261. @@ -279,10 +279,12 @@ static int __net_init dev_proc_net_init(
  262. if (!proc_create_net("dev", 0444, net->proc_net, &dev_seq_ops,
  263. sizeof(struct seq_net_private)))
  264. goto out;
  265. - if (!proc_create_seq("softnet_stat", 0444, net->proc_net,
  266. + if (!IS_ENABLED(CONFIG_PROC_STRIPPED) &&
  267. + !proc_create_seq("softnet_stat", 0444, net->proc_net,
  268. &softnet_seq_ops))
  269. goto out_dev;
  270. - if (!proc_create_net("ptype", 0444, net->proc_net, &ptype_seq_ops,
  271. + if (!IS_ENABLED(CONFIG_PROC_STRIPPED) &&
  272. + !proc_create_net("ptype", 0444, net->proc_net, &ptype_seq_ops,
  273. sizeof(struct seq_net_private)))
  274. goto out_softnet;
  275. @@ -292,9 +294,11 @@ static int __net_init dev_proc_net_init(
  276. out:
  277. return rc;
  278. out_ptype:
  279. - remove_proc_entry("ptype", net->proc_net);
  280. + if (!IS_ENABLED(CONFIG_PROC_STRIPPED))
  281. + remove_proc_entry("ptype", net->proc_net);
  282. out_softnet:
  283. - remove_proc_entry("softnet_stat", net->proc_net);
  284. + if (!IS_ENABLED(CONFIG_PROC_STRIPPED))
  285. + remove_proc_entry("softnet_stat", net->proc_net);
  286. out_dev:
  287. remove_proc_entry("dev", net->proc_net);
  288. goto out;
  289. @@ -304,8 +308,10 @@ static void __net_exit dev_proc_net_exit
  290. {
  291. wext_proc_exit(net);
  292. - remove_proc_entry("ptype", net->proc_net);
  293. - remove_proc_entry("softnet_stat", net->proc_net);
  294. + if (!IS_ENABLED(CONFIG_PROC_STRIPPED)) {
  295. + remove_proc_entry("ptype", net->proc_net);
  296. + remove_proc_entry("softnet_stat", net->proc_net);
  297. + }
  298. remove_proc_entry("dev", net->proc_net);
  299. }
  300. --- a/net/core/sock.c
  301. +++ b/net/core/sock.c
  302. @@ -3483,6 +3483,8 @@ static __net_initdata struct pernet_oper
  303. static int __init proto_init(void)
  304. {
  305. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  306. + return 0;
  307. return register_pernet_subsys(&proto_net_ops);
  308. }
  309. --- a/net/ipv4/fib_trie.c
  310. +++ b/net/ipv4/fib_trie.c
  311. @@ -2717,11 +2717,13 @@ static const struct seq_operations fib_r
  312. int __net_init fib_proc_init(struct net *net)
  313. {
  314. - if (!proc_create_net("fib_trie", 0444, net->proc_net, &fib_trie_seq_ops,
  315. + if (!IS_ENABLED(CONFIG_PROC_STRIPPED) &&
  316. + !proc_create_net("fib_trie", 0444, net->proc_net, &fib_trie_seq_ops,
  317. sizeof(struct fib_trie_iter)))
  318. goto out1;
  319. - if (!proc_create_net_single("fib_triestat", 0444, net->proc_net,
  320. + if (!IS_ENABLED(CONFIG_PROC_STRIPPED) &&
  321. + !proc_create_net_single("fib_triestat", 0444, net->proc_net,
  322. fib_triestat_seq_show, NULL))
  323. goto out2;
  324. @@ -2732,17 +2734,21 @@ int __net_init fib_proc_init(struct net
  325. return 0;
  326. out3:
  327. - remove_proc_entry("fib_triestat", net->proc_net);
  328. + if (!IS_ENABLED(CONFIG_PROC_STRIPPED))
  329. + remove_proc_entry("fib_triestat", net->proc_net);
  330. out2:
  331. - remove_proc_entry("fib_trie", net->proc_net);
  332. + if (!IS_ENABLED(CONFIG_PROC_STRIPPED))
  333. + remove_proc_entry("fib_trie", net->proc_net);
  334. out1:
  335. return -ENOMEM;
  336. }
  337. void __net_exit fib_proc_exit(struct net *net)
  338. {
  339. - remove_proc_entry("fib_trie", net->proc_net);
  340. - remove_proc_entry("fib_triestat", net->proc_net);
  341. + if (!IS_ENABLED(CONFIG_PROC_STRIPPED)) {
  342. + remove_proc_entry("fib_trie", net->proc_net);
  343. + remove_proc_entry("fib_triestat", net->proc_net);
  344. + }
  345. remove_proc_entry("route", net->proc_net);
  346. }
  347. --- a/net/ipv4/proc.c
  348. +++ b/net/ipv4/proc.c
  349. @@ -523,5 +523,8 @@ static __net_initdata struct pernet_oper
  350. int __init ip_misc_proc_init(void)
  351. {
  352. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  353. + return 0;
  354. +
  355. return register_pernet_subsys(&ip_proc_ops);
  356. }
  357. --- a/net/ipv4/route.c
  358. +++ b/net/ipv4/route.c
  359. @@ -410,6 +410,9 @@ static struct pernet_operations ip_rt_pr
  360. static int __init ip_rt_proc_init(void)
  361. {
  362. + if (IS_ENABLED(CONFIG_PROC_STRIPPED))
  363. + return 0;
  364. +
  365. return register_pernet_subsys(&ip_rt_proc_ops);
  366. }