* [PATCH] sys_set/getpriority PRIO_USER semantics fix and optimisation
@ 2004-12-01 23:21 pmeda
2004-12-02 21:53 ` Prasanna Meda
0 siblings, 1 reply; 2+ messages in thread
From: pmeda @ 2004-12-01 23:21 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel
This change brings the semantics equivalent to 2.4 and also to what
the man page says; Also optimises by avoiding unneeded lookup in uid
cache, when who is same as the current->uid.
sys_set/getpriority is rewritten in 2.5/2.6, perhaps while transitioning
to the pid maps. It has now semantical bug, when uid is zero. Note
that akpm also fixed refcount leak and locking in the new functions
in changeset http://linus.bkbits.net:8080/linux-2.5/cset@1.1608.10.84
sys.c | 26 ++++++++++++--------------
1 files changed, 12 insertions, 14 deletions
Signed-off-by: pmeda@akamai.com
--- linux-2.6.9-1/kernel/sys.c Wed Dec 1 20:46:50 2004
+++ linux-2.6.9-2/kernel/sys.c Wed Dec 1 21:47:36 2004
@@ -341,19 +341,18 @@
} while_each_task_pid(who, PIDTYPE_PGID, p);
break;
case PRIO_USER:
- if (!who)
- user = current->user;
- else
- user = find_user(who);
-
- if (!user)
- goto out_unlock;
+ user = current->user;
+ if (!who)
+ who = current->uid;
+ else
+ if ((who != current->uid) && !(user = find_user(who)))
+ goto out_unlock; /* No processes for this user */
do_each_thread(g, p)
if (p->uid == who)
error = set_one_prio(p, niceval, error);
while_each_thread(g, p);
- if (who)
+ if (who != current->uid)
free_uid(user); /* For find_user() */
break;
}
@@ -400,13 +399,12 @@
} while_each_task_pid(who, PIDTYPE_PGID, p);
break;
case PRIO_USER:
+ user = current->user;
if (!who)
- user = current->user;
+ who = current->uid;
else
- user = find_user(who);
-
- if (!user)
- goto out_unlock;
+ if ((who != current->uid) && !(user = find_user(who)))
+ goto out_unlock; /* No processes for this user */
do_each_thread(g, p)
if (p->uid == who) {
@@ -415,7 +413,7 @@
retval = niceval;
}
while_each_thread(g, p);
- if (who)
+ if (who != current->uid)
free_uid(user); /* for find_user() */
break;
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] sys_set/getpriority PRIO_USER semantics fix and optimisation
2004-12-01 23:21 [PATCH] sys_set/getpriority PRIO_USER semantics fix and optimisation pmeda
@ 2004-12-02 21:53 ` Prasanna Meda
0 siblings, 0 replies; 2+ messages in thread
From: Prasanna Meda @ 2004-12-02 21:53 UTC (permalink / raw)
To: akpm, linux-kernel
pmeda@akamai.com wrote:
> sys_set/getpriority is rewritten in 2.5/2.6, perhaps while transitioning
> to the pid maps. It has now semantical bug, when uid is zero. Note
A test case:
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
int main()
{
int prio1, prio2, ret, errno;
/* If root, loose priv. for testing */
setresuid(237, 237, 237);
prio1 = getpriority(2, getuid());
if (setpriority(PRIO_USER, 0, prio1+1) < 0) {
perror("setprio");
printf("FAILED!\n");
}
else {
prio2 = getpriority(2, getuid());
printf("Old prio:%d to new prio:%d\n", prio1, prio2);
printf((prio1 +1 != prio2)? "FAILED\n":"PASSED\n");
}
exit(0);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-12-02 20:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-01 23:21 [PATCH] sys_set/getpriority PRIO_USER semantics fix and optimisation pmeda
2004-12-02 21:53 ` Prasanna Meda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox