Linux-Fsdevel Archive on lore.kernel.org
 help / color / Atom feed
From: Matthew Bobrowski <repnop@google.com>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Jan Kara <jack@suse.cz>,
	Christian Brauner <christian.brauner@ubuntu.com>,
	Linux API <linux-api@vger.kernel.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: [PATCH 2/2] fanotify: Add pidfd support to the fanotify API
Date: Mon, 26 Apr 2021 20:26:53 +1000
Message-ID: <YIaVbWu8up3RY7gf@google.com> (raw)
In-Reply-To: <CAOQ4uxhyGKSM3LFKRtgNe+HmkUJRCFwafXdgC_8ysg7Bs43rWg@mail.gmail.com>

On Fri, Apr 23, 2021 at 11:14:34AM +0300, Amir Goldstein wrote:
> On Fri, Apr 23, 2021 at 11:02 AM Matthew Bobrowski <repnop@google.com> wrote:
> >
> > On Fri, Apr 23, 2021 at 10:39:46AM +0300, Amir Goldstein wrote:
> > > On Fri, Apr 23, 2021 at 2:06 AM Matthew Bobrowski <repnop@google.com> wrote:
> > > >
> > > > On Wed, Apr 21, 2021 at 10:04:49AM +0200, Jan Kara wrote:
> > > > > On Tue 20-04-21 12:36:59, Matthew Bobrowski wrote:
> > > > > > On Mon, Apr 19, 2021 at 05:02:33PM +0200, Christian Brauner wrote:
> > > > > > > A general question about struct fanotify_event_metadata and its
> > > > > > > extensibility model:
> > > > > > > looking through the code it seems that this struct is read via
> > > > > > > fanotify_rad(). So the user is expected to supply a buffer with at least
> > > > > > >
> > > > > > > #define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata))
> > > > > > >
> > > > > > > bytes. In addition you can return the info to the user about how many
> > > > > > > bytes the kernel has written from fanotify_read().
> > > > > > >
> > > > > > > So afaict extending fanotify_event_metadata should be _fairly_
> > > > > > > straightforward, right? It would essentially the complement to
> > > > > > > copy_struct_from_user() which Aleksa and I added (1 or 2 years ago)
> > > > > > > which deals with user->kernel and you're dealing with kernel->user:
> > > > > > > - If the user supplied a buffer smaller than the minimum known struct
> > > > > > >   size -> reject.
> > > > > > > - If the user supplied a buffer < smaller than what the current kernel
> > > > > > >   supports -> copy only what userspace knows about, and return the size
> > > > > > >   userspace knows about.
> > > > > > > - If the user supplied a buffer that is larger than what the current
> > > > > > >   kernel knows about -> copy only what the kernel knows about, zero the
> > > > > > >   rest, and return the kernel size.
> > > > > > >
> > > > > > > Extension should then be fairly straightforward (64bit aligned
> > > > > > > increments)?
> > > > > >
> > > > > > You'd think that it's fairly straightforward, but I have a feeling
> > > > > > that the whole fanotify_event_metadata extensibility discussion and
> > > > > > the current limitation to do so revolves around whether it can be
> > > > > > achieved in a way which can guarantee that no userspace applications
> > > > > > would break. I think the answer to this is that there's no guarantee
> > > > > > because of <<reasons>>, so the decision to extend fanotify's feature
> > > > > > set was done via other means i.e. introduction of additional
> > > > > > structures.
> > > > >
> > > > > There's no real problem extending fanotify_event_metadata. We already have
> > > > > multiple extended version of that structure in use (see e.g. FAN_REPORT_FID
> > > > > flag and its effect, extended versions of the structure in
> > > > > include/uapi/linux/fanotify.h). The key for backward compatibility is to
> > > > > create extended struct only when explicitely requested by a flag when
> > > > > creating notification group - and that would be the case here -
> > > > > FAN_REPORT_PIDFD or how you called it. It is just that extending the
> > > > > structure means adding 8 bytes to each event and parsing extended structure
> > > > > is more cumbersome than just fetching s32 from a well known location.
> > > > >
> > > > > On the other hand extended structure is self-describing (i.e., you can tell
> > > > > the meaning of all the fields just from the event you receive) while
> > > > > reusing 'pid' field means that you have to know how the notification group
> > > > > was created (whether FAN_REPORT_PIDFD was used or not) to be able to
> > > > > interpret the contents of the event. Actually I think the self-describing
> > > > > feature of fanotify event stream is useful (e.g. when application manages
> > > > > multiple fanotify groups or when fanotify group descriptors are passed
> > > > > among processes) so now I'm more leaning towards using the extended
> > > > > structure instead of reusing 'pid' as Christian suggests. I'm sorry for the
> > > > > confusion.
> > > >
> > > > This approach makes sense to me.
> > > >
> > > > Jan/Amir, just to be clear, we've agreed to go ahead with the extended
> > > > struct approach whereby specifying the FAN_REPORT_PIDFD flag will
> > > > result in an event which includes an additional struct
> > > > (i.e. fanotify_event_info_pid) alongside the generic existing
> > >
> > > struct fanotify_event_info_pidfd?
> >
> > Well, yeah? I mean, my line of thought was that we'd also need to
> > include struct fanotify_event_info_header alongside the event to
> > provide more meta-information about the additional event you'd expect
> > to receive when FAN_REPORT_PIDFD is provided, so we'd end up with
> > something like:
> >
> > struct fanotify_event_info_pidfd {
> >        struct fanotify_event_info_header hdr;
> >        __s32 pidfd;
> > }
> >
> > Unless this of course is overbaking it and there's no need to do this?
> >
> 
> We need this. I was just pointing out that you wrote fanotify_event_info_pid
> must have been a typo.

Oh, right, that sure was a typo! :)

Amir, I was just thinking about this a little over the weekend and I
don't think we discussed how to handle the FAN_REPORT_PIDFD |
FAN_REPORT_FID and friends case? My immediate thought is to make
FAN_REPORT_PIDFD mutually exclusive with FAN_REPORT_FID and friends,
but then again receiving a pidfd along with FID events may be also
useful for some? What are your thoughts on this? If we don't go ahead
with mutual exclusion, then this multiple event types alongside struct
fanotify_event_metadata starts getting a little clunky, don't you
think?

/M

  reply index

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-15 23:21 [PATCH 0/2] fanotify: Adding " Matthew Bobrowski
2021-04-15 23:22 ` [PATCH 1/2] pidfd_create(): remove static qualifier and declare pidfd_create() in linux/pid.h Matthew Bobrowski
2021-04-19 10:13   ` Jan Kara
2021-04-19 12:50   ` Christian Brauner
2021-04-20  0:17     ` Matthew Bobrowski
2021-04-15 23:22 ` [PATCH 2/2] fanotify: Add pidfd support to the fanotify API Matthew Bobrowski
2021-04-16  6:27   ` Amir Goldstein
2021-04-16  7:05     ` Matthew Bobrowski
2021-04-16  7:53       ` Amir Goldstein
2021-04-16  8:08         ` Matthew Bobrowski
2021-04-19 13:02     ` Christian Brauner
2021-04-19 10:21   ` Jan Kara
2021-04-20  1:35     ` Matthew Bobrowski
2021-04-19 13:20   ` Christian Brauner
2021-04-19 13:53     ` Amir Goldstein
2021-04-19 14:44       ` Christian Brauner
2021-04-19 13:55     ` Jan Kara
2021-04-19 15:02       ` Christian Brauner
2021-04-20  2:36         ` Matthew Bobrowski
2021-04-21  8:04           ` Jan Kara
2021-04-21  9:29             ` Amir Goldstein
2021-04-21 10:00               ` Jan Kara
2021-04-21 10:12                 ` Amir Goldstein
2021-04-21 13:48                   ` Jan Kara
2021-04-21 14:46                     ` Christian Brauner
2021-04-22 23:06             ` Matthew Bobrowski
2021-04-23  7:39               ` Amir Goldstein
2021-04-23  8:02                 ` Matthew Bobrowski
2021-04-23  8:14                   ` Amir Goldstein
2021-04-26 10:26                     ` Matthew Bobrowski [this message]
2021-04-26 11:11                       ` Amir Goldstein
2021-04-27  3:35                         ` Matthew Bobrowski
2021-04-27  5:14                           ` Amir Goldstein
2021-04-28 22:53                             ` Matthew Bobrowski
2021-04-19 12:34 ` [PATCH 0/2] fanotify: Adding " Christian Brauner

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=YIaVbWu8up3RY7gf@google.com \
    --to=repnop@google.com \
    --cc=amir73il@gmail.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=jack@suse.cz \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-fsdevel@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

Linux-Fsdevel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-fsdevel/0 linux-fsdevel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-fsdevel linux-fsdevel/ https://lore.kernel.org/linux-fsdevel \
		linux-fsdevel@vger.kernel.org
	public-inbox-index linux-fsdevel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-fsdevel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git