Thread (98 messages) flat view 98 messages, 2 authors, 2011-05-08

[v2 064/115] sysctl: sysctl_head_grab defaults to root header on NULL

From: Lucian Adrian Grijincu <hidden>
Date: 2011-05-08 22:51:36
Also in: lkml
Subsystem: filesystems (vfs and infrastructure), proc filesystem, proc sysctl, the rest · Maintainers: Alexander Viro, Christian Brauner, Kees Cook, Joel Granados, Linus Torvalds

The code that could send NULL to sysctl_head_grab is grab_header
because for the root sysctl directory ('/proc/sys/')
PROC_I(inode)->sysctl is NULL.

For it we used to return root_table_header indirectly through a call
to sysctl_head_next(NULL). Now we default to the root header here.

The BUG() has not been triggered until now so we can assume no one
else is sending NULL here.

Signed-off-by: Lucian Adrian Grijincu <redacted>
---
 fs/proc/proc_sysctl.c |    5 +----
 kernel/sysctl.c       |    2 +-
 2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index d1640bc..93962b0 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -64,10 +64,7 @@ static struct ctl_table *find_in_table(struct ctl_table *p, struct qstr *name)
 
 static struct ctl_table_header *grab_header(struct inode *inode)
 {
-	if (PROC_I(inode)->sysctl)
-		return sysctl_head_grab(PROC_I(inode)->sysctl);
-	else
-		return sysctl_head_next(NULL);
+	return sysctl_head_grab(PROC_I(inode)->sysctl);
 }
 
 static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 0450d3d..8b56695 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1554,7 +1554,7 @@ void sysctl_head_put(struct ctl_table_header *head)
 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
 {
 	if (!head)
-		BUG();
+		head = &root_table_header;
 	spin_lock(&sysctl_lock);
 	if (!use_table(head))
 		head = ERR_PTR(-ENOENT);
-- 
1.7.5.134.g1c08b
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help