diff options
| author | Eric W. Biederman <ebiederm@xmission.com> | 2015-05-11 17:44:25 -0400 |
|---|---|---|
| committer | Eric W. Biederman <ebiederm@xmission.com> | 2015-07-01 11:36:41 -0400 |
| commit | eb6d38d5427b3ad42f5268da0f1dd31bb0af1264 (patch) | |
| tree | 1fb54abb73c369444d6b84f12e3eff670c0a5d64 | |
| parent | f9bd6733d3f11e24f3949becf277507d422ee1eb (diff) | |
proc: Allow creating permanently empty directories that serve as mount points
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.
Cc: stable@vger.kernel.org
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
| -rw-r--r-- | fs/proc/generic.c | 23 | ||||
| -rw-r--r-- | fs/proc/inode.c | 4 | ||||
| -rw-r--r-- | fs/proc/internal.h | 6 | ||||
| -rw-r--r-- | fs/proc/root.c | 4 |
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 | } |
| 456 | EXPORT_SYMBOL(proc_mkdir); | 460 | EXPORT_SYMBOL(proc_mkdir); |
| 457 | 461 | ||
| 462 | struct 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 | |||
| 458 | struct proc_dir_entry *proc_create_data(const char *name, umode_t mode, | 481 | struct 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 | } |
| 192 | extern void pde_put(struct proc_dir_entry *); | 192 | extern void pde_put(struct proc_dir_entry *); |
| 193 | 193 | ||
| 194 | static inline bool is_empty_pde(const struct proc_dir_entry *pde) | ||
| 195 | { | ||
| 196 | return S_ISDIR(pde->mode) && !pde->proc_iops; | ||
| 197 | } | ||
| 198 | struct 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 64e1ab64bde6..68feb0f70e63 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c | |||
| @@ -179,10 +179,10 @@ void __init proc_root_init(void) | |||
| 179 | #endif | 179 | #endif |
| 180 | proc_mkdir("fs", NULL); | 180 | proc_mkdir("fs", NULL); |
| 181 | proc_mkdir("driver", NULL); | 181 | proc_mkdir("driver", NULL); |
| 182 | proc_mkdir("fs/nfsd", NULL); /* somewhere for the nfsd filesystem to be mounted */ | 182 | proc_create_mount_point("fs/nfsd"); /* somewhere for the nfsd filesystem to be mounted */ |
| 183 | #if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE) | 183 | #if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE) |
| 184 | /* just give it a mountpoint */ | 184 | /* just give it a mountpoint */ |
| 185 | proc_mkdir("openprom", NULL); | 185 | proc_create_mount_point("openprom"); |
| 186 | #endif | 186 | #endif |
| 187 | proc_tty_init(); | 187 | proc_tty_init(); |
| 188 | proc_mkdir("bus", NULL); | 188 | proc_mkdir("bus", NULL); |
