From: David Howells <dhowells@redhat.com>
To: Kevin Qu <rofail@gmail.com>, Jeff Epler <jepler@unpythonic.net>
Cc: dhowells@redhat.com, linux-kernel@vger.kernel.org
Subject: Re: how to get right euid?
Date: Tue, 05 Jan 2010 16:00:33 +0000 [thread overview]
Message-ID: <17885.1262707233@redhat.com> (raw)
In-Reply-To: <78aa970c1001020516m3d2255fj38f02629e7d740c8@mail.gmail.com>
Kevin Qu <rofail@gmail.com> wrote:
> I wrote a kernel module and it create a "file" in /proc.
> The "file" permission is set to 644.
> When check access permission, I use :
Check where? In file_operations::open(), in file_operations::write() or in
inode_operations::permission()?
> if( op == 4 || (op ==2 && current->euid == 0) )
> return 0;
>
> But it does not work on 2.6.29,
> so I changed it like below:
>
> if( op & 0x4 || (op & 0x2 && current_euid() == 0) )
> return 0;
What is op? Is "op == N" equivalent to "op & N"? Should N be a symbolic
constant (MAY_READ or MAY_WRITE)?
> It works when read from the "file" in /proc,
> but when write to it with sudo, like:
>
> 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?
As Jeff said, where you're making the check matters.
In the above sudo command, the open() call is done by the shell, under the
EUID of whoever is logged in, whereas the write() call is done by the echo
command as executed by sudo, under the EUID set by sudo.
Note that if you're making the check in write(), the UID that you're checking
should be the one in struct file::f_cred.
David
prev parent reply other threads:[~2010-01-05 16:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-02 13:16 how to get right euid? Kevin Qu
2010-01-02 15:19 ` Jeff Epler
2010-01-05 16:00 ` David Howells [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=17885.1262707233@redhat.com \
--to=dhowells@redhat.com \
--cc=jepler@unpythonic.net \
--cc=linux-kernel@vger.kernel.org \
--cc=rofail@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox