902-debloat_proc.patch 12 KB

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