Re: [PATCH 3/5] exec: unify compat_do_execve() code
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: 2011-02-25 19:11:38
Also in:
lkml
On Fri, Feb 25, 2011 at 9:53 AM, Oleg Nesterov [off-list ref] wrote:
Teach get_arg_ptr() to handle compat = T case correctly.
Does it?
+#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,
+ regs, true);
+}
+#endif
I really suspect this should be something like
typedef union {
compat_uptr_t compat;
const char __user *native;
} conditional_user_ptr_t;
...
int compat_do_execve(char *filename,
compat_uptr_t argv,
compat_uptr_t envp,
struct pt_regs *regs)
{
return do_execve_common(filename,
compat_ptr(argv), compat_ptr(envp), regs);
where that 'do_execve_common()' takes it's arguments as
union conditional_user_ptr_t __user *argv,
union conditional_user_ptr_t __user *envp
and then in get_arg_ptr() we do the proper union member dereference
depending on the "compat" flag.
THAT would actually have the type system help us track what is
actually going on, and would clarify the rules. It would also make it
clear that "do_execve_common()" does *not* take some kind of random
pointer to user space (much less a "const char __user *const char
__user *"). It really does take a pointer to user space, but what that
pointer contains in turn depends on the "compat" flag.
IOW, it really acts as a pointer to a user-space union, and I think
we'd be better off having the type show that.
Linus
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>