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] [thread-next>] [day] [month] [year] [list]
Message-Id: <2EC080E4-B31C-46F5-8239-FF96493DA861@goldelico.com>
Date:	Thu, 15 Oct 2015 18:52:29 +0200
From:	"H. Nikolaus Schaller" <hns@...delico.com>
To:	Russell King - ARM Linux <linux@....linux.org.uk>
Cc:	Nathan Lynch <nathan_lynch@...tor.com>,
	Szabolcs Nagy <szabolcs.nagy@....com>,
	Will Deacon <will.deacon@....com>,
	linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
	marek@...delico.com
Subject: Re: [PATCH v2] ARM: fix vdsomunge not to depend on glibc specific byteswap.h


Am 15.10.2015 um 18:37 schrieb Russell King - ARM Linux <linux@....linux.org.uk>:

> On Thu, Oct 15, 2015 at 07:52:38AM +0200, H. Nikolaus Schaller wrote:
>> ERROR: space prohibited before that close parenthesis ')'
>> #46: FILE: arch/arm/vdso/vdsomunge.c:64:
>> +		(((unsigned short)(x) & (unsigned short)0xff00U) >> 8) ))
> 
> I have a pet hatred of too many parens.  I also have a hatred of idiotic
> casts.  What about changing the above to one of:
> 
> 		(((x) & 0xff00) >> 8)
> 		(((x) >> 8) & 0xff)
> 
>> 
>> ERROR: space prohibited before that close parenthesis ')'
>> #53: FILE: arch/arm/vdso/vdsomunge.c:71:
>> +		(((unsigned int)(x) & (unsigned int)0xff000000UL) >> 24) ))
> 
> and one of:
> 
> 		(((x) & 0xff000000) >> 24)
> 		(((x) >> 24) & 0xff)
> 
> ?

Well, the semantics is sometimes the same but I think readability goes down
because the macro becomes quite un-symmetric and for >> 8 you should
better be sure that values are unsigned if combining with | operator.

Of course it is questionable why the constants (with U and UL modifiers)
are casted.

The full macro (as copied verbatim from existing arch/mips/boot/elf2ecoff.c) is:

+#define swab16(x) \
+	((unsigned short)( \
+		(((unsigned short)(x) & (unsigned short)0x00ffU) << 8) | \
+		(((unsigned short)(x) & (unsigned short)0xff00U) >> 8)))
+
+#define swab32(x) \
+	((unsigned int)( \
+		(((unsigned int)(x) & (unsigned int)0x000000ffUL) << 24) | \
+		(((unsigned int)(x) & (unsigned int)0x0000ff00UL) <<  8) | \
+		(((unsigned int)(x) & (unsigned int)0x00ff0000UL) >>  8) | \
+		(((unsigned int)(x) & (unsigned int)0xff000000UL) >> 24)))
+

I have already submitted a V3 of this patch, so please comment that.

A question is why this is not generally available for all HOSTCC based tools
so that we could simply include some header. But since that is no kernel
code but a tool, I think it is not really necessary to put significant efforts
into this piece of code.

This was probably the intention of the original code to simply include
byteswap.h - then you don't even see how complex the macros are -
but it is not a standard header.

BR and thanks,
Nikolaus Schaller--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ