Re: [PATCH 06/21] powerpc: Avoid comparison of unsigned long >= 0 in __access_ok

From: Christophe LEROY
Date: Mon Feb 26 2018 - 01:50:41 EST




Le 26/02/2018 Ã 07:34, Christophe LEROY a ÃcritÂ:


Le 25/02/2018 Ã 18:22, Mathieu Malaterre a ÃcritÂ:
Rewrite check size - 1 <= Y as size < Y since `size` is unsigned value.
Fix warning (treated as error in W=1):

ÂÂ CCÂÂÂÂÂ arch/powerpc/kernel/signal_32.o
In file included from ./include/linux/uaccess.h:14:0,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ from ./include/asm-generic/termios-base.h:8,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ from ./arch/powerpc/include/asm/termios.h:20,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ from ./include/uapi/linux/termios.h:6,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ from ./include/linux/tty.h:7,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ from arch/powerpc/kernel/signal_32.c:36:
./include/asm-generic/termios-base.h: In function âuser_termio_to_kernel_termiosâ:
./arch/powerpc/include/asm/uaccess.h:52:35: error: comparison of unsigned expression >= 0 is always true [-Werror=type-limits]
ÂÂÂ (((size) == 0) || (((size) - 1) <= ((segment).seg - (addr)))))
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ^
./arch/powerpc/include/asm/uaccess.h:58:3: note: in expansion of macro â__access_okâ
ÂÂÂ __access_ok((__force unsigned long)(addr), (size), get_fs()))
ÂÂÂ ^~~~~~~~~~~
./arch/powerpc/include/asm/uaccess.h:262:6: note: in expansion of macro âaccess_okâ
ÂÂ if (access_ok(VERIFY_READ, __gu_addr, (size)))ÂÂ \
ÂÂÂÂÂÂ ^~~~~~~~~
./arch/powerpc/include/asm/uaccess.h:80:2: note: in expansion of macro â__get_user_checkâ
ÂÂ __get_user_check((x), (ptr), sizeof(*(ptr)))
ÂÂ ^~~~~~~~~~~~~~~~
./include/asm-generic/termios-base.h:36:6: note: in expansion of macro âget_userâ
ÂÂ if (get_user(termios->c_line, &termio->c_line) < 0)
ÂÂÂÂÂÂ ^~~~~~~~
[...]
cc1: all warnings being treated as errors

Signed-off-by: Mathieu Malaterre <malat@xxxxxxxxxx>
---
 arch/powerpc/include/asm/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
index 51bfeb8777f0..fadc406bd39d 100644
--- a/arch/powerpc/include/asm/uaccess.h
+++ b/arch/powerpc/include/asm/uaccess.h
@@ -49,7 +49,7 @@
 #define __access_ok(addr, size, segment) \
ÂÂÂÂÂ (((addr) <= (segment).seg) &&ÂÂÂÂÂÂÂ \
-ÂÂÂÂ (((size) == 0) || (((size) - 1) <= ((segment).seg - (addr)))))
+ÂÂÂÂ (((size) == 0) || ((size) < ((segment).seg - (addr)))))

IIUC, ((2 - 1) <= 1) is the same as (2 < 1) ?????


Note that I already try to submit a fix for this warning 3 years ago (https://patchwork.ozlabs.org/patch/418075/) and it was rejected with the following comment:

Again, I don't think Linux enables this warning. What did you do to
produce this? In any case, it's a bad warning that doesn't take macros
into account, and the answer is not to make the code less clear by hiding
the fact that zero is a special case.

Christophe



Christophe

 #endif