Skip to contentSkip to conversation

s390/kaslr: Fix casts in get_random

PATCH In review Nathan Chancellor 4 participants 5 messages Feb 8, 2020 – Feb 17, 2020 s390

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390/kaslr: Fix casts in get_random

Clang warns:

../arch/s390/boot/kaslr.c:78:25: warning: passing 'char *' to parameter of type 'const u8 *' (aka 'const unsigned char *') converts between pointers to integer
types with different sign [-Wpointer-sign]
(char *) entropy, (char *) entropy,
^~~~~~~~~~~~~~~~
../arch/s390/include/asm/cpacf.h:280:28: note: passing argument to parameter 'src' here
u8 *dest, const u8 *src, long src_len)
^
2 warnings generated.

Fix the cast to match what else is done in this function.

Fixes b2d24b97b2a9 ("s390/kernel: add support for kernel address space layout randomization (KASLR)")
---
 arch/s390/boot/kaslr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/boot/kaslr.c +1 -1
index 5d12352545c5..5591243d673e 100644
@@ -75,7 +75,7 @@ static unsigned long get_random(unsigned long limit)
 		*(unsigned long *) prng.parm_block ^= seed;
 		for (i = 0; i < 16; i++) {
 			cpacf_kmc(CPACF_KMC_PRNG, prng.parm_block,
-				  (char *) entropy, (char *) entropy,
+				  (u8 *) entropy, (u8 *) entropy,
 				  sizeof(entropy));
 			memcpy(prng.parm_block, entropy, sizeof(entropy));
 		}
Signature · 1 line
2.25.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Nathan Chancellor

Clang warns:

../arch/s390/boot/kaslr.c:78:25: warning: passing 'char *' to parameter of type 'const u8 *' (aka 'const unsigned char *') converts between pointers to integer
types with different sign [-Wpointer-sign]
(char *) entropy, (char *) entropy,
^~~~~~~~~~~~~~~~
../arch/s390/include/asm/cpacf.h:280:28: note: passing argument to parameter 'src' here
u8 *dest, const u8 *src, long src_len)
^
2 warnings generated.

Quoted 5 lines

Fix the cast to match what else is done in this function.

Fixes b2d24b97b2a9 ("s390/kernel: add support for kernel address space layout randomization (KASLR)")

Thanks for the patch!

Quoted 24 lines
---
 arch/s390/boot/kaslr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/boot/kaslr.c +1 -2
index 5d12352545c5..5591243d673e 100644
@@ -75,7 +75,7 @@ static unsigned long get_random(unsigned long limit)
                *(unsigned long *) prng.parm_block ^= seed;
                for (i = 0; i < 16; i++) {
                        cpacf_kmc(CPACF_KMC_PRNG, prng.parm_block,
-                                 (char *) entropy, (char *) entropy,
+                                 (u8 *) entropy, (u8 *) entropy,
                                  sizeof(entropy));
                        memcpy(prng.parm_block, entropy, sizeof(entropy));
                }
--

2.25.0

--
You received this message because you are subscribed to the Google Groups "Clang Built Linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/20200208141052.48476-1-natechancellor%40gmail.com.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#2 lore raw
In reply to Nathan Chancellor
Quoted 28 lines · Nathan Chancellor

Clang warns:

../arch/s390/boot/kaslr.c:78:25: warning: passing 'char *' to parameter of type 'const u8 *' (aka 'const unsigned char *') converts between pointers to integer
types with different sign [-Wpointer-sign]
(char *) entropy, (char *) entropy,
^~~~~~~~~~~~~~~~
../arch/s390/include/asm/cpacf.h:280:28: note: passing argument to parameter 'src' here
u8 *dest, const u8 *src, long src_len)
^
2 warnings generated.

Fix the cast to match what else is done in this function.

Fixes b2d24b97b2a9 ("s390/kernel: add support for kernel address space layout randomization (KASLR)")
---
 arch/s390/boot/kaslr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/boot/kaslr.c +0 -0
index 5d12352545c5..5591243d673e 100644

arch/s390/boot/kaslr.c static unsigned long get_random(unsigned long limit) · line 78

Quoted 5 lines
arch/s390/boot/kaslr.c +1 -1
@@ -75,7 +75,7 @@ static unsigned long get_random(unsigned long limit)
 		*(unsigned long *) prng.parm_block ^= seed;
 		for (i = 0; i < 16; i++) {
 			cpacf_kmc(CPACF_KMC_PRNG, prng.parm_block,
-				  (char *) entropy, (char *) entropy,
+				  (u8 *) entropy, (u8 *) entropy,

Why not change the function to take void *?

static inline int cpacf_kmc(unsigned long func, void *param,
u8 *dest, const u8 *src, long src_len)

vs:

static inline int cpacf_kmc(unsigned long func, void *param,
void *dest, const void *src, long src_len)

and remove the casts?

#3 lore raw
Quoted 40 lines · Joe Perches
Quoted 28 lines · Nathan Chancellor

Clang warns:

../arch/s390/boot/kaslr.c:78:25: warning: passing 'char *' to parameter of type 'const u8 *' (aka 'const unsigned char *') converts between pointers to integer
types with different sign [-Wpointer-sign]
(char *) entropy, (char *) entropy,
^~~~~~~~~~~~~~~~
../arch/s390/include/asm/cpacf.h:280:28: note: passing argument to parameter 'src' here
u8 *dest, const u8 *src, long src_len)
^
2 warnings generated.

Fix the cast to match what else is done in this function.

Fixes b2d24b97b2a9 ("s390/kernel: add support for kernel address space layout randomization (KASLR)")
---
 arch/s390/boot/kaslr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/boot/kaslr.c +0 -0
index 5d12352545c5..5591243d673e 100644

arch/s390/boot/kaslr.c static unsigned long get_random(unsigned long limit) · line 78

Quoted 5 lines
arch/s390/boot/kaslr.c +1 -1
@@ -75,7 +75,7 @@ static unsigned long get_random(unsigned long limit)
 		*(unsigned long *) prng.parm_block ^= seed;
 		for (i = 0; i < 16; i++) {
 			cpacf_kmc(CPACF_KMC_PRNG, prng.parm_block,
-				  (char *) entropy, (char *) entropy,
+				  (u8 *) entropy, (u8 *) entropy,

Why not change the function to take void *?

static inline int cpacf_kmc(unsigned long func, void *param,
u8 *dest, const u8 *src, long src_len)

Quoted 6 lines

vs:

static inline int cpacf_kmc(unsigned long func, void *param,
void *dest, const void *src, long src_len)

and remove the casts?

I can certainly do that if the maintainers prefer it.

Cheers,
Nathan

maintainer
#4 lore raw
Quoted 46 lines · Nathan Chancellor
Quoted 45 lines · Joe Perches
Quoted 28 lines · Nathan Chancellor

Clang warns:

../arch/s390/boot/kaslr.c:78:25: warning: passing 'char *' to parameter of type 'const u8 *' (aka 'const unsigned char *') converts between pointers to integer
types with different sign [-Wpointer-sign]
(char *) entropy, (char *) entropy,
^~~~~~~~~~~~~~~~
../arch/s390/include/asm/cpacf.h:280:28: note: passing argument to parameter 'src' here
u8 *dest, const u8 *src, long src_len)
^
2 warnings generated.

Fix the cast to match what else is done in this function.

Fixes b2d24b97b2a9 ("s390/kernel: add support for kernel address space layout randomization (KASLR)")
---
 arch/s390/boot/kaslr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/boot/kaslr.c +0 -0
index 5d12352545c5..5591243d673e 100644

arch/s390/boot/kaslr.c static unsigned long get_random(unsigned long limit) · line 78

Quoted 5 lines
arch/s390/boot/kaslr.c +1 -1
@@ -75,7 +75,7 @@ static unsigned long get_random(unsigned long limit)
 		*(unsigned long *) prng.parm_block ^= seed;
 		for (i = 0; i < 16; i++) {
 			cpacf_kmc(CPACF_KMC_PRNG, prng.parm_block,
-				  (char *) entropy, (char *) entropy,
+				  (u8 *) entropy, (u8 *) entropy,

Why not change the function to take void *?

static inline int cpacf_kmc(unsigned long func, void *param,
u8 *dest, const u8 *src, long src_len)

vs:

static inline int cpacf_kmc(unsigned long func, void *param,
void *dest, const void *src, long src_len)

Quoted 6 lines
Quoted 1 line

and remove the casts?

I can certainly do that if the maintainers prefer it.

Cheers,
Nathan

KBUILD_CFLAGS contains -Wno-pointer-sign but special arch/s390/boot code has a separate set of build flags. Anyhow the change makes sense as it is. Applied to fixes, thanks