linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Helsley <matt.helsley@gmail.com>
To: Eric Paris <eparis@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	viro@zeniv.linux.org.uk, hch@infradead.org, agruen@suse.de,
	containers@lists.linux-foundation.org, matthltc@us.ibm.com,
	Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>,
	Oleg Nesterov <oleg@redhat.com>
Subject: Re: [PATCH 2/4] fanotify: Add pids to events
Date: Thu, 14 Jan 2010 20:41:10 -0800	[thread overview]
Message-ID: <6a12d2f31001142041j7f917b07l1e1a728790175321@mail.gmail.com> (raw)
In-Reply-To: <20091202141458.12819.96170.stgit@paris.rdu.redhat.com>

On Wed, Dec 2, 2009 at 6:14 AM, Eric Paris <eparis@redhat.com> wrote:
> From: Andreas Gruenbacher <agruen@suse.de>
>
> Pass the process identifiers of the triggering processes to fanotify
> listeners: this information is useful for event filtering and logging.
>
> Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
> Signed-off-by: Eric Paris <eparis@redhat.com>
> ---
>
>  fs/notify/fanotify/fanotify.c      |    5 +++--
>  fs/notify/fanotify/fanotify_user.c |    1 +
>  fs/notify/notification.c           |    3 +++
>  include/linux/fanotify.h           |    1 +
>  include/linux/fsnotify_backend.h   |    1 +
>  5 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
> index 5b0b6b4..881067d 100644
> --- a/fs/notify/fanotify/fanotify.c
> +++ b/fs/notify/fanotify/fanotify.c
> @@ -10,8 +10,9 @@ static bool should_merge(struct fsnotify_event *old, struct fsnotify_event *new)
>  {
>        pr_debug("%s: old=%p new=%p\n", __func__, old, new);
>
> -       if ((old->to_tell == new->to_tell) &&
> -           (old->data_type == new->data_type)) {
> +       if (old->to_tell == new->to_tell &&
> +           old->data_type == new->data_type &&
> +           old->tgid == new->tgid) {
>                switch (old->data_type) {
>                case (FSNOTIFY_EVENT_PATH):
>                        if ((old->path.mnt == new->path.mnt) &&
> diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
> index 7646111..7cfb2f6 100644
> --- a/fs/notify/fanotify/fanotify_user.c
> +++ b/fs/notify/fanotify/fanotify_user.c
> @@ -108,6 +108,7 @@ static ssize_t fill_event_metadata(struct fsnotify_group *group,
>        metadata->event_len = FAN_EVENT_METADATA_LEN;
>        metadata->vers = FANOTIFY_METADATA_VERSION;
>        metadata->mask = fanotify_outgoing_mask(event->mask);
> +       metadata->pid = pid_vnr(event->tgid);

Eric, you never replied to my point about pid namespaces
(http://lkml.org/lkml/2009/7/1/2). I'm still concerned that it's a
problem for this patch. I've cc'd some pid namespace folks, listed the
problems, and some alternative solutions (where I could think of any)
below:

1. Since fanotify doesn't hold a reference to the struct pid then the
pid can become stale before the event is acted upon.
    solution a: Just ignoring this problem, like other interfaces
often do, is probably ok.
    ... ?
    solution z: Seems to require taking a reference to the pid and
giving userspace a way to drop the reference after it's done using
this value to refer to the process (yuck).

2. If the event recipient does a clone and enters a new pidns the pid
number will be incorrect without any indication.
  solution a: The events could be flushed during clone(CLONE_NEWPID)
but then userspace would miss
      them.
  solution b: Translating the pids wouldn't work because the tasks
generaly won't exist in the new
      namespace. So perhaps just write negative values in the pid
fields during clone(CLONE_NEWPID).

3. If the listening process is not in the same or an ancestor pid
namespace of the triggering process then there is no correct pid
corresponding to the event.  (Note: Always using the initial pid
namespace isn't a good [interim] solution -- then programs relying on
fanotify couldn't run in other pid namespaces).
    solution a: Again, perhaps they should be set to negative values.
    ... ?
    solution z: Disable fanotify in non-initial pid namespaces (yuck).

Cheers,
    -Matt Helsley
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2010-01-15  4:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-02 14:14 [PATCH 1/4] fanotify: create_fd cleanup Eric Paris
2009-12-02 14:14 ` [PATCH 2/4] fanotify: Add pids to events Eric Paris
2010-01-15  4:41   ` Matthew Helsley [this message]
     [not found]     ` <6a12d2f31001142041j7f917b07l1e1a728790175321-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-01-15 15:12       ` Andreas Gruenbacher
2010-01-15 21:21         ` Matt Helsley
2010-01-16 22:53           ` Andreas Gruenbacher
2010-01-17  3:44             ` Matt Helsley
2009-12-02 14:15 ` [PATCH 3/4] fsnotify: split generic and inode specific mark code Eric Paris
2009-12-02 14:15 ` [PATCH 4/4] fsnotify: clear marks to 0 in fsnotify_init_mark Eric Paris

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=6a12d2f31001142041j7f917b07l1e1a728790175321@mail.gmail.com \
    --to=matt.helsley@gmail.com \
    --cc=agruen@suse.de \
    --cc=containers@lists.linux-foundation.org \
    --cc=eparis@redhat.com \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthltc@us.ibm.com \
    --cc=oleg@redhat.com \
    --cc=sukadev@linux.vnet.ibm.com \
    --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;
as well as URLs for NNTP newsgroup(s).