902-debloat_proc.patch 11 KB

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