lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <094e77fd96696ada25eb1a620b46ef21c0cf6cc0.camel@linux.ibm.com>
Date:   Fri, 30 Sep 2022 10:01:19 +0200
From:   Niklas Schnelle <schnelle@...ux.ibm.com>
To:     Jason Gunthorpe <jgg@...dia.com>
Cc:     Matthew Rosato <mjrosato@...ux.ibm.com>,
        Pierre Morel <pmorel@...ux.ibm.com>, iommu@...ts.linux.dev,
        linux-s390@...r.kernel.org, borntraeger@...ux.ibm.com,
        hca@...ux.ibm.com, gor@...ux.ibm.com,
        gerald.schaefer@...ux.ibm.com, agordeev@...ux.ibm.com,
        svens@...ux.ibm.com, joro@...tes.org, will@...nel.org,
        robin.murphy@....com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3 4/5] iommu/s390: Fix incorrect aperture check

On Thu, 2022-09-29 at 12:58 -0300, Jason Gunthorpe wrote:
> On Thu, Sep 29, 2022 at 05:33:01PM +0200, Niklas Schnelle wrote:
> > The domain->geometry.aperture_end specifies the last valid address treat
> > it as such when checking if a DMA address is valid.
> > 
> > Reviewed-by: Pierre Morel <pmorel@...ux.ibm.com>
> > Reviewed-by: Matthew Rosato <mjrosato@...ux.ibm.com>
> > Signed-off-by: Niklas Schnelle <schnelle@...ux.ibm.com>
> > ---
> >  drivers/iommu/s390-iommu.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/iommu/s390-iommu.c b/drivers/iommu/s390-iommu.c
> > index ed0e64f478cf..6d4a9c7db32c 100644
> > --- a/drivers/iommu/s390-iommu.c
> > +++ b/drivers/iommu/s390-iommu.c
> > @@ -210,7 +210,7 @@ static int s390_iommu_update_trans(struct s390_domain *s390_domain,
> >  	int rc = 0;
> >  
> >  	if (dma_addr < s390_domain->domain.geometry.aperture_start ||
> > -	    dma_addr + size > s390_domain->domain.geometry.aperture_end)
> > +	    dma_addr + size > s390_domain->domain.geometry.aperture_end + 1)
> 
> The reason the iommu layer uses 'last' (= start + size - 1) not 'end'
> is to allow for the very last byte of the range to be used.
> 
> Meaning (start + size) == 0 in some cases due to the overflow.
> 
> Generally when working with lasts's I prefer people write code in a
> way that doesn't trigger the overflow, because there are some
> complicated C rules about integer promotion that can mean the desired
> overflow silently doesn't happen in obscure cases - especially if
> unsigned long != u64
> 
> So, I'd write this as:
> 
>   (dma_addr + size - 1) > s390_domain->domain.geometry.aperture_end
> 
> Jason

Makes sense. Thanks.


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ