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