Linux IOMMU Development
 help / color / mirror / Atom feed
* [PATCH] iommu/sva: fix signedness bug in iommu_sva_alloc_pasid()
@ 2023-04-06  8:55 Dan Carpenter
  2023-04-06 12:48 ` Baolu Lu
  2023-07-07  7:17 ` Dan Carpenter
  0 siblings, 2 replies; 6+ messages in thread
From: Dan Carpenter @ 2023-04-06  8:55 UTC (permalink / raw)
  To: Jacob Pan
  Cc: Will Deacon, Robin Murphy, Lu Baolu, Kevin Tian, Jason Gunthorpe,
	iommu, kernel-janitors

The ida_alloc_range() function returns negative error codes on error.
On success it returns values in the min to max range (inclusive).  It
never returns more then INT_MAX even if "max" is higher.  It never
returns values in the 0 to (min - 1) range.

The bug is that "min" is an unsigned int so negative error codes will
be promoted to high positive values errors treated as success.

Fixes: 1a14bf0fc7ed ("iommu/sva: Use GFP_KERNEL for pasid allocation")
Signed-off-by: Dan Carpenter <error27@gmail.com>
---
 drivers/iommu/iommu-sva.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
index c4ab3c457fbc..6e4f1ba1c148 100644
--- a/drivers/iommu/iommu-sva.c
+++ b/drivers/iommu/iommu-sva.c
@@ -33,8 +33,9 @@ static int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t ma
 	}
 
 	ret = ida_alloc_range(&iommu_global_pasid_ida, min, max, GFP_KERNEL);
-	if (ret < min)
+	if (ret < 0)
 		goto out;
+
 	mm->pasid = ret;
 	ret = 0;
 out:
-- 
2.39.1


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

* Re: [PATCH] iommu/sva: fix signedness bug in iommu_sva_alloc_pasid()
  2023-04-06  8:55 [PATCH] iommu/sva: fix signedness bug in iommu_sva_alloc_pasid() Dan Carpenter
@ 2023-04-06 12:48 ` Baolu Lu
  2023-07-07  7:17 ` Dan Carpenter
  1 sibling, 0 replies; 6+ messages in thread
From: Baolu Lu @ 2023-04-06 12:48 UTC (permalink / raw)
  To: Dan Carpenter, Jacob Pan
  Cc: baolu.lu, Will Deacon, Robin Murphy, Kevin Tian, Jason Gunthorpe,
	iommu, kernel-janitors

On 2023/4/6 16:55, Dan Carpenter wrote:
> The ida_alloc_range() function returns negative error codes on error.
> On success it returns values in the min to max range (inclusive).  It
> never returns more then INT_MAX even if "max" is higher.  It never
> returns values in the 0 to (min - 1) range.
> 
> The bug is that "min" is an unsigned int so negative error codes will
> be promoted to high positive values errors treated as success.
> 
> Fixes: 1a14bf0fc7ed ("iommu/sva: Use GFP_KERNEL for pasid allocation")
> Signed-off-by: Dan Carpenter<error27@gmail.com>

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>

Best regards,
baolu

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

* Re: [PATCH] iommu/sva: fix signedness bug in iommu_sva_alloc_pasid()
  2023-04-06  8:55 [PATCH] iommu/sva: fix signedness bug in iommu_sva_alloc_pasid() Dan Carpenter
  2023-04-06 12:48 ` Baolu Lu
@ 2023-07-07  7:17 ` Dan Carpenter
  2023-07-10  9:27   ` Will Deacon
  1 sibling, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2023-07-07  7:17 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jacob Pan, Will Deacon, Robin Murphy, Lu Baolu, Kevin Tian,
	Jason Gunthorpe, iommu, kernel-janitors

Ping!

regards,
dan carpenter

On Thu, Apr 06, 2023 at 11:55:31AM +0300, Dan Carpenter wrote:
> The ida_alloc_range() function returns negative error codes on error.
> On success it returns values in the min to max range (inclusive).  It
> never returns more then INT_MAX even if "max" is higher.  It never
> returns values in the 0 to (min - 1) range.
> 
> The bug is that "min" is an unsigned int so negative error codes will
> be promoted to high positive values errors treated as success.
> 
> Fixes: 1a14bf0fc7ed ("iommu/sva: Use GFP_KERNEL for pasid allocation")
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> ---
>  drivers/iommu/iommu-sva.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
> index c4ab3c457fbc..6e4f1ba1c148 100644
> --- a/drivers/iommu/iommu-sva.c
> +++ b/drivers/iommu/iommu-sva.c
> @@ -33,8 +33,9 @@ static int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t ma
>  	}
>  
>  	ret = ida_alloc_range(&iommu_global_pasid_ida, min, max, GFP_KERNEL);
> -	if (ret < min)
> +	if (ret < 0)
>  		goto out;
> +
>  	mm->pasid = ret;
>  	ret = 0;
>  out:
> -- 
> 2.39.1

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

* Re: [PATCH] iommu/sva: fix signedness bug in iommu_sva_alloc_pasid()
  2023-07-07  7:17 ` Dan Carpenter
@ 2023-07-10  9:27   ` Will Deacon
  2023-07-10  9:34     ` Dan Carpenter
  0 siblings, 1 reply; 6+ messages in thread
From: Will Deacon @ 2023-07-10  9:27 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Dan Carpenter, Jacob Pan, Robin Murphy, Lu Baolu, Kevin Tian,
	Jason Gunthorpe, iommu, kernel-janitors, joro

On Fri, Jul 07, 2023 at 10:17:23AM +0300, Dan Carpenter wrote:
> Ping!

Ah, Joerg isn't on CC. Fixing that now...

Will

> On Thu, Apr 06, 2023 at 11:55:31AM +0300, Dan Carpenter wrote:
> > The ida_alloc_range() function returns negative error codes on error.
> > On success it returns values in the min to max range (inclusive).  It
> > never returns more then INT_MAX even if "max" is higher.  It never
> > returns values in the 0 to (min - 1) range.
> > 
> > The bug is that "min" is an unsigned int so negative error codes will
> > be promoted to high positive values errors treated as success.
> > 
> > Fixes: 1a14bf0fc7ed ("iommu/sva: Use GFP_KERNEL for pasid allocation")
> > Signed-off-by: Dan Carpenter <error27@gmail.com>
> > ---
> >  drivers/iommu/iommu-sva.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/iommu/iommu-sva.c b/drivers/iommu/iommu-sva.c
> > index c4ab3c457fbc..6e4f1ba1c148 100644
> > --- a/drivers/iommu/iommu-sva.c
> > +++ b/drivers/iommu/iommu-sva.c
> > @@ -33,8 +33,9 @@ static int iommu_sva_alloc_pasid(struct mm_struct *mm, ioasid_t min, ioasid_t ma
> >  	}
> >  
> >  	ret = ida_alloc_range(&iommu_global_pasid_ida, min, max, GFP_KERNEL);
> > -	if (ret < min)
> > +	if (ret < 0)
> >  		goto out;
> > +
> >  	mm->pasid = ret;
> >  	ret = 0;
> >  out:
> > -- 
> > 2.39.1

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

* Re: [PATCH] iommu/sva: fix signedness bug in iommu_sva_alloc_pasid()
  2023-07-10  9:27   ` Will Deacon
@ 2023-07-10  9:34     ` Dan Carpenter
  2023-07-14 12:53       ` Joerg Roedel
  0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2023-07-10  9:34 UTC (permalink / raw)
  To: Will Deacon, joro
  Cc: Dan Carpenter, Jacob Pan, Robin Murphy, Lu Baolu, Kevin Tian,
	Jason Gunthorpe, iommu, kernel-janitors, joro

On Mon, Jul 10, 2023 at 10:27:14AM +0100, Will Deacon wrote:
> On Fri, Jul 07, 2023 at 10:17:23AM +0300, Dan Carpenter wrote:
> > Ping!
> 
> Ah, Joerg isn't on CC. Fixing that now...
> 

Sorry!  I use a script to send patches and for a while if the patch had
a Fixes tag then my script would remove the top name listed from
get_maintainer.pl.  Doh!

I should probably resend this?

regards,
dan carpenter


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

* Re: [PATCH] iommu/sva: fix signedness bug in iommu_sva_alloc_pasid()
  2023-07-10  9:34     ` Dan Carpenter
@ 2023-07-14 12:53       ` Joerg Roedel
  0 siblings, 0 replies; 6+ messages in thread
From: Joerg Roedel @ 2023-07-14 12:53 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Will Deacon, Dan Carpenter, Jacob Pan, Robin Murphy, Lu Baolu,
	Kevin Tian, Jason Gunthorpe, iommu, kernel-janitors

On Mon, Jul 10, 2023 at 12:34:19PM +0300, Dan Carpenter wrote:
> I should probably resend this?

No, just applied it, thanks.

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

end of thread, other threads:[~2023-07-14 12:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-06  8:55 [PATCH] iommu/sva: fix signedness bug in iommu_sva_alloc_pasid() Dan Carpenter
2023-04-06 12:48 ` Baolu Lu
2023-07-07  7:17 ` Dan Carpenter
2023-07-10  9:27   ` Will Deacon
2023-07-10  9:34     ` Dan Carpenter
2023-07-14 12:53       ` Joerg Roedel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox