From: Jan Kara <jack@suse.cz>
To: Richard Guy Briggs <rgb@redhat.com>
Cc: Jan Kara <jack@suse.cz>,
Linux-Audit Mailing List <linux-audit@redhat.com>,
LKML <linux-kernel@vger.kernel.org>,
linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org,
Paul Moore <paul@paul-moore.com>,
Eric Paris <eparis@parisplace.org>,
Steve Grubb <sgrubb@redhat.com>,
Amir Goldstein <amir73il@gmail.com>
Subject: Re: [PATCH v5 2/3] fanotify: define struct members to hold response decision context
Date: Tue, 17 Jan 2023 09:27:23 +0100 [thread overview]
Message-ID: <20230117082723.7g3ig6ernoslt7ub@quack3> (raw)
In-Reply-To: <Y8W2tcXFoUajzojc@madcap2.tricolour.ca>
On Mon 16-01-23 15:42:29, Richard Guy Briggs wrote:
> On 2023-01-03 13:42, Jan Kara wrote:
> > On Thu 22-12-22 15:47:21, Richard Guy Briggs wrote:
> > > > > +
> > > > > + if (info_len != sizeof(*friar))
> > > > > + return -EINVAL;
> > > > > +
> > > > > + if (copy_from_user(friar, info, sizeof(*friar)))
> > > > > + return -EFAULT;
> > > > > +
> > > > > + if (friar->hdr.type != FAN_RESPONSE_INFO_AUDIT_RULE)
> > > > > + return -EINVAL;
> > > > > + if (friar->hdr.pad != 0)
> > > > > + return -EINVAL;
> > > > > + if (friar->hdr.len != sizeof(*friar))
> > > > > + return -EINVAL;
> > > > > +
> > > > > + return info_len;
> > > > > +}
> > > > > +
> > > >
> > > > ...
> > > >
> > > > > @@ -327,10 +359,18 @@ static int process_access_response(struct fsnotify_group *group,
> > > > > return -EINVAL;
> > > > > }
> > > > >
> > > > > - if (fd < 0)
> > > > > + if ((response & FAN_AUDIT) && !FAN_GROUP_FLAG(group, FAN_ENABLE_AUDIT))
> > > > > return -EINVAL;
> > > > >
> > > > > - if ((response & FAN_AUDIT) && !FAN_GROUP_FLAG(group, FAN_ENABLE_AUDIT))
> > > > > + if (response & FAN_INFO) {
> > > > > + ret = process_access_response_info(fd, info, info_len, &friar);
> > > > > + if (ret < 0)
> > > > > + return ret;
> > > > > + } else {
> > > > > + ret = 0;
> > > > > + }
> > > > > +
> > > > > + if (fd < 0)
> > > > > return -EINVAL;
> > > >
> > > > And here I'd do:
> > > >
> > > > if (fd == FAN_NOFD)
> > > > return 0;
> > > > if (fd < 0)
> > > > return -EINVAL;
> > > >
> > > > As we talked in previous revisions we'd specialcase FAN_NOFD to just verify
> > > > extra info is understood by the kernel so that application writing fanotify
> > > > responses has a way to check which information it can provide to the
> > > > kernel.
> > >
> > > The reason for including it in process_access_response_info() is to make
> > > sure that it is included in the FAN_INFO case to detect this extension.
> > > If it were included here
> >
> > I see what you're getting at now. So the condition
> >
> > if (fd == FAN_NOFD)
> > return 0;
> >
> > needs to be moved into
> >
> > if (response & FAN_INFO)
> >
> > branch after process_access_response_info(). I still prefer to keep it
> > outside of the process_access_response_info() function itself as it looks
> > more logical to me. Does it address your concerns?
>
> Ok. Note that this does not return zero to userspace, since this
> function's return value is added to the size of the struct
> fanotify_response when there is no error.
Right, good point. 0 is not a good return value in this case.
> For that reason, I think it makes more sense to return -ENOENT, or some
> other unused error code that fits, unless you think it is acceptable to
> return sizeof(struct fanotify_response) when FAN_INFO is set to indicate
> this.
Yeah, my intention was to indicate "success" to userspace so I'd like to
return whatever we return for the case when struct fanotify_response is
accepted for a normal file descriptor - looks like info_len is the right
value. Thanks!
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2023-01-17 8:27 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-12 14:06 [PATCH v5 0/3] fanotify: Allow user space to pass back additional audit info Richard Guy Briggs
2022-12-12 14:06 ` [PATCH v5 1/3] fanotify: Ensure consistent variable type for response Richard Guy Briggs
2022-12-20 23:30 ` Paul Moore
2022-12-12 14:06 ` [PATCH v5 2/3] fanotify: define struct members to hold response decision context Richard Guy Briggs
2022-12-16 16:43 ` Jan Kara
2022-12-16 17:05 ` Paul Moore
2022-12-19 10:10 ` Jan Kara
2022-12-22 20:47 ` Richard Guy Briggs
2023-01-03 12:42 ` Jan Kara
2023-01-16 20:42 ` Richard Guy Briggs
2023-01-17 8:27 ` Jan Kara [this message]
2023-01-17 19:33 ` Richard Guy Briggs
2022-12-12 14:06 ` [PATCH v5 3/3] fanotify,audit: Allow audit to use the full permission event response Richard Guy Briggs
2022-12-20 23:31 ` Paul Moore
2022-12-22 20:42 ` Richard Guy Briggs
2022-12-22 21:16 ` Paul Moore
2023-01-10 0:06 ` Steve Grubb
2023-01-10 3:08 ` Richard Guy Briggs
2023-01-10 15:26 ` Steve Grubb
2023-01-10 18:32 ` [PATCH v5 3/3] fanotify, audit: " Richard Guy Briggs
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=20230117082723.7g3ig6ernoslt7ub@quack3 \
--to=jack@suse.cz \
--cc=amir73il@gmail.com \
--cc=eparis@parisplace.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-audit@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=rgb@redhat.com \
--cc=sgrubb@redhat.com \
/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).