linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ryan Mallon <rmallon@gmail.com>
To: Ulrich Windl <Ulrich.Windl@rz.uni-regensburg.de>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Antw: Re: /sys and access(2): Correctly implemented?
Date: Mon, 09 Jul 2012 17:22:45 +1000	[thread overview]
Message-ID: <4FFA86C5.7090601@gmail.com> (raw)
In-Reply-To: <4FFA950B020000A10000A68F@gwsmtp1.uni-regensburg.de>

On 09/07/12 16:23, Ulrich Windl wrote:
>>>> Ryan Mallon <rmallon@gmail.com> schrieb am 09.07.2012 um 01:24 in Nachricht
> <4FFA16B6.9050009@gmail.com>:
>> On 06/07/12 16:27, Ulrich Windl wrote:
>>> Hi!
>>>
>>> Recently I found a problem with the command (kernel 3.0.34-0.7-default from 
>> SLES 11 SP2, run as root):
>>> test -r "$file" && cat "$file"
>>> emitting "Permission denied"
>>>
>>> Investigating, I found that "test" actually uses "access()" to check for 
>> permissions. Unfortunately there are some files in /sys that have "write-only" 
>> permission bits set (e.g. /sys/devices/system/cpu/probe).
>>>
>>> ~ # ll /sys/devices/system/cpu/probe
>>> --w------- 1 root root 4096 Jun 29 12:43 /sys/devices/system/cpu/probe
>>> ~ # F=/sys/devices/system/cpu/probe
>>> ~ # test "$F" && cat "$F"
>>> cat: /sys/devices/system/cpu/probe: Permission denied
>>
>> Looks like you have a typo here, I think you wanted "test -r $F", not
>> "test $F", the latter will just evaluate "$F" as an expression which
>> will be true, and so you get the permission denied error running cat.
> 
> Hi!
> 
> You are right: It's a typo, but only in the message; the actual test was done correctly, and the outcome is quite the same.
> 
>>
>> Using "test -r $F" on a write-only sysfs file correctly returns false on
>> my machine (Ubuntu 10.04.4 LTS/2.6.32-41-generic).
> 
> Not here, unfortunately:

Oops, I missed the bit about you running as root. I get the same results
running as root on my machine as you, both for sysfs and regular files.

It appears that access(2) as the super-user is might be implementation
defined, see:

  http://pubs.opengroup.org/onlinepubs/000095399/functions/access.html
  http://lists.gnu.org/archive/html/bug-bash/2010-07/msg00071.html

However, I can't find any concrete information on it for Linux, and the
manpage doesn't mention anything other the the X_OK bit.

~Ryan

  reply	other threads:[~2012-07-09  7:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-06  6:27 /sys and access(2): Correctly implemented? Ulrich Windl
2012-07-08 23:24 ` Ryan Mallon
2012-07-09  6:23   ` Antw: " Ulrich Windl
2012-07-09  7:22     ` Ryan Mallon [this message]
2012-07-09  8:11       ` Ulrich Windl

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=4FFA86C5.7090601@gmail.com \
    --to=rmallon@gmail.com \
    --cc=Ulrich.Windl@rz.uni-regensburg.de \
    --cc=linux-kernel@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).