| 1 | --- a/fs/locks.c |
| 2 | +++ b/fs/locks.c |
| 3 | @@ -2269,6 +2269,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 | @@ -67,3 +67,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 | @@ -108,6 +108,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 | @@ -143,7 +143,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 | @@ -160,6 +163,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 | @@ -174,6 +180,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_tty_ldisc = proc_mkdir("tty/ldisc", NULL); |
| 69 | --- a/kernel/exec_domain.c |
| 70 | +++ b/kernel/exec_domain.c |
| 71 | @@ -173,6 +173,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 | @@ -311,6 +311,9 @@ void register_irq_proc(unsigned int irq, |
| 83 | { |
| 84 | char name [MAX_NAMELEN]; |
| 85 | |
| 86 | + if (IS_ENABLED(CONFIG_PROC_STRIPPED)) |
| 87 | + return; |
| 88 | + |
| 89 | if (!root_irq_dir || (desc->irq_data.chip == &no_irq_chip) || desc->dir) |
| 90 | return; |
| 91 | |
| 92 | @@ -347,6 +350,9 @@ void unregister_irq_proc(unsigned int ir |
| 93 | { |
| 94 | char name [MAX_NAMELEN]; |
| 95 | |
| 96 | + if (IS_ENABLED(CONFIG_PROC_STRIPPED)) |
| 97 | + return; |
| 98 | + |
| 99 | if (!root_irq_dir || !desc->dir) |
| 100 | return; |
| 101 | #ifdef CONFIG_SMP |
| 102 | @@ -386,6 +392,9 @@ void init_irq_proc(void) |
| 103 | unsigned int irq; |
| 104 | struct irq_desc *desc; |
| 105 | |
| 106 | + if (IS_ENABLED(CONFIG_PROC_STRIPPED)) |
| 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 | @@ -293,6 +293,8 @@ 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 | pe = proc_create("timer_list", 0444, NULL, &timer_list_fops); |
| 121 | if (!pe) |
| 122 | return -ENOMEM; |
| 123 | --- a/mm/vmalloc.c |
| 124 | +++ b/mm/vmalloc.c |
| 125 | @@ -2639,6 +2639,8 @@ static const struct file_operations proc |
| 126 | |
| 127 | static int __init proc_vmalloc_init(void) |
| 128 | { |
| 129 | + if (IS_ENABLED(CONFIG_PROC_STRIPPED)) |
| 130 | + return 0; |
| 131 | proc_create("vmallocinfo", S_IRUSR, NULL, &proc_vmalloc_operations); |
| 132 | return 0; |
| 133 | } |
| 134 | --- a/mm/vmstat.c |
| 135 | +++ b/mm/vmstat.c |
| 136 | @@ -1212,10 +1212,12 @@ static int __init setup_vmstat(void) |
| 137 | start_cpu_timer(cpu); |
| 138 | #endif |
| 139 | #ifdef CONFIG_PROC_FS |
| 140 | - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations); |
| 141 | - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops); |
| 142 | + if (!IS_ENABLED(CONFIG_PROC_STRIPPED)) { |
| 143 | + proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations); |
| 144 | + proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops); |
| 145 | + proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations); |
| 146 | + } |
| 147 | proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations); |
| 148 | - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations); |
| 149 | #endif |
| 150 | return 0; |
| 151 | } |
| 152 | --- a/net/8021q/vlanproc.c |
| 153 | +++ b/net/8021q/vlanproc.c |
| 154 | @@ -127,6 +127,9 @@ void vlan_proc_cleanup(struct net *net) |
| 155 | { |
| 156 | struct vlan_net *vn = net_generic(net, vlan_net_id); |
| 157 | |
| 158 | + if (IS_ENABLED(CONFIG_PROC_STRIPPED)) |
| 159 | + return; |
| 160 | + |
| 161 | if (vn->proc_vlan_conf) |
| 162 | remove_proc_entry(name_conf, vn->proc_vlan_dir); |
| 163 | |
| 164 | @@ -146,6 +149,9 @@ int __net_init vlan_proc_init(struct net |
| 165 | { |
| 166 | struct vlan_net *vn = net_generic(net, vlan_net_id); |
| 167 | |
| 168 | + if (IS_ENABLED(CONFIG_PROC_STRIPPED)) |
| 169 | + return 0; |
| 170 | + |
| 171 | vn->proc_vlan_dir = proc_net_mkdir(net, name_root, net->proc_net); |
| 172 | if (!vn->proc_vlan_dir) |
| 173 | goto err; |
| 174 | --- a/net/core/dev.c |
| 175 | +++ b/net/core/dev.c |
| 176 | @@ -4425,9 +4425,11 @@ static int __net_init dev_proc_net_init( |
| 177 | |
| 178 | if (!proc_net_fops_create(net, "dev", S_IRUGO, &dev_seq_fops)) |
| 179 | goto out; |
| 180 | - if (!proc_net_fops_create(net, "softnet_stat", S_IRUGO, &softnet_seq_fops)) |
| 181 | + if (!IS_ENABLED(CONFIG_PROC_STRIPPED) && |
| 182 | + !proc_net_fops_create(net, "softnet_stat", S_IRUGO, &softnet_seq_fops)) |
| 183 | goto out_dev; |
| 184 | - if (!proc_net_fops_create(net, "ptype", S_IRUGO, &ptype_seq_fops)) |
| 185 | + if (!IS_ENABLED(CONFIG_PROC_STRIPPED) && |
| 186 | + !proc_net_fops_create(net, "ptype", S_IRUGO, &ptype_seq_fops)) |
| 187 | goto out_softnet; |
| 188 | |
| 189 | if (wext_proc_init(net)) |
| 190 | @@ -4436,9 +4438,11 @@ static int __net_init dev_proc_net_init( |
| 191 | out: |
| 192 | return rc; |
| 193 | out_ptype: |
| 194 | - proc_net_remove(net, "ptype"); |
| 195 | + if (!IS_ENABLED(CONFIG_PROC_STRIPPED)) |
| 196 | + proc_net_remove(net, "ptype"); |
| 197 | out_softnet: |
| 198 | - proc_net_remove(net, "softnet_stat"); |
| 199 | + if (!IS_ENABLED(CONFIG_PROC_STRIPPED)) |
| 200 | + proc_net_remove(net, "softnet_stat"); |
| 201 | out_dev: |
| 202 | proc_net_remove(net, "dev"); |
| 203 | goto out; |
| 204 | @@ -4448,8 +4452,10 @@ static void __net_exit dev_proc_net_exit |
| 205 | { |
| 206 | wext_proc_exit(net); |
| 207 | |
| 208 | - proc_net_remove(net, "ptype"); |
| 209 | - proc_net_remove(net, "softnet_stat"); |
| 210 | + if (!IS_ENABLED(CONFIG_PROC_STRIPPED)) { |
| 211 | + proc_net_remove(net, "ptype"); |
| 212 | + proc_net_remove(net, "softnet_stat"); |
| 213 | + } |
| 214 | proc_net_remove(net, "dev"); |
| 215 | } |
| 216 | |
| 217 | --- a/net/core/sock.c |
| 218 | +++ b/net/core/sock.c |
| 219 | @@ -2748,6 +2748,8 @@ static __net_initdata struct pernet_oper |
| 220 | |
| 221 | static int __init proto_init(void) |
| 222 | { |
| 223 | + if (IS_ENABLED(CONFIG_PROC_STRIPPED)) |
| 224 | + return 0; |
| 225 | return register_pernet_subsys(&proto_net_ops); |
| 226 | } |
| 227 | |
| 228 | --- a/net/ipv4/fib_trie.c |
| 229 | +++ b/net/ipv4/fib_trie.c |
| 230 | @@ -2604,10 +2604,12 @@ static const struct file_operations fib_ |
| 231 | |
| 232 | int __net_init fib_proc_init(struct net *net) |
| 233 | { |
| 234 | - if (!proc_net_fops_create(net, "fib_trie", S_IRUGO, &fib_trie_fops)) |
| 235 | + if (!IS_ENABLED(CONFIG_PROC_STRIPPED) && |
| 236 | + !proc_net_fops_create(net, "fib_trie", S_IRUGO, &fib_trie_fops)) |
| 237 | goto out1; |
| 238 | |
| 239 | - if (!proc_net_fops_create(net, "fib_triestat", S_IRUGO, |
| 240 | + if (!IS_ENABLED(CONFIG_PROC_STRIPPED) && |
| 241 | + !proc_net_fops_create(net, "fib_triestat", S_IRUGO, |
| 242 | &fib_triestat_fops)) |
| 243 | goto out2; |
| 244 | |
| 245 | @@ -2626,8 +2628,10 @@ out1: |
| 246 | |
| 247 | void __net_exit fib_proc_exit(struct net *net) |
| 248 | { |
| 249 | - proc_net_remove(net, "fib_trie"); |
| 250 | - proc_net_remove(net, "fib_triestat"); |
| 251 | + if (!IS_ENABLED(CONFIG_PROC_STRIPPED)) { |
| 252 | + proc_net_remove(net, "fib_trie"); |
| 253 | + proc_net_remove(net, "fib_triestat"); |
| 254 | + } |
| 255 | proc_net_remove(net, "route"); |
| 256 | } |
| 257 | |
| 258 | --- a/net/ipv4/igmp.c |
| 259 | +++ b/net/ipv4/igmp.c |
| 260 | @@ -2661,6 +2661,8 @@ static struct pernet_operations igmp_net |
| 261 | |
| 262 | int __init igmp_mc_proc_init(void) |
| 263 | { |
| 264 | + if (IS_ENABLED(CONFIG_PROC_STRIPPED)) |
| 265 | + return 0; |
| 266 | return register_pernet_subsys(&igmp_net_ops); |
| 267 | } |
| 268 | #endif |
| 269 | --- a/net/ipv4/ipmr.c |
| 270 | +++ b/net/ipv4/ipmr.c |
| 271 | @@ -70,6 +70,10 @@ |
| 272 | #define CONFIG_IP_PIMSM 1 |
| 273 | #endif |
| 274 | |
| 275 | +#ifdef CONFIG_PROC_STRIPPED |
| 276 | +#undef CONFIG_PROC_FS |
| 277 | +#endif |
| 278 | + |
| 279 | struct mr_table { |
| 280 | struct list_head list; |
| 281 | #ifdef CONFIG_NET_NS |
| 282 | --- a/net/ipv4/proc.c |
| 283 | +++ b/net/ipv4/proc.c |
| 284 | @@ -498,6 +498,9 @@ static __net_initdata struct pernet_oper |
| 285 | |
| 286 | int __init ip_misc_proc_init(void) |
| 287 | { |
| 288 | + if (IS_ENABLED(CONFIG_PROC_STRIPPED)) |
| 289 | + return 0; |
| 290 | + |
| 291 | return register_pernet_subsys(&ip_proc_ops); |
| 292 | } |
| 293 | |
| 294 | --- a/net/ipv4/route.c |
| 295 | +++ b/net/ipv4/route.c |
| 296 | @@ -427,6 +427,9 @@ static struct pernet_operations ip_rt_pr |
| 297 | |
| 298 | static int __init ip_rt_proc_init(void) |
| 299 | { |
| 300 | + if (IS_ENABLED(CONFIG_PROC_STRIPPED)) |
| 301 | + return 0; |
| 302 | + |
| 303 | return register_pernet_subsys(&ip_rt_proc_ops); |
| 304 | } |
| 305 | |
| 306 | --- a/ipc/msg.c |
| 307 | +++ b/ipc/msg.c |
| 308 | @@ -135,6 +135,9 @@ void __init msg_init(void) |
| 309 | printk(KERN_INFO "msgmni has been set to %d\n", |
| 310 | init_ipc_ns.msg_ctlmni); |
| 311 | |
| 312 | + if (IS_ENABLED(CONFIG_PROC_STRIPPED)) |
| 313 | + return; |
| 314 | + |
| 315 | ipc_init_proc_interface("sysvipc/msg", |
| 316 | " key msqid perms cbytes qnum lspid lrpid uid gid cuid cgid stime rtime ctime\n", |
| 317 | IPC_MSG_IDS, sysvipc_msg_proc_show); |
| 318 | --- a/ipc/sem.c |
| 319 | +++ b/ipc/sem.c |
| 320 | @@ -185,6 +185,8 @@ void sem_exit_ns(struct ipc_namespace *n |
| 321 | void __init sem_init (void) |
| 322 | { |
| 323 | sem_init_ns(&init_ipc_ns); |
| 324 | + if (IS_ENABLED(CONFIG_PROC_STRIPPED)) |
| 325 | + return; |
| 326 | ipc_init_proc_interface("sysvipc/sem", |
| 327 | " key semid perms nsems uid gid cuid cgid otime ctime\n", |
| 328 | IPC_SEM_IDS, sysvipc_sem_proc_show); |
| 329 | --- a/ipc/shm.c |
| 330 | +++ b/ipc/shm.c |
| 331 | @@ -115,6 +115,8 @@ pure_initcall(ipc_ns_init); |
| 332 | |
| 333 | void __init shm_init (void) |
| 334 | { |
| 335 | + if (IS_ENABLED(CONFIG_PROC_STRIPPED)) |
| 336 | + return; |
| 337 | ipc_init_proc_interface("sysvipc/shm", |
| 338 | #if BITS_PER_LONG <= 32 |
| 339 | " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime rss swap\n", |
| 340 | --- a/ipc/util.c |
| 341 | +++ b/ipc/util.c |
| 342 | @@ -148,6 +148,9 @@ void __init ipc_init_proc_interface(cons |
| 343 | struct proc_dir_entry *pde; |
| 344 | struct ipc_proc_iface *iface; |
| 345 | |
| 346 | + if (IS_ENABLED(CONFIG_PROC_STRIPPED)) |
| 347 | + return; |
| 348 | + |
| 349 | iface = kmalloc(sizeof(*iface), GFP_KERNEL); |
| 350 | if (!iface) |
| 351 | return; |
| 352 | |