aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2015-05-11 17:44:25 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-07-21 13:10:00 -0400
commita2020b02c1ec4fffddb77785773dff533428f814 (patch)
tree751730d146363e8adde874dc246a66f84fdd69f0 /fs
parentbdbdf7ee9d561da7b4b840435c963344061953d6 (diff)
proc: Allow creating permanently empty directories that serve as mount points
commit eb6d38d5427b3ad42f5268da0f1dd31bb0af1264 upstream. Add a new function proc_create_mount_point that when used to creates a directory that can not be added to. Add a new function is_empty_pde to test if a function is a mount point. Update the code to use make_empty_dir_inode when reporting a permanently empty directory to the vfs. Update the code to not allow adding to permanently empty directories. Update /proc/openprom and /proc/fs/nfsd to be permanently empty directories. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/proc/generic.c23
-rw-r--r--fs/proc/inode.c4
-rw-r--r--fs/proc/internal.h6
-rw-r--r--fs/proc/root.c4
4 files changed, 35 insertions, 2 deletions
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index df6327a2b865..e5dee5c3188e 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -373,6 +373,10 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
373 WARN(1, "create '/proc/%s' by hand\n", qstr.name); 373 WARN(1, "create '/proc/%s' by hand\n", qstr.name);
374 return NULL; 374 return NULL;
375 } 375 }
376 if (is_empty_pde(*parent)) {
377 WARN(1, "attempt to add to permanently empty directory");
378 return NULL;
379 }
376 380
377 ent = kzalloc(sizeof(struct proc_dir_entry) + qstr.len + 1, GFP_KERNEL); 381 ent = kzalloc(sizeof(struct proc_dir_entry) + qstr.len + 1, GFP_KERNEL);
378 if (!ent) 382 if (!ent)
@@ -455,6 +459,25 @@ struct proc_dir_entry *proc_mkdir(const char *name,
455} 459}
456EXPORT_SYMBOL(proc_mkdir); 460EXPORT_SYMBOL(proc_mkdir);
457 461
462struct proc_dir_entry *proc_create_mount_point(const char *name)
463{
464 umode_t mode = S_IFDIR | S_IRUGO | S_IXUGO;
465 struct proc_dir_entry *ent, *parent = NULL;
466
467 ent = __proc_create(&parent, name, mode, 2);
468 if (ent) {
469 ent->data = NULL;
470 ent->proc_fops = NULL;
471 ent->proc_iops = NULL;
472 if (proc_register(parent, ent) < 0) {
473 kfree(ent);
474 parent->nlink--;
475 ent = NULL;
476 }
477 }
478 return ent;
479}
480
458struct proc_dir_entry *proc_create_data(const char *name, umode_t mode, 481struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
459 struct proc_dir_entry *parent, 482 struct proc_dir_entry *parent,
460 const struct file_operations *proc_fops, 483 const struct file_operations *proc_fops,
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index 8272aaba1bb0..e3eb5524639f 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -423,6 +423,10 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
423 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 423 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
424 PROC_I(inode)->pde = de; 424 PROC_I(inode)->pde = de;
425 425
426 if (is_empty_pde(de)) {
427 make_empty_dir_inode(inode);
428 return inode;
429 }
426 if (de->mode) { 430 if (de->mode) {
427 inode->i_mode = de->mode; 431 inode->i_mode = de->mode;
428 inode->i_uid = de->uid; 432 inode->i_uid = de->uid;
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index c835b94c0cd3..aa2781095bd1 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -191,6 +191,12 @@ static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
191} 191}
192extern void pde_put(struct proc_dir_entry *); 192extern void pde_put(struct proc_dir_entry *);
193 193
194static inline bool is_empty_pde(const struct proc_dir_entry *pde)
195{
196 return S_ISDIR(pde->mode) && !pde->proc_iops;
197}
198struct proc_dir_entry *proc_create_mount_point(const char *name);
199
194/* 200/*
195 * inode.c 201 * inode.c
196 */ 202 */
diff --git a/fs/proc/root.c b/fs/proc/root.c
index b7fa4bfe896a..3d987dfdef83 100644
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -182,10 +182,10 @@ void __init proc_root_init(void)
182#endif 182#endif
183 proc_mkdir("fs", NULL); 183 proc_mkdir("fs", NULL);
184 proc_mkdir("driver", NULL); 184 proc_mkdir("driver", NULL);
185 proc_mkdir("fs/nfsd", NULL); /* somewhere for the nfsd filesystem to be mounted */ 185 proc_create_mount_point("fs/nfsd"); /* somewhere for the nfsd filesystem to be mounted */
186#if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE) 186#if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE)
187 /* just give it a mountpoint */ 187 /* just give it a mountpoint */
188 proc_mkdir("openprom", NULL); 188 proc_create_mount_point("openprom");
189#endif 189#endif
190 proc_tty_init(); 190 proc_tty_init();
191 proc_mkdir("bus", NULL); 191 proc_mkdir("bus", NULL);