Re: [PATCH 0/4 RESEND] exec: unify compat/non-compat code

From: Linus Torvalds
Date: Fri Feb 25 2011 - 13:55:28 EST

On Fri, Feb 25, 2011 at 9:52 AM, Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
>> On 12/01, Milton Miller wrote:
>> >
>> > > +#ifdef CONFIG_COMPAT
>> > > +int compat_do_execve(char * filename,
>> > > + compat_uptr_t __user *argv,
>> > > + compat_uptr_t __user *envp,
>> > > + struct pt_regs * regs)
>> > > +{
>> > > + return do_execve_common(filename,
>> > > +                         (void __user*)argv, (void __user*)envp,
>> >
>> > Shouldn't these be compat_ptr(argv)?  (makes a difference on s390)

Indeed. The "compat_uptr_t __user *argv" is wrong, and it should be just

compat_uptr_t argv;

and then every time you turn it into a pointer, it should use

Then, since it's a pointer to an array of pointers, when you do that,
you should turn it into a pointer to "compat_uptr_t", so you actually
have this:

- user passes "compat_uptr_t"

- the kernel can turn that into "compat_uptr_t __user *" by doing

compat_uptr_t __user *pptr;
pptr = compat_ptr(argv);

- the kernel needs to fetch the individual entries with

compat_uptr_t cuptr = get_user(pptr);

- the kernel can then turn _those_ into the actual pointers to the string with

const char __user *str = compat_ptr(cuptr);

so you need two levels of compat_ptr() conversion.

> So, once again, this should not (and can not) be compat_ptr(argv) afaics.

It can be, and probably should. But the low-level s390 wrapper
function may have done one of the levels already. It probably
shouldn't, and we _should_ do the "compat_ptr()" thing a the generic C
level. That's what we do with all the other pointers, after all.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at