Re: how to get right euid?

From: Jeff Epler
Date: Sat Jan 02 2010 - 10:19:36 EST


On Sat, Jan 02, 2010 at 09:16:42PM +0800, Kevin Qu wrote:
> sudo echo "some thing" > /proc/my_file
>
> It denied. (But it works when I su to superuser and do so.)
>
> So I checked the current_euid(),
> but it returns 1000 (not 0),Why?

This may be due to a misunderstanding of how shell redirects work.
Probably current_euid() is returning exactly the right thing.

When you execute
some command line > somefile
the shell opens somefile for writing and makes it be fd 1 (stdout) using
dup2. Then it execs 'some' with the argument array being
['some', 'command', 'line'].

So consider your sudo: The shell, running as user 1000, opens
'somefile' for writing, then execs 'sudo' which happens to be setuid
root.

Jeff
--
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/