From: "Michael S. Tsirkin" <mst@redhat.com>
To: Weimin Xiong <xiongwm2026@163.com>
Cc: qemu-devel@nongnu.org, jasowang@redhat.com,
virtualization@lists.linux.dev,
Xiong Weimin <xiongweimin@kylinos.cn>
Subject: Re: [PATCH] hw/net/virtio-net: Remove dangerous cast in receive_header
Date: Fri, 24 Jul 2026 05:44:32 -0400 [thread overview]
Message-ID: <20260724054210-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20260724093809.810263-1-xiongwm2026@163.com>
On Fri, Jul 24, 2026 at 05:38:09PM +0800, Weimin Xiong wrote:
> From: Xiong Weimin <xiongweimin@kylinos.cn>
>
> The receive_header() function contains a "FIXME this cast is evil"
> comment. The code does:
> void *wbuf = (void *)buf;
>
> This cast from 'const void *' to 'void *' removes const qualifier which
> could lead to unintended modifications.
... and so you cast to uint8_t * instead, removing const qualifier.
> Instead, use a properly typed
> pointer and pass it correctly to work_around_broken_dhclient().
>
> Signed-off-by: Xiong Weimin <xiongweimin@kylinos.cn>
> ---
> hw/net/virtio-net.c | 12 +++++++----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index 1234567890ab..fedcba098765 4321006
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -1716,12 +1716,14 @@ static void receive_header(VirtIONet *n, const struct iovec *iov, int iov_cnt,
> const void *buf, size_t size)
> {
> if (n->has_vnet_hdr) {
> - /* FIXME this cast is evil */
> - void *wbuf = (void *)buf;
> - work_around_broken_dhclient(wbuf, wbuf + n->host_hdr_len,
> - size - n->host_hdr_len);
> + const uint8_t *wbuf = buf;
> + uint8_t *payload = (uint8_t *)(wbuf + n->host_hdr_len);
> +
Forgive me how is this better?
what is properly typed and correctly about casting to uint8_t *?
As far as I can see all you did is remove a comment.
> + work_around_broken_dhclient(wbuf, payload,
> + size - n->host_hdr_len);
>
> if (n->needs_vnet_hdr_swap) {
> - virtio_net_hdr_swap(VIRTIO_DEVICE(n), wbuf);
> + virtio_net_hdr_swap(VIRTIO_DEVICE(n), (void *)wbuf);
> }
> iov_from_buf(iov, iov_cnt, 0, buf, sizeof(struct virtio_net_hdr));
> } else {
prev parent reply other threads:[~2026-07-24 9:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 9:38 [PATCH] hw/net/virtio-net: Remove dangerous cast in receive_header Weimin Xiong
2026-07-24 9:44 ` Michael S. Tsirkin [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=20260724054210-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=jasowang@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=virtualization@lists.linux.dev \
--cc=xiongweimin@kylinos.cn \
--cc=xiongwm2026@163.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