linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kara <jack@suse.cz>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Henry Wilson <henry.wilson@acentic.com>, Jan Kara <jack@suse.cz>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	linux-api@vger.kernel.org
Subject: Re: [PATCH v4 4.17] inotify: Add flag IN_MASK_CREATE for inotify_add_watch()
Date: Thu, 31 May 2018 13:43:41 +0200	[thread overview]
Message-ID: <20180531114341.ytovomqmnvbomsxh@quack2.suse.cz> (raw)
In-Reply-To: <CAOQ4uxiB=fTgN8UwX7G69Sy6h4WQKr=3AF0i8apNEzkPH8F8rw@mail.gmail.com>

On Thu 31-05-18 13:38:47, Amir Goldstein wrote:
> On Thu, May 31, 2018 at 12:43 PM,  <henry.wilson@acentic.com> wrote:
> > From: Henry Wilson <henry.wilson@acentic.com>
> >
> > inotify: Add flag IN_MASK_CREATE for inotify_add_watch()
> >
> > The flag IN_MASK_CREATE is introduced as a flag for inotiy_add_watch() which
> > prevents inotify from modifying any existing watches when invoked. If the
> > pathname specified in the call has a watched inode associated with it and
> > IN_MASK_CREATE is specified, fail with an errno of EEXIST.
> >
> > Use of IN_MASK_CREATE with IN_MASK_ADD is reserved for future use and will return
> > EINVAL.
> >
> > RATIONALE
> >
> > In the current implementation, there is no way to prevent inotify_add_watch()
> > from modifying existing watch descriptors. Even if the caller keeps a record of
> > all watch descriptors collected, this is only sufficient to detect that an
> > existing watch descriptor may have been modified.
> >
> > The assumption that a particular path will map to the same inode over multiple
> > calls to inotify_add_watch() cannot be made as files can be renamed or deleted.
> > It is also not possible to assume that two distinct paths do no map to the same
> > inode, due to hard-links or a dereferenced symbolic link. Further uses of
> > inotify_add_watch() to revert the change may cause other watch descriptors to
> > be modified or created, merely compunding the problem. There is currently no
> > system call such as inotify_modify_watch() to explicity modify a watch
> > descriptor, which would be able to revert unwanted changes. Thus the caller
> > cannot guarantee to be able to revert any changes to existing watch decriptors.
> >
> > Additionally the caller cannot assume that the events that are associated with a
> > watch descriptor are within the set requested, as any future calls to
> > inotify_add_watch() may unintentionally modify a watch descriptor's mask. Thus
> > it cannot currently be guaranteed that a watch descriptor will only generate
> > events which have been requested. The program must filter events which come
> > through its watch descriptor to within its expected range.
> >
> > Signed-off-by: Henry Wilson <henry.wilson@acentic.com>
> 
> Reviewed-by: Amir Goldstein <amir73il@gmail.com>
> 
> See one suggestions below.
> 
> > ---
> >
> > EXTENSIONS
> >
> > A new system call inotify_modify_watch(fd, wd, mask) would be useful to modify
> > an existing watch directly to avoid similar problems when modifying a watch
> > descriptor's mask
> >
> > CHANGELOG
> >
> > v2: updated inotify_user_init() to the increased size of INOTIFY_ALL_BITS
> > v3: renamed IN_ONLY_CREATE to IN_EXCL_ADD
> >     additional rational for the change introduced to commit
> > v4: renamed IN_EXCL_ADD to IN_MASK_CREATE
> >     EINVAL returned when attempting to use IN_MASK_CREATE and IN_MASK_ADD
> > ---
> >  fs/notify/inotify/inotify_user.c | 9 ++++++++-
> >  include/linux/inotify.h          | 2 +-
> >  include/uapi/linux/inotify.h     | 1 +
> >  3 files changed, 10 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
> > index ef32f3657958..134e9c5308c8 100644
> > --- a/fs/notify/inotify/inotify_user.c
> > +++ b/fs/notify/inotify/inotify_user.c
> > @@ -506,6 +506,7 @@ static int inotify_update_existing_watch(struct fsnotify_group *group,
> >         __u32 old_mask, new_mask;
> >         __u32 mask;
> >         int add = (arg & IN_MASK_ADD);
> > +       int create = (arg & IN_MASK_CREATE);
> >         int ret;
> >
> 
> Exclusive flag validation would look nicer here...
> 
>    if (add && create)
>       return -EINVAL;
> 
> >         mask = inotify_arg_to_mask(arg);
> > @@ -513,6 +514,8 @@ static int inotify_update_existing_watch(struct fsnotify_group *group,
> >         fsn_mark = fsnotify_find_mark(&inode->i_fsnotify_marks, group);
> >         if (!fsn_mark)
> >                 return -ENOENT;
> > +       else if (create)
> > +               return -EEXIST;
> >
> >         i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark);
> >
> > @@ -714,6 +717,10 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,
> >         if (unlikely(!f.file))
> >                 return -EBADF;
> >
> > +       /* IN_MASK_ADD and IN_MASK_CREATE don't make sense together */
> > +       if (unlikely((mask & IN_MASK_ADD) && (mask & IN_MASK_CREATE)))
> > +               return -EINVAL;
> > +
> 
> ..., but it may be safer practice
> to keep it in the outer syscall interface, so not sure.

Yeah, I think the outer interface is better for clarity. I'll take the
patch as is. Thanks for your review.

							Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

      reply	other threads:[~2018-05-31 11:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-03 15:24 [PATCH 4.17] inotify: Add flag IN_ONLY_CREATE for inotify_add_watch() Henry Wilson
2018-05-03 19:42 ` Amir Goldstein
2018-05-04  8:44   ` Henry Wilson
2018-05-16 10:44 ` [PATCH v2 4.17] From: Henry Wilson <henry.wilson@acentic.com> henry.wilson
2018-05-29  9:15   ` Jan Kara
2018-05-29 11:03     ` Henry Wilson
2018-05-29 12:15       ` Jan Kara
2018-05-30 11:00         ` Henry Wilson
2018-05-30 10:26   ` [PATCH v3 4.17] inotify: Add flag IN_EXCL_ADD for inotify_add_watch() henry.wilson
2018-05-30 13:01     ` Jan Kara
2018-05-30 13:35       ` Henry Wilson
2018-05-30 15:40         ` Amir Goldstein
2018-05-30 16:04           ` Jan Kara
2018-05-30 19:03             ` Amir Goldstein
2018-05-31  9:42               ` Jan Kara
2018-05-31  8:22             ` Henry Wilson
2018-05-31 10:24               ` Amir Goldstein
2018-05-30 16:10           ` Randy Dunlap
2018-05-31  9:43     ` [PATCH v4 4.17] inotify: Add flag IN_MASK_CREATE " henry.wilson
2018-05-31 10:38       ` Amir Goldstein
2018-05-31 11:43         ` Jan Kara [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=20180531114341.ytovomqmnvbomsxh@quack2.suse.cz \
    --to=jack@suse.cz \
    --cc=amir73il@gmail.com \
    --cc=henry.wilson@acentic.com \
    --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
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).