From: Samuel Thibault <samuel.thibault@gnu.org>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
"Marc-André Lureau" <marcandre.lureau@gmail.com>,
jan.kiszka@siemens.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] slirp: Use lduw_be_p in slirp_input
Date: Thu, 17 Jan 2019 14:22:57 +0100 [thread overview]
Message-ID: <20190117132257.uoksqpl6cuu6zilt@function> (raw)
In-Reply-To: <d79f1118-38ed-16fc-0233-0c41570d6d8c@redhat.com>
Philippe Mathieu-Daudé, le jeu. 17 janv. 2019 14:16:16 +0100, a ecrit:
> On 1/17/19 12:50 AM, Samuel Thibault wrote:
> > Hello,
> >
> > Richard Henderson, le mer. 26 déc. 2018 14:42:54 +1100, a ecrit:
> >> The pointer may be unaligned, so we must use our routines for that.
> >> At the same time, we might as well use the big-endian version
> >> instead of ntohs.
> >>
> >> This fixes sparc64 host SIGBUS during pxe boot.
> >
> > I'm not at ease with applying this, when Marc-André is trying to make
> > slirp an external library... I'd rather apply the change below, could
> > somebody review it?
> >
> > Samuel
> >
> >
> > slirp: Avoid unaligned 16bit memory access
> >
> > pkt parameter may be unaligned, so we must access it byte-wise.
> >
> > This fixes sparc64 host SIGBUS during pxe boot.
> >
> > Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
> >
> > diff --git a/slirp/slirp.c b/slirp/slirp.c
> > index ab2fc4eb8b..0e41d5aedf 100644
> > --- a/slirp/slirp.c
> > +++ b/slirp/slirp.c
> > @@ -851,7 +851,7 @@ void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
> > if (pkt_len < ETH_HLEN)
> > return;
> >
> > - proto = ntohs(*(uint16_t *)(pkt + 12));
> > + proto = (((uint16_t) pkt[12]) << 8) + pkt[13];
> > switch(proto) {
> > case ETH_P_ARP:
> > arp_input(slirp, pkt, pkt_len);
>
> What about using memcpy?
Well, it looks to me even more confusing than doing the shifts :)
> -- >8 --
> @@ -846,12 +846,13 @@ static void arp_input(Slirp *slirp, const uint8_t
> *pkt, int pkt_len)
> void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
> {
> struct mbuf *m;
> - int proto;
> + uint16_t proto;
>
> if (pkt_len < ETH_HLEN)
> return;
>
> - proto = ntohs(*(uint16_t *)(pkt + 12));
> + memcpy(&proto, pkt + 12, sizeof(proto)); /* Avoid unaligned 16bit
> access */
> + proto = ntohs(proto);
> switch(proto) {
> case ETH_P_ARP:
> arp_input(slirp, pkt, pkt_len);
> ---
>
next prev parent reply other threads:[~2019-01-17 13:32 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-26 3:42 [Qemu-devel] [PATCH] slirp: Use lduw_be_p in slirp_input Richard Henderson
2018-12-26 10:57 ` Peter Maydell
2018-12-26 11:04 ` Philippe Mathieu-Daudé
2019-01-16 23:50 ` Samuel Thibault
2019-01-17 0:05 ` Richard Henderson
2019-01-17 13:16 ` Philippe Mathieu-Daudé
2019-01-17 13:22 ` Samuel Thibault [this message]
2019-01-17 13:56 ` Peter Maydell
2019-01-18 11:25 ` Marc-André Lureau
2019-01-18 11:37 ` Marc-André Lureau
2019-01-18 11:54 ` Peter Maydell
2019-01-23 11:29 ` no-reply
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=20190117132257.uoksqpl6cuu6zilt@function \
--to=samuel.thibault@gnu.org \
--cc=jan.kiszka@siemens.com \
--cc=marcandre.lureau@gmail.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/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).