aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorAndrew Morton <akpm@osdl.org>2004-05-10 00:00:52 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2004-05-10 00:00:52 -0700
commit475c3656c94b2d8709c113bd7bbd1aa963213f0a (patch)
treef072e4c22da5e83da6ac6ffa366bf1948480fda1 /kernel
parent5a80c2eaf119ef59badcba46580df9a5294fb603 (diff)
downloadhistory-475c3656c94b2d8709c113bd7bbd1aa963213f0a.tar.gz
[PATCH] find_user locking and leak fix
find_user() is being called from set/get_priority(), but it doesn't take the needed lock, and those callers were forgetting to drop the refcount which find_user() took.
Diffstat (limited to 'kernel')
-rw-r--r--kernel/sys.c4
-rw-r--r--kernel/user.c13
2 files changed, 16 insertions, 1 deletions
diff --git a/kernel/sys.c b/kernel/sys.c
index 4d414d92588944..6c700952637c0a 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -348,6 +348,8 @@ asmlinkage long sys_setpriority(int which, int who, int niceval)
if (p->uid == who)
error = set_one_prio(p, niceval, error);
while_each_thread(g, p);
+ if (who)
+ free_uid(user); /* For find_user() */
break;
}
out_unlock:
@@ -410,6 +412,8 @@ asmlinkage long sys_getpriority(int which, int who)
retval = niceval;
}
while_each_thread(g, p);
+ if (who)
+ free_uid(user); /* for find_user() */
break;
}
out_unlock:
diff --git a/kernel/user.c b/kernel/user.c
index f5c9d425a78397..0e9e032a6d84eb 100644
--- a/kernel/user.c
+++ b/kernel/user.c
@@ -64,9 +64,20 @@ static inline struct user_struct *uid_hash_find(uid_t uid, struct list_head *has
return NULL;
}
+/*
+ * Locate the user_struct for the passed UID. If found, take a ref on it. The
+ * caller must undo that ref with free_uid().
+ *
+ * If the user_struct could not be found, return NULL.
+ */
struct user_struct *find_user(uid_t uid)
{
- return uid_hash_find(uid, uidhashentry(uid));
+ struct user_struct *ret;
+
+ spin_lock(&uidhash_lock);
+ ret = uid_hash_find(uid, uidhashentry(uid));
+ spin_unlock(&uidhash_lock);
+ return ret;
}
void free_uid(struct user_struct *up)