All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Daniel P . Berrangé" <berrange@redhat.com>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	qemu-stable <qemu-stable@nongnu.org>
Subject: Re: [PATCH] qemu-sockets: fix unix socket path copy (again)
Date: Wed, 1 Sep 2021 11:29:58 +0300	[thread overview]
Message-ID: <9785281e-85cb-a993-d35a-94ef11df9b67@msgid.tls.msk.ru> (raw)
In-Reply-To: <CAFEAcA9xc_q1fDT1F8uEW=dEQXmRWX8nusPmtmFLASg1EwU8gw@mail.gmail.com>

On 31.08.2021 22:47, Peter Maydell wrote:
> On Tue, 31 Aug 2021 at 19:34, Michael Tokarev <mjt@tls.msk.ru> wrote:
..
>> -    assert(salen >= sizeof(su->sun_family) + 1 &&
>> -           salen <= sizeof(struct sockaddr_un));
>> +    /* there's a corner case when trailing \0 does not fit into
>> +     * sockaddr_un. Compare length with sizeof(sockaddr_storage),
>> +     * not with sizeof(sockaddr_un), since this is what we actually
>> +     * provide, to ensure we had no truncation and a room for
>> +     * the trailing \0 which we add below.
>> +     * When salen == sizeof(sun_family) it is unnamed socket,
>> +     * and when first byte of sun_path is \0, it is abstract. */
>> +    assert(salen >= sizeof(su->sun_family) &&
>> +           salen <= sizeof(struct sockaddr_storage));
> 
> Again, why are we asserting an upper bound? We don't care here:
> the representation in the SocketAddress structure has no length
> limit on the path. (Conversely, we do care about the max length
> when we convert from a SocketAddress to a sockaddr_un: we do this
> in eg unix_connect_saddr().)

We have sizeof(sockaddr_storage) space there. If the kernel returned
salen greather than that, this means we received only partial address
and can't rely on it. It is like snprintf() returning more bytes than
available in the buffer - it says how much bytes NEEDED.

/mjt


  reply	other threads:[~2021-09-01  8:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-31 18:26 Michael Tokarev
2021-08-31 19:21 ` Marc-André Lureau
2021-08-31 19:26   ` Michael Tokarev
2021-09-01  9:12   ` Daniel P. Berrangé
2021-09-01  9:20     ` Michael Tokarev
2021-08-31 19:47 ` Peter Maydell
2021-09-01  8:29   ` Michael Tokarev [this message]
2021-09-01  9:52     ` Peter Maydell
2021-09-01 11:45       ` Michael Tokarev
2021-09-01 11:58         ` Daniel P. Berrangé
2021-09-01 11:57     ` Daniel P. Berrangé

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=9785281e-85cb-a993-d35a-94ef11df9b67@msgid.tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=berrange@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    --subject='Re: [PATCH] qemu-sockets: fix unix socket path copy (again)' \
    /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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.