qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Christian Schoenebeck <qemu_oss@crudebyte.com>
To: qemu-devel@nongnu.org
Cc: Greg Kurz <groug@kaod.org>,
	Christian Schoenebeck <qemu_oss@crudebyte.com>,
	anthony.perard@citrix.com,
	Stefano Stabellini <sstabellini@kernel.org>,
	Stefano Stabellini <stefano.stabellini@xilinx.com>
Subject: Re: [PATCH v2 2/9] 9pfs: validate count sent by client with T_readdir
Date: Fri, 10 Jan 2020 13:03:55 +0100	[thread overview]
Message-ID: <1919937.aoWvVaMKoZ@silver> (raw)
In-Reply-To: <20200109005335.4b6214a5@bahia.lan>

On Donnerstag, 9. Januar 2020 00:53:35 CET Greg Kurz wrote:
> > My idea was to "handle it as an error" immediately when server receives a
> > T_version request with a "msize" argument transmitted by client that would
> > be way too small for anything.
> > 
> > Because if client sends T_version with msize < P9_IOHDRSZ then it is
> > obvious that this msize would be way too small for handling any
> > subsequent 9p request at all.
> 
> P9_IOHDRSZ is 24 bytes, it is definitely not enough to accommodate an
> R_getattr message (153 bytes and heavily used by the linux client) for
> example, so we would likely need a higher minimum as you're suggesting
> later in this mail.
[snip]
> > 1. What is the minimum msize to be allowed with T_version?
> > 
> >    P9_IOHDRSZ would be IMO too small, because P9_IOHDRSZ is the size of
> >    the
> >    common header portion of all IO requests. So it would rather make sense
> >    IMO
> >    reviewing the protocol and pick the largest header size among all
> >    possible
> 
> Not the largest header size, rather the size of the largest message,
> otherwise we may still disconnect. Some response messages contain a
> variable size string that the 9p spec forbids to truncate. In the case
> of R_readlink for example, this could go up to the largest target size
> supported by the host filesystem for symbolic links... ie. likely PATH_MAX.

Good point.

> >    requests supported by 9pfs server ATM. The advantage of this approach
> >    would
> >    be that overall code would be easier too maintain, since we don't have
> >    to
> >    add minimum msize checks in any (or even all) individual request type
> >    handlers. T_version handler of server would already enforce a minimum
> >    msize
> >    and prevent the session if msize too small, and that's it.
> 
> Makes sense. Since the linux client already requires msize to be at
> least 4096, this could be a reasonable choice: it doesn't break any
> existing setups and it allows fairly large strings in messages.

4096 as min. msize is fine with me.

In practice people should use a *much* higher msize for performance reasons 
anyway. And I planned to make this circumstance more clear in the docs.

> > 2. How to handle that error with T_version exactly?
> > 
> >    As far as I can see it, it was originally not considered that T_version
> >    might react with an error response at all. The specs are ambiguous
> >    about
> >    this topic. All you can find is that if the transmitted protocol
> >    version
> >    is not supported by server, then server should respond with "unknown"
> >    with
> >    its R_version response, but should not respond with R_error in that
> >    case.
> >    
> >    The specs do not prohibit R_error for T_version in general, but I could
> >    imagine that some clients might not expect if we would send R_error. On
> >    the
> >    other hand responding with R_version "unknown" would not be appropriate
> >    for
> >    this msize error either, because that would mean to the client that the
> >    protocol version was not supported, which is not the case. So it would
> >    leave client uninformed about the actual reason/cause of the error.
> 
> Other 9p implementations have minimal msize checks and return an error
> message. We could go that way too. The only fishy thing I see, and that
> the other implementations seem to ignore, is that the error message format
> depends on the protocol version. It is R_error for older 9p2000 and
> 9p2000.u, while 9p2000.L uses R_lerror.

Ok, noted.

> If the client doesn't understand
> any of these protocols, which is very unlikely, it seems reasonable to
> interrupt the server.

No need. If it is neither 9P2000.u nor 9P2000.L then the appropriate reply of 
server was and still is:

R_version "unknown"

Since the unsupported protocol version still weights higher than the 
unsupported msize. If you are very, very picky, you might want to distinguish 
in this particular case from the case where msize is even too small for 
R_version "unknown", but personally I don't care since the latter would be an 
extreme exotic and broken client.

Best regards,
Christian Schoenebeck




  reply	other threads:[~2020-01-10 12:04 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-18 14:17 [PATCH v2 0/9] 9pfs: readdir optimization Christian Schoenebeck
2019-12-18 13:06 ` [PATCH v2 1/9] tests/virtio-9p: add terminating null in v9fs_string_read() Christian Schoenebeck
2020-01-06 11:00   ` Greg Kurz
2019-12-18 13:17 ` [PATCH v2 2/9] 9pfs: validate count sent by client with T_readdir Christian Schoenebeck
2020-01-06 12:30   ` Greg Kurz
2020-01-06 15:10     ` Christian Schoenebeck
2020-01-06 17:49       ` Greg Kurz
2020-01-06 21:43         ` Christian Schoenebeck
2020-01-08 23:53       ` Greg Kurz
2020-01-10 12:03         ` Christian Schoenebeck [this message]
2019-12-18 13:23 ` [PATCH v2 3/9] hw/9pfs/9p-synth: added directory for readdir test Christian Schoenebeck
2020-01-09 18:49   ` Greg Kurz
2019-12-18 13:30 ` [PATCH v2 4/9] tests/virtio-9p: added " Christian Schoenebeck
2020-01-06 17:22   ` Greg Kurz
2020-01-07 12:25     ` Christian Schoenebeck
2020-01-07 15:27       ` Greg Kurz
2020-01-08 23:55   ` Greg Kurz
2020-01-10 12:10     ` Christian Schoenebeck
2019-12-18 13:35 ` [PATCH v2 5/9] tests/virtio-9p: check file names of R_readdir response Christian Schoenebeck
2020-01-06 17:07   ` Greg Kurz
2020-01-07 12:28     ` Christian Schoenebeck
2020-01-07 15:29       ` Greg Kurz
2019-12-18 13:43 ` [PATCH v2 6/9] 9pfs: readdir benchmark Christian Schoenebeck
2019-12-18 13:52 ` [PATCH v2 7/9] hw/9pfs/9p-synth: avoid n-square issue in synth_readdir() Christian Schoenebeck
2019-12-18 14:00 ` [PATCH v2 8/9] 9pfs: T_readdir latency optimization Christian Schoenebeck
2019-12-18 14:10 ` [PATCH v2 9/9] hw/9pfs/9p.c: benchmark time on T_readdir request Christian Schoenebeck

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=1919937.aoWvVaMKoZ@silver \
    --to=qemu_oss@crudebyte.com \
    --cc=anthony.perard@citrix.com \
    --cc=groug@kaod.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sstabellini@kernel.org \
    --cc=stefano.stabellini@xilinx.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).