virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Dan Carpenter <dan.carpenter@oracle.com>,
	"Michael S. Tsirkin" <mst@redhat.com>
Cc: virtualization@lists.linux-foundation.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 2/2] vdpa: Fix pointer math bug in vdpasim_get_config()
Date: Thu, 9 Apr 2020 10:06:35 +0800	[thread overview]
Message-ID: <d463d227-92ff-d35f-6b3c-b86b85613da1@redhat.com> (raw)
In-Reply-To: <20200406144552.GF68494@mwanda>


On 2020/4/6 下午10:45, Dan Carpenter wrote:
> If "offset" is non-zero then we end up copying from beyond the end of
> the config because of pointer math.  We can fix this by casting the
> struct to a u8 pointer.
>
> Fixes: 2c53d0f64c06 ("vdpasim: vDPA device simulator")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> Is it really worth letting people specify the offset?
>
>   drivers/vdpa/vdpa_sim/vdpa_sim.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
> index b3c800653056..e03c25765513 100644
> --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
> +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
> @@ -509,7 +509,7 @@ static void vdpasim_get_config(struct vdpa_device *vdpa, unsigned int offset,
>   	struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
>   
>   	if (offset + len < sizeof(struct virtio_net_config))
> -		memcpy(buf, &vdpasim->config + offset, len);
> +		memcpy(buf, (u8 *)&vdpasim->config + offset, len);
>   }
>   
>   static void vdpasim_set_config(struct vdpa_device *vdpa, unsigned int offset,


Acked-by: Jason Wang <jasowang@redhat.com>

  reply	other threads:[~2020-04-09  2:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-06 14:45 [PATCH 1/2] vdpa: Signedness bugs in vdpasim_work() Dan Carpenter
2020-04-06 14:45 ` [PATCH 2/2] vdpa: Fix pointer math bug in vdpasim_get_config() Dan Carpenter
2020-04-09  2:06   ` Jason Wang [this message]
2020-04-09  2:05 ` [PATCH 1/2] vdpa: Signedness bugs in vdpasim_work() Jason Wang

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=d463d227-92ff-d35f-6b3c-b86b85613da1@redhat.com \
    --to=jasowang@redhat.com \
    --cc=dan.carpenter@oracle.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=virtualization@lists.linux-foundation.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).