Commit ece47480 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by Luis Henriques

proc: Allow creating permanently empty directories that serve as mount points

commit eb6d38d5 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: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
[ luis: backported to 3.16: adjusted context ]
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 452452be
...@@ -334,6 +334,11 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent, ...@@ -334,6 +334,11 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
len = strlen(fn); len = strlen(fn);
if (is_empty_pde(*parent)) {
WARN(1, "attempt to add to permanently empty directory");
return NULL;
}
ent = kzalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL); ent = kzalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL);
if (!ent) if (!ent)
goto out; goto out;
...@@ -409,6 +414,25 @@ struct proc_dir_entry *proc_mkdir(const char *name, ...@@ -409,6 +414,25 @@ struct proc_dir_entry *proc_mkdir(const char *name,
} }
EXPORT_SYMBOL(proc_mkdir); EXPORT_SYMBOL(proc_mkdir);
struct proc_dir_entry *proc_create_mount_point(const char *name)
{
umode_t mode = S_IFDIR | S_IRUGO | S_IXUGO;
struct proc_dir_entry *ent, *parent = NULL;
ent = __proc_create(&parent, name, mode, 2);
if (ent) {
ent->data = NULL;
ent->proc_fops = NULL;
ent->proc_iops = NULL;
if (proc_register(parent, ent) < 0) {
kfree(ent);
parent->nlink--;
ent = NULL;
}
}
return ent;
}
struct proc_dir_entry *proc_create_data(const char *name, umode_t mode, struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
struct proc_dir_entry *parent, struct proc_dir_entry *parent,
const struct file_operations *proc_fops, const struct file_operations *proc_fops,
......
...@@ -431,6 +431,10 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de) ...@@ -431,6 +431,10 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
PROC_I(inode)->pde = de; PROC_I(inode)->pde = de;
if (is_empty_pde(de)) {
make_empty_dir_inode(inode);
return inode;
}
if (de->mode) { if (de->mode) {
inode->i_mode = de->mode; inode->i_mode = de->mode;
inode->i_uid = de->uid; inode->i_uid = de->uid;
......
...@@ -193,6 +193,12 @@ static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde) ...@@ -193,6 +193,12 @@ static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
} }
extern void pde_put(struct proc_dir_entry *); extern void pde_put(struct proc_dir_entry *);
static inline bool is_empty_pde(const struct proc_dir_entry *pde)
{
return S_ISDIR(pde->mode) && !pde->proc_iops;
}
struct proc_dir_entry *proc_create_mount_point(const char *name);
/* /*
* inode.c * inode.c
*/ */
......
...@@ -176,10 +176,10 @@ void __init proc_root_init(void) ...@@ -176,10 +176,10 @@ void __init proc_root_init(void)
#endif #endif
proc_mkdir("fs", NULL); proc_mkdir("fs", NULL);
proc_mkdir("driver", NULL); proc_mkdir("driver", NULL);
proc_mkdir("fs/nfsd", NULL); /* somewhere for the nfsd filesystem to be mounted */ proc_create_mount_point("fs/nfsd"); /* somewhere for the nfsd filesystem to be mounted */
#if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE) #if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE)
/* just give it a mountpoint */ /* just give it a mountpoint */
proc_mkdir("openprom", NULL); proc_create_mount_point("openprom");
#endif #endif
proc_tty_init(); proc_tty_init();
proc_mkdir("bus", NULL); proc_mkdir("bus", NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment