From: "Daniel P. Berrangé" <firstname.lastname@example.org> To: Michael Tokarev <email@example.com> Cc: "Peter Maydell" <firstname.lastname@example.org>, qemu-stable <email@example.com>, "QEMU Developers" <firstname.lastname@example.org>, "Marc-André Lureau" <email@example.com> Subject: Re: [PATCH] qemu-sockets: fix unix socket path copy (again) Date: Wed, 1 Sep 2021 12:57:31 +0100 [thread overview] Message-ID: <YS9qq0jnjMkr6firstname.lastname@example.org> (raw) In-Reply-To: <email@example.com> On Wed, Sep 01, 2021 at 11:29:58AM +0300, Michael Tokarev wrote: > On 31.08.2021 22:47, Peter Maydell wrote: > > On Tue, 31 Aug 2021 at 19:34, Michael Tokarev <firstname.lastname@example.org> 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. The salen parameter to 'accept' / 'getsockname' etc is caller supplied and indicates how long the buffer provided is. The kernel updates the value on success, but the updated vaue will never exceed the input value. According to the manpage if salen only allows sizeof(struct sockaddr_un), then the returned data will simply not be NUL-terminated. I'm increasingly inclined to agree with Peter though, we should just not try to do this assert because it isn't adding value. We have a trust relationship with the kernel and so can assume salen values it gives us are correct. We only need to assert if we're validating an assumption that we're making ourselves, that isn't otherwise guaranteed by the kernel API semantics. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
prev parent reply other threads:[~2021-09-01 11:59 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 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é [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=YS9qq0jnjMkr6email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --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.