Linux cryptographic layer development
 help / color / mirror / Atom feed
* [RFC] [PATCH]  Fix for a warning - crypto/fcrypt,c
@ 2013-08-15 12:01 Jan-Simon Möller
  2013-08-21 10:47 ` Herbert Xu
  2013-08-21 20:42 ` Jan-Simon Möller
  0 siblings, 2 replies; 5+ messages in thread
From: Jan-Simon Möller @ 2013-08-15 12:01 UTC (permalink / raw)
  To: dl9pf, Herbert Xu, David S. Miller, linux-crypto, behanw,
	pageexec

[-- Attachment #1: Type: text/plain, Size: 1668 bytes --]

Hi all,

please merge the attached patch. 

Fix for warning:
linux/crypto/fcrypt.c:143:47: warning: signed shift result (0x598000000) 
requires 36 bits to
      represent, but 'int' only has 32 bits [-Wshift-overflow]
        Z(0xef), Z(0x70), Z(0xcf), Z(0xc2), Z(0x2a), Z(0xb3), Z(0x61), 
Z(0xad),
                                                     ^~~~~~~
linux/crypto/fcrypt.c:113:29: note: expanded from macro 'Z'
#define Z(x) cpu_to_be32((x << 27 ) | (x >> 5))
                            ^  ~~
linux/include/uapi/linux/byteorder/little_endian.h:38:53: note: expanded from 
macro
      '__cpu_to_be32'
#define __cpu_to_be32(x) ((__force __be32)__swab32((x)))
                                                    ^
linux/include/uapi/linux/swab.h:116:21: note: expanded from macro '__swab32'
        ___constant_swab32(x) :                 \
                           ^
linux/include/uapi/linux/swab.h:18:12: note: expanded from macro 
'___constant_swab32'
        (((__u32)(x) & (__u32)0x0000ff00UL) <<  8) |            \
                  ^

Solution - make sure we don't exceed the 32 bit range by adding (x & ~(1U << 
27))  
=  & (0xF7FFFFFF)_16 or & (1111 0111 1111 1111 1111 1111 1111 1111)_2


Author:  PaX Team <pageexec at freemail.hu>                                                                                                                                 
ML-Post: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120507/142707.html
URL:     http://llvm.linuxfoundation.org

Merge:   Jan-Simon Möller <dl9pf at gmx.de>



Best,
-- 

Dipl.-Ing.
Jan-Simon Möller

jansimon.moeller@gmx.de

[-- Attachment #2: 0044-Fix-bitoperation-for-compilation-with-clang.patch --]
[-- Type: text/x-patch, Size: 2424 bytes --]

>From 7b1f235999aa1f1c45602826696e613b1eab315b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan-Simon=20M=C3=B6ller?= <dl9pf@gmx.de>
Date: Wed, 14 Nov 2012 13:09:07 +0100
Subject: [PATCH 44/51] Fix bitoperation for compilation with clang
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Author:  PaX Team <pageexec at freemail.hu>
ML-Post: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120507/142707.html
URL:     http://llvm.linuxfoundation.org

Merge:   Jan-Simon Möller <dl9pf at gmx.de>

Description:

Fix for warning:
linux/crypto/fcrypt.c:143:47: warning: signed shift result (0x598000000) requires 36 bits to
      represent, but 'int' only has 32 bits [-Wshift-overflow]
        Z(0xef), Z(0x70), Z(0xcf), Z(0xc2), Z(0x2a), Z(0xb3), Z(0x61), Z(0xad),
                                                     ^~~~~~~
linux/crypto/fcrypt.c:113:29: note: expanded from macro 'Z'
#define Z(x) cpu_to_be32((x << 27 ) | (x >> 5))
                            ^  ~~
linux/include/uapi/linux/byteorder/little_endian.h:38:53: note: expanded from macro
      '__cpu_to_be32'
#define __cpu_to_be32(x) ((__force __be32)__swab32((x)))
                                                    ^
linux/include/uapi/linux/swab.h:116:21: note: expanded from macro '__swab32'
        ___constant_swab32(x) :                 \
                           ^
linux/include/uapi/linux/swab.h:18:12: note: expanded from macro '___constant_swab32'
        (((__u32)(x) & (__u32)0x0000ff00UL) <<  8) |            \
                  ^

Solution - make sure we don't exceed the 32 bit range by adding (x & ~(1U << 27))  
=  & (0xF7FFFFFF)_16 or & (1111 0111 1111 1111 1111 1111 1111 1111)_2

Signed-off-by: Jan-Simon Möller <dl9pf@gmx.de>
---
 crypto/fcrypt.c |    2 +-
 1 Datei geändert, 1 Zeile hinzugefügt(+), 1 Zeile entfernt(-)

diff --git a/crypto/fcrypt.c b/crypto/fcrypt.c
index 3b2cf56..8ad29b7 100644
--- a/crypto/fcrypt.c
+++ b/crypto/fcrypt.c
@@ -110,7 +110,7 @@ static const __be32 sbox0[256] = {
 };
 
 #undef Z
-#define Z(x) cpu_to_be32((x << 27) | (x >> 5))
+#define Z(x) cpu_to_be32(((x & ~(1U << 27)) << 27) | (x >> 5))
 static const __be32 sbox1[256] = {
 	Z(0x77), Z(0x14), Z(0xa6), Z(0xfe), Z(0xb2), Z(0x5e), Z(0x8c), Z(0x3e),
 	Z(0x67), Z(0x6c), Z(0xa1), Z(0x0d), Z(0xc2), Z(0xa2), Z(0xc1), Z(0x85),
-- 
1.7.10.4


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

* Re: [RFC] [PATCH]  Fix for a warning - crypto/fcrypt,c
  2013-08-15 12:01 [RFC] [PATCH] Fix for a warning - crypto/fcrypt,c Jan-Simon Möller
@ 2013-08-21 10:47 ` Herbert Xu
  2013-08-21 15:39   ` PaX Team
  2013-08-21 20:42 ` Jan-Simon Möller
  1 sibling, 1 reply; 5+ messages in thread
From: Herbert Xu @ 2013-08-21 10:47 UTC (permalink / raw)
  To: Jan-Simon Möller; +Cc: David S. Miller, linux-crypto, behanw, pageexec

On Thu, Aug 15, 2013 at 02:01:50PM +0200, Jan-Simon Möller wrote:
> Hi all,
> 
> please merge the attached patch. 
> 
> Fix for warning:
> linux/crypto/fcrypt.c:143:47: warning: signed shift result (0x598000000) 
> requires 36 bits to
>       represent, but 'int' only has 32 bits [-Wshift-overflow]
>         Z(0xef), Z(0x70), Z(0xcf), Z(0xc2), Z(0x2a), Z(0xb3), Z(0x61), 
> Z(0xad),
>                                                      ^~~~~~~
> linux/crypto/fcrypt.c:113:29: note: expanded from macro 'Z'
> #define Z(x) cpu_to_be32((x << 27 ) | (x >> 5))
>                             ^  ~~
> linux/include/uapi/linux/byteorder/little_endian.h:38:53: note: expanded from 
> macro
>       '__cpu_to_be32'
> #define __cpu_to_be32(x) ((__force __be32)__swab32((x)))
>                                                     ^
> linux/include/uapi/linux/swab.h:116:21: note: expanded from macro '__swab32'
>         ___constant_swab32(x) :                 \
>                            ^
> linux/include/uapi/linux/swab.h:18:12: note: expanded from macro 
> '___constant_swab32'
>         (((__u32)(x) & (__u32)0x0000ff00UL) <<  8) |            \
>                   ^
> 
> Solution - make sure we don't exceed the 32 bit range by adding (x & ~(1U << 
> 27))  
> =  & (0xF7FFFFFF)_16 or & (1111 0111 1111 1111 1111 1111 1111 1111)_2

Your fix makes no sense.  To achieve what you want you'd need to lop
off the first 5 bits, not the fifth bit.

However, which compiler is this? This warning seems to be rather
pointless.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [RFC] [PATCH]  Fix for a warning - crypto/fcrypt,c
  2013-08-21 10:47 ` Herbert Xu
@ 2013-08-21 15:39   ` PaX Team
  0 siblings, 0 replies; 5+ messages in thread
From: PaX Team @ 2013-08-21 15:39 UTC (permalink / raw)
  To: Jan-Simon Möller, Herbert Xu; +Cc: David S. Miller, linux-crypto, behanw

On 21 Aug 2013 at 20:47, Herbert Xu wrote:

> On Thu, Aug 15, 2013 at 02:01:50PM +0200, Jan-Simon Möller wrote:
> > Solution - make sure we don't exceed the 32 bit range by adding (x & ~(1U << 
> > 27))  
> > =  & (0xF7FFFFFF)_16 or & (1111 0111 1111 1111 1111 1111 1111 1111)_2
> 
> Your fix makes no sense.  To achieve what you want you'd need to lop
> off the first 5 bits, not the fifth bit.

oops, the bitmask expression wanted to be (1U << 27) - 1) instead.
another approach would be to simply cast the macro argument to __be32.

> However, which compiler is this? This warning seems to be rather
> pointless.

it's clang and this warning is about an undefined behaviour because
the hexadecimal constants passed to this macro are treated as signed
ints and for some of the constants the result of the shift cannot be
represented as a signed int.

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

* Re: [RFC] [PATCH]  Fix for a warning - crypto/fcrypt,c
  2013-08-15 12:01 [RFC] [PATCH] Fix for a warning - crypto/fcrypt,c Jan-Simon Möller
  2013-08-21 10:47 ` Herbert Xu
@ 2013-08-21 20:42 ` Jan-Simon Möller
  2013-08-26  6:04   ` Herbert Xu
  1 sibling, 1 reply; 5+ messages in thread
From: Jan-Simon Möller @ 2013-08-21 20:42 UTC (permalink / raw)
  To: Herbert Xu, linux-crypto; +Cc: behanw, pageexec


Should I resend a fixed version with 
(1U << 27) - 1) instead ?

Best,
JS

On Thursday 15 August 2013 14:01:50 Jan-Simon Möller wrote:
> Hi all,
> 
> please merge the attached patch.
> 
> Fix for warning:
> linux/crypto/fcrypt.c:143:47: warning: signed shift result (0x598000000)
> requires 36 bits to
>       represent, but 'int' only has 32 bits [-Wshift-overflow]
>         Z(0xef), Z(0x70), Z(0xcf), Z(0xc2), Z(0x2a), Z(0xb3), Z(0x61),
> Z(0xad),
>                                                      ^~~~~~~
> linux/crypto/fcrypt.c:113:29: note: expanded from macro 'Z'
> #define Z(x) cpu_to_be32((x << 27 ) | (x >> 5))
>                             ^  ~~
> linux/include/uapi/linux/byteorder/little_endian.h:38:53: note: expanded
> from macro
>       '__cpu_to_be32'
> #define __cpu_to_be32(x) ((__force __be32)__swab32((x)))
>                                                     ^
> linux/include/uapi/linux/swab.h:116:21: note: expanded from macro '__swab32'
> ___constant_swab32(x) :                 \
>                            ^
> linux/include/uapi/linux/swab.h:18:12: note: expanded from macro
> '___constant_swab32'
>         (((__u32)(x) & (__u32)0x0000ff00UL) <<  8) |            \
>                   ^
> 
> Solution - make sure we don't exceed the 32 bit range by adding (x & ~(1U <<
> 27))
> =  & (0xF7FFFFFF)_16 or & (1111 0111 1111 1111 1111 1111 1111 1111)_2
> 
> 
> Author:  PaX Team <pageexec at freemail.hu>
> ML-Post:
> http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120507/142707
> .html URL:     http://llvm.linuxfoundation.org
> 
> Merge:   Jan-Simon Möller <dl9pf at gmx.de>
> 
> 
> 
> Best,

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

* Re: [RFC] [PATCH]  Fix for a warning - crypto/fcrypt,c
  2013-08-21 20:42 ` Jan-Simon Möller
@ 2013-08-26  6:04   ` Herbert Xu
  0 siblings, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2013-08-26  6:04 UTC (permalink / raw)
  To: Jan-Simon Möller; +Cc: linux-crypto, behanw, pageexec

On Wed, Aug 21, 2013 at 10:42:01PM +0200, Jan-Simon Möller wrote:
> 
> Should I resend a fixed version with 
> (1U << 27) - 1) instead ?

Sure.

Thanks,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

end of thread, other threads:[~2013-08-26  6:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-15 12:01 [RFC] [PATCH] Fix for a warning - crypto/fcrypt,c Jan-Simon Möller
2013-08-21 10:47 ` Herbert Xu
2013-08-21 15:39   ` PaX Team
2013-08-21 20:42 ` Jan-Simon Möller
2013-08-26  6:04   ` Herbert Xu

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