Re: [PATCH 0/3] extend get/setrlimit to support setting rlimits externalto a process (v7)

From: Jiri Slaby
Date: Mon Nov 09 2009 - 10:56:21 EST


On 11/09/2009 10:01 AM, Ingo Molnar wrote:
> So i guess renaming setrlimit to do_setrlimit and adding the syscall
> from Neil's patch should bring the two series into sync, right?

Actually, not really. It can't work for few reasons (below) now.

+SYSCALL_DEFINE3(getprlimit, pid_t, pid, unsigned int, resource,
+ struct rlimit __user *, rlim)
+{
+ unsigned long flags;
+ struct task_struct *tsk;
+ struct pid *ppid;
+ int retval = -EINVAL;

(here should be some sort of security checking as spotted by Ingo
already). And I would move the out-of-bounds resource check here as well
to reduce the fail path handling.

+ ppid = find_get_pid(pid);
+ if (!ppid)
+ goto out;
+
+ tsk = get_pid_task(ppid, PIDTYPE_PID);
+
+ if (!tsk)
+ goto out_put_pid;
+
+ if (resource >= RLIM_NLIMITS)
+ goto out_put_all;
+
+ retval = -EBUSY;
+ if (!lock_task_sighand(tsk, &flags))

X task_lock below cannot nest inside sighand (according to Oleg)
X ->sighand/signal might be NULL here (and below) AFAICT
So we need tasklist_lock for reading and check sighand != NULL.

+ goto out_put_all;
+
+ else {
+ struct rlimit val;
+
+ task_lock(tsk->group_leader);
+ val = current->signal->rlim[resource];

Well, you meant tsk->signal->rlim[resource] :).

+ task_unlock(tsk->group_leader);
+ retval = copy_to_user(rlim, &val, sizeof(*rlim)) ? -EFAULT : 0;
+ }

If I'm totally overlooking something, please let me know, otherwise I'll
fix that in the way I wrote above. (The same holds for setprlimit.)

Thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/