mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kay Sievers <kay.sievers@vrfy.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Al Viro <viro@zeniv.linux.org.uk>,
	Kernel development list <linux-kernel@vger.kernel.org>
Subject: Re: How to tell whether a struct file is held by a process?
Date: Thu, 21 May 2009 23:07:29 +0200	[thread overview]
Message-ID: <ac3eb2510905211407l3aec14acx2572a2ad4e675b9@mail.gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0905210945290.2886-100000@iolanthe.rowland.org>

On Thu, May 21, 2009 at 16:06, Alan Stern <stern@rowland.harvard.edu> wrote:
> On Thu, 21 May 2009, Al Viro wrote:
>> On Tue, May 19, 2009 at 12:57:21PM -0400, Alan Stern wrote:
>> > What's the best way to tell whether the current process has a
>> > particular struct file among its open files?  Is there any better way
>> > to find out than blindly calling fget() for each possible fd?
>> >
>> > Is this a totally insane thing to do?
>>
>> It is insane.  You might lock fdtable and scan it, but as soon as you
>> drop the spinlock your return value is worthless.
>
> In this case, I believe that changes after the check has been made
> won't hurt -- everything relevant to my work will be serialized by a
> separate lock.
>
>> What are you trying to do?  If the process is cooperating, you don't really
>> need that in the kernel, if it's not, the check is not usable...
>
> I'm trying to work out a good way to reserve access rights to a device
> -- even if that device doesn't exist yet.
>
> Here's the story.  People have requested that the kernel add a
> mechanism whereby a user program can get more-or-less exclusive access
> rights to a USB device.  In fact, they'd like to reserve these rights
> for any device plugged into a particular USB port.  So even if no
> device is plugged into that port at the moment, the program should get
> exclusive access as soon as a new device is detected there.
>
> In order to prevent programs from dying without releasing their
> exclusive rights, it seems natural to implement these rights as open
> files.  Thus, opening file A(P) will give a program exclusive access
> rights to any device plugged into USB port P.  Closing A(P) releases
> the rights.  (The A(P) files would be implemented as single-open files,
> probably in sysfs.)
>
> The problem is this.  Let D be the device plugged into port P.  When
> some program opens D's device file, it's necessary to check whether
> that same program has an open file reference for A(P), i.e., has opened
> A(P), or has inherited a descriptor for A(P) from its parent, or has
> been passed such a descriptor over a Unix socket, etc.  If not, and if
> A(P) is open (owned by someone else), then access to D is denied.
>
> If you can think up a better way to implement these exclusive access
> rights, I'd be glad to hear it.

Not sure, if we already discussed that with a conclusion: this
"prevent access to a future device" interface needs to work at the pid
level, or would a uid/gid check be sufficient?

Root can do all that stuff anyway, even with the locking in place.
Uid/gid file permissions need to be applied to the "lock file", so
specified non-root users can use that interface.

Maybe it would be good enough, to check that the one that opened the
"lock file" has the same uid/gid as the on that tries to open the
device when it has shown up?

Kay

  reply	other threads:[~2009-05-21 21:07 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-19 16:57 Alan Stern
2009-05-21  9:52 ` Al Viro
2009-05-21 14:06   ` Alan Stern
2009-05-21 21:07     ` Kay Sievers [this message]
2009-05-21 21:27       ` Alan Stern
2009-05-22 13:30         ` Pantelis Koukousoulas
2009-05-22 13:38           ` Oliver Neukum
2009-05-22 13:43           ` Alan Cox
2009-05-22 13:52             ` Pantelis Koukousoulas
2009-05-22 14:12               ` Alan Cox
2009-05-22 14:29                 ` Pantelis Koukousoulas
2009-05-21 22:14       ` Alan Cox
2009-05-22  1:28         ` Kyle Moffett
2009-05-22  9:53           ` Alan Cox
2009-05-22 15:12             ` Alan Stern
2009-05-22 15:20               ` Alan Cox
2009-05-22 16:04                 ` Alan Stern
2009-05-22 16:23                   ` Pantelis Koukousoulas
2009-05-22 18:19                     ` Alan Stern
2009-05-22 15:21               ` Kay Sievers
2009-05-22 15:54                 ` Alan Stern
2009-05-22 18:24                   ` Kay Sievers
2009-05-22 18:48                     ` Pantelis Koukousoulas
2009-05-22 19:31                     ` Alan Stern
2009-05-22 21:54                       ` Kay Sievers
2009-05-22 22:07                         ` Alan Stern
2009-05-23 22:47                           ` Kay Sievers
2009-05-22  8:36         ` Oliver Neukum
2009-05-21 22:22     ` Alan Cox
2009-05-22 12:26     ` Oliver Neukum

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=ac3eb2510905211407l3aec14acx2572a2ad4e675b9@mail.gmail.com \
    --to=kay.sievers@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®