902-debloat_proc.patch 11 KB

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