Merge branch 'timers-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[safe/jmp/linux-2.6] / kernel / sysctl.c
index c9a0af8..fe47133 100644 (file)
@@ -1516,9 +1516,9 @@ static int do_sysctl_strategy(struct ctl_table_root *root,
        int op = 0, rc;
 
        if (oldval)
-               op |= 004;
+               op |= MAY_READ;
        if (newval)
-               op |= 002;
+               op |= MAY_WRITE;
        if (sysctl_perm(root, table, op))
                return -EPERM;
 
@@ -1560,7 +1560,7 @@ repeat:
                if (n == table->ctl_name) {
                        int error;
                        if (table->child) {
-                               if (sysctl_perm(root, table, 001))
+                               if (sysctl_perm(root, table, MAY_EXEC))
                                        return -EPERM;
                                name++;
                                nlen--;
@@ -1635,7 +1635,7 @@ static int test_perm(int mode, int op)
                mode >>= 6;
        else if (in_egroup_p(0))
                mode >>= 3;
-       if ((mode & op & 0007) == op)
+       if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
                return 0;
        return -EACCES;
 }
@@ -1645,7 +1645,7 @@ int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
        int error;
        int mode;
 
-       error = security_sysctl(table, op);
+       error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
        if (error)
                return error;
 
@@ -1680,43 +1680,45 @@ static __init int sysctl_init(void)
 
 core_initcall(sysctl_init);
 
-static int is_branch_in(struct ctl_table *branch, struct ctl_table *table)
+static struct ctl_table *is_branch_in(struct ctl_table *branch,
+                                     struct ctl_table *table)
 {
        struct ctl_table *p;
        const char *s = branch->procname;
 
        /* branch should have named subdirectory as its first element */
        if (!s || !branch->child)
-               return 0;
+               return NULL;
 
        /* ... and nothing else */
        if (branch[1].procname || branch[1].ctl_name)
-               return 0;
+               return NULL;
 
        /* table should contain subdirectory with the same name */
        for (p = table; p->procname || p->ctl_name; p++) {
                if (!p->child)
                        continue;
                if (p->procname && strcmp(p->procname, s) == 0)
-                       return 1;
+                       return p;
        }
-       return 0;
+       return NULL;
 }
 
 /* see if attaching q to p would be an improvement */
 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
 {
        struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
+       struct ctl_table *next;
        int is_better = 0;
        int not_in_parent = !p->attached_by;
 
-       while (is_branch_in(by, to)) {
+       while ((next = is_branch_in(by, to)) != NULL) {
                if (by == q->attached_by)
                        is_better = 1;
                if (to == p->attached_by)
                        not_in_parent = 1;
                by = by->child;
-               to = to->child;
+               to = next->child;
        }
 
        if (is_better && not_in_parent) {
@@ -1932,6 +1934,21 @@ void unregister_sysctl_table(struct ctl_table_header * header)
        spin_unlock(&sysctl_lock);
 }
 
+int sysctl_is_seen(struct ctl_table_header *p)
+{
+       struct ctl_table_set *set = p->set;
+       int res;
+       spin_lock(&sysctl_lock);
+       if (p->unregistering)
+               res = 0;
+       else if (!set->is_seen)
+               res = 1;
+       else
+               res = set->is_seen(set);
+       spin_unlock(&sysctl_lock);
+       return res;
+}
+
 void setup_sysctl_set(struct ctl_table_set *p,
        struct ctl_table_set *parent,
        int (*is_seen)(struct ctl_table_set *))