Commit 24074a35 authored by David Howells's avatar David Howells Committed by Al Viro

proc: Make inline name size calculation automatic

Make calculation of the size of the inline name in struct proc_dir_entry
automatic, rather than having to manually encode the numbers and failing to
allow for lockdep.

Require a minimum inline name size of 33+1 to allow for names that look
like two hex numbers with a dash between.
Reported-by: default avatarAl Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent de52cf92
...@@ -410,7 +410,7 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent, ...@@ -410,7 +410,7 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
if (!ent) if (!ent)
goto out; goto out;
if (qstr.len + 1 <= sizeof(ent->inline_name)) { if (qstr.len + 1 <= SIZEOF_PDE_INLINE_NAME) {
ent->name = ent->inline_name; ent->name = ent->inline_name;
} else { } else {
ent->name = kmalloc(qstr.len + 1, GFP_KERNEL); ent->name = kmalloc(qstr.len + 1, GFP_KERNEL);
......
...@@ -105,9 +105,8 @@ void __init proc_init_kmemcache(void) ...@@ -105,9 +105,8 @@ void __init proc_init_kmemcache(void)
kmem_cache_create("pde_opener", sizeof(struct pde_opener), 0, kmem_cache_create("pde_opener", sizeof(struct pde_opener), 0,
SLAB_ACCOUNT|SLAB_PANIC, NULL); SLAB_ACCOUNT|SLAB_PANIC, NULL);
proc_dir_entry_cache = kmem_cache_create_usercopy( proc_dir_entry_cache = kmem_cache_create_usercopy(
"proc_dir_entry", sizeof(struct proc_dir_entry), 0, SLAB_PANIC, "proc_dir_entry", SIZEOF_PDE_SLOT, 0, SLAB_PANIC,
offsetof(struct proc_dir_entry, inline_name), OFFSETOF_PDE_NAME, SIZEOF_PDE_INLINE_NAME, NULL);
sizeof_field(struct proc_dir_entry, inline_name), NULL);
} }
static int proc_show_options(struct seq_file *seq, struct dentry *root) static int proc_show_options(struct seq_file *seq, struct dentry *root)
......
...@@ -62,14 +62,20 @@ struct proc_dir_entry { ...@@ -62,14 +62,20 @@ struct proc_dir_entry {
char *name; char *name;
umode_t mode; umode_t mode;
u8 namelen; u8 namelen;
#ifdef CONFIG_64BIT char inline_name[];
#define SIZEOF_PDE_INLINE_NAME (192-155)
#else
#define SIZEOF_PDE_INLINE_NAME (128-95)
#endif
char inline_name[SIZEOF_PDE_INLINE_NAME];
} __randomize_layout; } __randomize_layout;
#define OFFSETOF_PDE_NAME offsetof(struct proc_dir_entry, inline_name)
#define SIZEOF_PDE_SLOT \
(OFFSETOF_PDE_NAME + 34 <= 64 ? 64 : \
OFFSETOF_PDE_NAME + 34 <= 128 ? 128 : \
OFFSETOF_PDE_NAME + 34 <= 192 ? 192 : \
OFFSETOF_PDE_NAME + 34 <= 256 ? 256 : \
OFFSETOF_PDE_NAME + 34 <= 512 ? 512 : \
0)
#define SIZEOF_PDE_INLINE_NAME (SIZEOF_PDE_SLOT - OFFSETOF_PDE_NAME)
extern struct kmem_cache *proc_dir_entry_cache; extern struct kmem_cache *proc_dir_entry_cache;
void pde_free(struct proc_dir_entry *pde); void pde_free(struct proc_dir_entry *pde);
......
...@@ -204,8 +204,7 @@ struct proc_dir_entry proc_root = { ...@@ -204,8 +204,7 @@ struct proc_dir_entry proc_root = {
.proc_fops = &proc_root_operations, .proc_fops = &proc_root_operations,
.parent = &proc_root, .parent = &proc_root,
.subdir = RB_ROOT, .subdir = RB_ROOT,
.name = proc_root.inline_name, .name = "/proc",
.inline_name = "/proc",
}; };
int pid_ns_prepare_proc(struct pid_namespace *ns) int pid_ns_prepare_proc(struct pid_namespace *ns)
......
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