From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: Greg Kurz <groug@kaod.org>
Cc: v9fs-developer@lists.sourceforge.net,
Latchesar Ionkov <lucho@ionkov.net>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Eric Van Hensbergen <ericvh@gmail.com>,
Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Dominique Martinet <asmadeus@codewreck.org>
Subject: Re: [V9fs-developer] [PATCH kernel] 9p/trans_fd: Check file mode at opening
Date: Wed, 29 Jul 2020 09:50:21 +1000 [thread overview]
Message-ID: <ceaa4de6-e4df-e6b0-8085-7020240c57b4@ozlabs.ru> (raw)
In-Reply-To: <20200728194235.52660c08@bahia.lan>
On 29/07/2020 03:42, Greg Kurz wrote:
> Hi Alexey,
>
> Working on 9p now ?!? ;-)
No, I am running syzkaller and seeing things :)
> Cc'ing Dominique Martinet who appears to be the person who takes care of 9p
> these days.
>
> On Tue, 28 Jul 2020 22:41:29 +1000
> Alexey Kardashevskiy <aik@ozlabs.ru> wrote:
>
>> The "fd" transport layer uses 2 file descriptors passed externally
>> and calls kernel_write()/kernel_read() on these. If files were opened
>> without FMODE_WRITE/FMODE_READ, WARN_ON_ONCE() will fire.
>>
>> This adds file mode checking in p9_fd_open; this returns -EBADF to
>> preserve the original behavior.
>>
>
> So this would cause open() to fail with EBADF, which might look a bit
> weird to userspace since it didn't pass an fd... Is this to have a
> different error than -EIO that is returned when either rfd or wfd
> doesn't point to an open file descriptor ?
This is only to preserve the existing behavior.
> If yes, why do we care ?
Without the patch, p9_fd_open() produces a kernel warning which is not
great by itself and becomes crash with panic_on_warn.
>
>> Found by syzkaller.
>>
>> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
>> ---
>> net/9p/trans_fd.c | 7 ++++++-
>> 1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
>> index 13cd683a658a..62cdfbd01f0a 100644
>> --- a/net/9p/trans_fd.c
>> +++ b/net/9p/trans_fd.c
>> @@ -797,6 +797,7 @@ static int parse_opts(char *params, struct p9_fd_opts *opts)
>>
>> static int p9_fd_open(struct p9_client *client, int rfd, int wfd)
>> {
>> + bool perm;
>> struct p9_trans_fd *ts = kzalloc(sizeof(struct p9_trans_fd),
>> GFP_KERNEL);
>> if (!ts)
>> @@ -804,12 +805,16 @@ static int p9_fd_open(struct p9_client *client, int rfd, int wfd)
>>
>> ts->rd = fget(rfd);
>> ts->wr = fget(wfd);
>> - if (!ts->rd || !ts->wr) {
>> + perm = ts->rd && (ts->rd->f_mode & FMODE_READ) &&
>> + ts->wr && (ts->wr->f_mode & FMODE_WRITE);
>> + if (!ts->rd || !ts->wr || !perm) {
>> if (ts->rd)
>> fput(ts->rd);
>> if (ts->wr)
>> fput(ts->wr);
>> kfree(ts);
>> + if (!perm)
>> + return -EBADF;
>> return -EIO;
>> }
>>
>
--
Alexey
next prev parent reply other threads:[~2020-07-28 23:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-28 12:41 [PATCH kernel] 9p/trans_fd: Check file mode at opening Alexey Kardashevskiy
2020-07-28 17:42 ` [V9fs-developer] " Greg Kurz
2020-07-28 23:50 ` Alexey Kardashevskiy [this message]
2020-07-29 6:06 ` Greg Kurz
2020-07-29 6:14 ` Dominique Martinet
2020-07-29 6:38 ` Greg Kurz
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=ceaa4de6-e4df-e6b0-8085-7020240c57b4@ozlabs.ru \
--to=aik@ozlabs.ru \
--cc=asmadeus@codewreck.org \
--cc=davem@davemloft.net \
--cc=ericvh@gmail.com \
--cc=groug@kaod.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lucho@ionkov.net \
--cc=netdev@vger.kernel.org \
--cc=v9fs-developer@lists.sourceforge.net \
/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