1
0

902-debloat_proc.patch 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. --- a/fs/locks.c
  2. +++ b/fs/locks.c
  3. @@ -2620,6 +2620,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. @@ -144,7 +144,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. @@ -161,6 +164,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. @@ -175,6 +181,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. @@ -176,6 +176,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. @@ -330,6 +330,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. @@ -379,6 +382,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. @@ -414,6 +420,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. @@ -362,6 +362,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. @@ -2663,6 +2663,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. @@ -1424,10 +1424,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. @@ -2941,6 +2941,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. @@ -2490,10 +2490,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. @@ -2503,17 +2505,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. @@ -524,6 +524,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. @@ -418,6 +418,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. @@ -1075,6 +1075,9 @@ void __init msg_init(void)
  230. printk(KERN_INFO "msgmni has been set to %d\n",
  231. init_ipc_ns.msg_ctlmni);
  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. @@ -161,6 +161,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. }