Skip to content

Commit 24074a3

Browse files
dhowellsAl Viro
authored andcommitted
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: Al Viro <[email protected]> Signed-off-by: David Howells <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent de52cf9 commit 24074a3

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

fs/proc/generic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
410410
if (!ent)
411411
goto out;
412412

413-
if (qstr.len + 1 <= sizeof(ent->inline_name)) {
413+
if (qstr.len + 1 <= SIZEOF_PDE_INLINE_NAME) {
414414
ent->name = ent->inline_name;
415415
} else {
416416
ent->name = kmalloc(qstr.len + 1, GFP_KERNEL);

fs/proc/inode.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ void __init proc_init_kmemcache(void)
105105
kmem_cache_create("pde_opener", sizeof(struct pde_opener), 0,
106106
SLAB_ACCOUNT|SLAB_PANIC, NULL);
107107
proc_dir_entry_cache = kmem_cache_create_usercopy(
108-
"proc_dir_entry", sizeof(struct proc_dir_entry), 0, SLAB_PANIC,
109-
offsetof(struct proc_dir_entry, inline_name),
110-
sizeof_field(struct proc_dir_entry, inline_name), NULL);
108+
"proc_dir_entry", SIZEOF_PDE_SLOT, 0, SLAB_PANIC,
109+
OFFSETOF_PDE_NAME, SIZEOF_PDE_INLINE_NAME, NULL);
111110
}
112111

113112
static int proc_show_options(struct seq_file *seq, struct dentry *root)

fs/proc/internal.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,20 @@ struct proc_dir_entry {
6262
char *name;
6363
umode_t mode;
6464
u8 namelen;
65-
#ifdef CONFIG_64BIT
66-
#define SIZEOF_PDE_INLINE_NAME (192-155)
67-
#else
68-
#define SIZEOF_PDE_INLINE_NAME (128-95)
69-
#endif
70-
char inline_name[SIZEOF_PDE_INLINE_NAME];
65+
char inline_name[];
7166
} __randomize_layout;
7267

68+
#define OFFSETOF_PDE_NAME offsetof(struct proc_dir_entry, inline_name)
69+
#define SIZEOF_PDE_SLOT \
70+
(OFFSETOF_PDE_NAME + 34 <= 64 ? 64 : \
71+
OFFSETOF_PDE_NAME + 34 <= 128 ? 128 : \
72+
OFFSETOF_PDE_NAME + 34 <= 192 ? 192 : \
73+
OFFSETOF_PDE_NAME + 34 <= 256 ? 256 : \
74+
OFFSETOF_PDE_NAME + 34 <= 512 ? 512 : \
75+
0)
76+
77+
#define SIZEOF_PDE_INLINE_NAME (SIZEOF_PDE_SLOT - OFFSETOF_PDE_NAME)
78+
7379
extern struct kmem_cache *proc_dir_entry_cache;
7480
void pde_free(struct proc_dir_entry *pde);
7581

fs/proc/root.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ struct proc_dir_entry proc_root = {
204204
.proc_fops = &proc_root_operations,
205205
.parent = &proc_root,
206206
.subdir = RB_ROOT,
207-
.name = proc_root.inline_name,
208-
.inline_name = "/proc",
207+
.name = "/proc",
209208
};
210209

211210
int pid_ns_prepare_proc(struct pid_namespace *ns)

0 commit comments

Comments
 (0)