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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YmwIHRhS2f1QTW3b@yury-laptop>
Date:   Fri, 29 Apr 2022 08:45:33 -0700
From:   Yury Norov <yury.norov@...il.com>
To:     Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc:     linux-kernel@...r.kernel.org,
        Alexander Gordeev <agordeev@...ux.ibm.com>,
        Christian Borntraeger <borntraeger@...ux.ibm.com>,
        Claudio Imbrenda <imbrenda@...ux.ibm.com>,
        David Hildenbrand <david@...hat.com>,
        Heiko Carstens <hca@...ux.ibm.com>,
        Janosch Frank <frankja@...ux.ibm.com>,
        Rasmus Villemoes <linux@...musvillemoes.dk>,
        Sven Schnelle <svens@...ux.ibm.com>,
        Vasily Gorbik <gor@...ux.ibm.com>, linux-s390@...r.kernel.org,
        kvm@...r.kernel.org
Subject: Re: [PATCH 2/5] lib: add bitmap_{from,to}_arr64

On Fri, Apr 29, 2022 at 03:59:25PM +0300, Andy Shevchenko wrote:
> On Thu, Apr 28, 2022 at 01:51:13PM -0700, Yury Norov wrote:
> > Manipulating 64-bit arrays with bitmap functions is potentially dangerous
> > because on 32-bit BE machines the order of halfwords doesn't match.
> > Another issue is that compiler may throw a warning about out-of-boundary
> > access.
> > 
> > This patch adds bitmap_{from,to}_arr64 functions in addition to existing
> > bitmap_{from,to}_arr32.
> 
> ...
> 
> > +	bitmap_copy_clear_tail((unsigned long *) (bitmap),	\
> > +			(const unsigned long *) (buf), (nbits))
> 
> Drop spaces after castings. Besides that it might be placed on a single line.
> 
> ...

OK
 
> 
> > +	bitmap_copy_clear_tail((unsigned long *) (buf),		\
> > +			(const unsigned long *) (bitmap), (nbits))
> 
> Ditto.
> 
> ...
> 
> > +void bitmap_to_arr64(u64 *buf, const unsigned long *bitmap, unsigned int nbits)
> > +{
> > +	const unsigned long *end = bitmap + BITS_TO_LONGS(nbits);
> > +
> > +	while (bitmap < end) {
> > +		*buf = *bitmap++;
> > +		if (bitmap < end)
> > +			*buf |= (u64)(*bitmap++) << 32;
> > +		buf++;
> > +	}
> >  
> > +	/* Clear tail bits in last element of array beyond nbits. */
> > +	if (nbits % 64)
> > +		buf[-1] &= GENMASK_ULL(nbits, 0);
> 
> Hmm... if nbits is > 0 and < 64, wouldn't be this problematic, since
> end == bitmap? Or did I miss something?

BITS_TO_LONGS(0) == 0
BITS_TO_LONGS(1..32) == 1
BITS_TO_LONGS(33..64) == 2

The only potential problem with buf[-1] is nbits == 0, but fortunately
(0 % 64) == 0, and it doesn't happen.

Thanks,
Yury

> > +}
> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ