virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vduse: Fix off by one in vduse_dev_mmap()
@ 2024-02-27 15:21 Dan Carpenter
  2024-02-27 15:48 ` Michael S. Tsirkin
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2024-02-27 15:21 UTC (permalink / raw)
  To: Cindy Lu
  Cc: Michael S. Tsirkin, Jason Wang, Xuan Zhuo, Xie Yongji,
	Maxime Coquelin, Christian Brauner, Greg Kroah-Hartman,
	virtualization, linux-kernel, kernel-janitors

The dev->vqs[] array has "dev->vq_num" elements.  It's allocated in
vduse_dev_init_vqs().  Thus, this > comparison needs to be >= to avoid
reading one element beyond the end of the array.

Fixes: 316ecd1346b0 ("vduse: Add file operation for mmap")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/vdpa/vdpa_user/vduse_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index b7a1fb88c506..9150c8281953 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -1532,7 +1532,7 @@ static int vduse_dev_mmap(struct file *file, struct vm_area_struct *vma)
 	if ((vma->vm_flags & VM_SHARED) == 0)
 		return -EINVAL;
 
-	if (index > dev->vq_num)
+	if (index >= dev->vq_num)
 		return -EINVAL;
 
 	vq = dev->vqs[index];
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] vduse: Fix off by one in vduse_dev_mmap()
  2024-02-27 15:21 [PATCH] vduse: Fix off by one in vduse_dev_mmap() Dan Carpenter
@ 2024-02-27 15:48 ` Michael S. Tsirkin
  2024-02-28 17:42   ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Michael S. Tsirkin @ 2024-02-27 15:48 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Cindy Lu, Jason Wang, Xuan Zhuo, Xie Yongji, Maxime Coquelin,
	Christian Brauner, Greg Kroah-Hartman, virtualization,
	linux-kernel, kernel-janitors

On Tue, Feb 27, 2024 at 06:21:46PM +0300, Dan Carpenter wrote:
> The dev->vqs[] array has "dev->vq_num" elements.  It's allocated in
> vduse_dev_init_vqs().  Thus, this > comparison needs to be >= to avoid
> reading one element beyond the end of the array.
> 
> Fixes: 316ecd1346b0 ("vduse: Add file operation for mmap")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>


Oh wow and does this not come from userspace? If yes we
need the speculation magic macro when using the index, do we not?

> ---
>  drivers/vdpa/vdpa_user/vduse_dev.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
> index b7a1fb88c506..9150c8281953 100644
> --- a/drivers/vdpa/vdpa_user/vduse_dev.c
> +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
> @@ -1532,7 +1532,7 @@ static int vduse_dev_mmap(struct file *file, struct vm_area_struct *vma)
>  	if ((vma->vm_flags & VM_SHARED) == 0)
>  		return -EINVAL;
>  
> -	if (index > dev->vq_num)
> +	if (index >= dev->vq_num)
>  		return -EINVAL;
>  
>  	vq = dev->vqs[index];
> -- 
> 2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] vduse: Fix off by one in vduse_dev_mmap()
  2024-02-27 15:48 ` Michael S. Tsirkin
@ 2024-02-28 17:42   ` Dan Carpenter
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2024-02-28 17:42 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Cindy Lu, Jason Wang, Xuan Zhuo, Xie Yongji, Maxime Coquelin,
	Christian Brauner, Greg Kroah-Hartman, virtualization,
	linux-kernel, kernel-janitors

On Tue, Feb 27, 2024 at 10:48:49AM -0500, Michael S. Tsirkin wrote:
> On Tue, Feb 27, 2024 at 06:21:46PM +0300, Dan Carpenter wrote:
> > The dev->vqs[] array has "dev->vq_num" elements.  It's allocated in
> > vduse_dev_init_vqs().  Thus, this > comparison needs to be >= to avoid
> > reading one element beyond the end of the array.
> > 
> > Fixes: 316ecd1346b0 ("vduse: Add file operation for mmap")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> 
> 
> Oh wow and does this not come from userspace? If yes we
> need the speculation magic macro when using the index, do we not?
> 

Yes, it does come from userspace.

To be honest, I'm not sure about speculation.  The similar places in
this file protect against speculation so, probably?  I'll resend the
patch.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-28 17:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-27 15:21 [PATCH] vduse: Fix off by one in vduse_dev_mmap() Dan Carpenter
2024-02-27 15:48 ` Michael S. Tsirkin
2024-02-28 17:42   ` Dan Carpenter

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).