[PATCH] powerpc/uaccess: fix warning/error with access_ok()

Subsystems: linux for powerpc (32-bit and 64-bit), the rest

STALE2866d

3 messages, 2 authors, 2018-10-18 · open the first message on its own page

[PATCH] powerpc/uaccess: fix warning/error with access_ok()

From: Christophe Leroy <hidden>
Date: 2018-10-18 08:48:48

With the following peace of code, the following compilation warning
is encountered:

	if (_IOC_DIR(ioc) != _IOC_NONE) {
		int verify = _IOC_DIR(ioc) & _IOC_READ ? VERIFY_WRITE : VERIFY_READ;

		if (!access_ok(verify, ioarg, _IOC_SIZE(ioc))) {

drivers/platform/test/dev.c: In function ‘my_ioctl’:
drivers/platform/test/dev.c:219:7: warning: unused variable ‘verify’ [-Wunused-variable]
   int verify = _IOC_DIR(ioc) & _IOC_READ ? VERIFY_WRITE : VERIFY_READ;

This patch fixes it by handing the type to __access_ok(), changing it
to an inline function for PPC64 as already done for PPC32

Signed-off-by: Christophe Leroy <redacted>
---
 arch/powerpc/include/asm/uaccess.h | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
index 15bea9a0f260..97faf0353919 100644
--- a/arch/powerpc/include/asm/uaccess.h
+++ b/arch/powerpc/include/asm/uaccess.h
@@ -47,13 +47,16 @@ static inline void set_fs(mm_segment_t fs)
  * This check is sufficient because there is a large enough
  * gap between user addresses and the kernel addresses
  */
-#define __access_ok(addr, size, segment)	\
-	(((addr) <= (segment).seg) && ((size) <= (segment).seg))
+static inline int __access_ok(int type, unsigned long addr, unsigned long size,
+			      mm_segment_t seg)
+{
+	return addr <= seg.seg && size <= seg.seg;
+}
 
 #else
 
-static inline int __access_ok(unsigned long addr, unsigned long size,
-			mm_segment_t seg)
+static inline int __access_ok(int type, unsigned long addr, unsigned long size,
+			      mm_segment_t seg)
 {
 	if (addr > seg.seg)
 		return 0;
@@ -64,7 +67,7 @@ static inline int __access_ok(unsigned long addr, unsigned long size,
 
 #define access_ok(type, addr, size)		\
 	(__chk_user_ptr(addr),			\
-	 __access_ok((__force unsigned long)(addr), (size), get_fs()))
+	 __access_ok((type), (__force unsigned long)(addr), (size), get_fs()))
 
 /*
  * These are the main single-value transfer routines.  They automatically
-- 
2.13.3

Re: [PATCH] powerpc/uaccess: fix warning/error with access_ok()

From: Christophe LEROY <hidden>
Date: 2018-10-18 09:19:42


Le 18/10/2018 à 10:48, Christophe Leroy a écrit :
With the following peace of code, the following compilation warning
is encountered:

	if (_IOC_DIR(ioc) != _IOC_NONE) {
		int verify = _IOC_DIR(ioc) & _IOC_READ ? VERIFY_WRITE : VERIFY_READ;

		if (!access_ok(verify, ioarg, _IOC_SIZE(ioc))) {

drivers/platform/test/dev.c: In function ‘my_ioctl’:
drivers/platform/test/dev.c:219:7: warning: unused variable ‘verify’ [-Wunused-variable]
    int verify = _IOC_DIR(ioc) & _IOC_READ ? VERIFY_WRITE : VERIFY_READ;

This patch fixes it by handing the type to __access_ok(), changing it
to an inline function for PPC64 as already done for PPC32
Oops, not that easy, there are places using __access_ok() directly, 
those need to be modified as well.

Christophe
quoted hunk
Signed-off-by: Christophe Leroy <redacted>
---
  arch/powerpc/include/asm/uaccess.h | 13 ++++++++-----
  1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
index 15bea9a0f260..97faf0353919 100644
--- a/arch/powerpc/include/asm/uaccess.h
+++ b/arch/powerpc/include/asm/uaccess.h
@@ -47,13 +47,16 @@ static inline void set_fs(mm_segment_t fs)
   * This check is sufficient because there is a large enough
   * gap between user addresses and the kernel addresses
   */
-#define __access_ok(addr, size, segment)	\
-	(((addr) <= (segment).seg) && ((size) <= (segment).seg))
+static inline int __access_ok(int type, unsigned long addr, unsigned long size,
+			      mm_segment_t seg)
+{
+	return addr <= seg.seg && size <= seg.seg;
+}
  
  #else
  
-static inline int __access_ok(unsigned long addr, unsigned long size,
-			mm_segment_t seg)
+static inline int __access_ok(int type, unsigned long addr, unsigned long size,
+			      mm_segment_t seg)
  {
  	if (addr > seg.seg)
  		return 0;
@@ -64,7 +67,7 @@ static inline int __access_ok(unsigned long addr, unsigned long size,
  
  #define access_ok(type, addr, size)		\
  	(__chk_user_ptr(addr),			\
-	 __access_ok((__force unsigned long)(addr), (size), get_fs()))
+	 __access_ok((type), (__force unsigned long)(addr), (size), get_fs()))
  
  /*
   * These are the main single-value transfer routines.  They automatically

Re: [PATCH] powerpc/uaccess: fix warning/error with access_ok()

From: kbuild test robot <hidden>
Date: 2018-10-18 23:12:20

Hi Christophe,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on powerpc/next]
[also build test ERROR on v4.19-rc8 next-20181018]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Christophe-Leroy/powerpc-uaccess-fix-warning-error-with-access_ok/20181019-031908
base:   https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next
config: powerpc-socrates_defconfig (attached as .config)
compiler: powerpc-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.2.0 make.cross ARCH=powerpc 

All error/warnings (new ones prefixed by >>):

   In file included from include/linux/uaccess.h:14:0,
                    from arch/powerpc/include/asm/sections.h:7,
                    from include/linux/kallsyms.h:15,
                    from include/linux/ftrace.h:11,
                    from include/linux/init_task.h:9,
                    from arch/powerpc/kernel/process.c:32:
   arch/powerpc/kernel/process.c: In function 'show_user_instructions':
quoted
arch/powerpc/include/asm/uaccess.h:21:25: error: incompatible type for argument 3 of '__access_ok'
    #define MAKE_MM_SEG(s)  ((mm_segment_t) { (s) })
                            ^
quoted
arch/powerpc/include/asm/uaccess.h:28:18: note: in expansion of macro 'MAKE_MM_SEG'
    #define USER_DS  MAKE_MM_SEG(TASK_SIZE - 1)
                     ^~~~~~~~~~~
quoted
arch/powerpc/kernel/process.c:1313:55: note: in expansion of macro 'USER_DS'
     if (!__access_ok(pc, NR_INSN_TO_PRINT * sizeof(int), USER_DS)) {
                                                          ^~~~~~~
   arch/powerpc/include/asm/uaccess.h:58:19: note: expected 'long unsigned int' but argument is of type 'mm_segment_t {aka struct <anonymous>}'
    static inline int __access_ok(int type, unsigned long addr, unsigned long size,
                      ^~~~~~~~~~~
quoted
arch/powerpc/kernel/process.c:1313:7: error: too few arguments to function '__access_ok'
     if (!__access_ok(pc, NR_INSN_TO_PRINT * sizeof(int), USER_DS)) {
          ^~~~~~~~~~~
   In file included from include/linux/uaccess.h:14:0,
                    from arch/powerpc/include/asm/sections.h:7,
                    from include/linux/kallsyms.h:15,
                    from include/linux/ftrace.h:11,
                    from include/linux/init_task.h:9,
                    from arch/powerpc/kernel/process.c:32:
   arch/powerpc/include/asm/uaccess.h:58:19: note: declared here
    static inline int __access_ok(int type, unsigned long addr, unsigned long size,
                      ^~~~~~~~~~~
--
   In file included from include/linux/uaccess.h:14:0,
                    from arch/powerpc/include/asm/sections.h:7,
                    from include/linux/kallsyms.h:15,
                    from include/linux/ftrace.h:11,
                    from include/linux/kprobes.h:42,
                    from arch/powerpc/lib/sstep.c:12:
   arch/powerpc/lib/sstep.c: In function 'address_ok':
quoted
arch/powerpc/include/asm/uaccess.h:21:25: error: incompatible type for argument 3 of '__access_ok'
    #define MAKE_MM_SEG(s)  ((mm_segment_t) { (s) })
                            ^
quoted
arch/powerpc/include/asm/uaccess.h:28:18: note: in expansion of macro 'MAKE_MM_SEG'
    #define USER_DS  MAKE_MM_SEG(TASK_SIZE - 1)
                     ^~~~~~~~~~~
quoted
arch/powerpc/lib/sstep.c:113:26: note: in expansion of macro 'USER_DS'
     if (__access_ok(ea, nb, USER_DS))
                             ^~~~~~~
   arch/powerpc/include/asm/uaccess.h:58:19: note: expected 'long unsigned int' but argument is of type 'mm_segment_t {aka struct <anonymous>}'
    static inline int __access_ok(int type, unsigned long addr, unsigned long size,
                      ^~~~~~~~~~~
quoted
arch/powerpc/lib/sstep.c:113:6: error: too few arguments to function '__access_ok'
     if (__access_ok(ea, nb, USER_DS))
         ^~~~~~~~~~~
   In file included from include/linux/uaccess.h:14:0,
                    from arch/powerpc/include/asm/sections.h:7,
                    from include/linux/kallsyms.h:15,
                    from include/linux/ftrace.h:11,
                    from include/linux/kprobes.h:42,
                    from arch/powerpc/lib/sstep.c:12:
   arch/powerpc/include/asm/uaccess.h:58:19: note: declared here
    static inline int __access_ok(int type, unsigned long addr, unsigned long size,
                      ^~~~~~~~~~~
quoted
arch/powerpc/include/asm/uaccess.h:21:25: error: incompatible type for argument 3 of '__access_ok'
    #define MAKE_MM_SEG(s)  ((mm_segment_t) { (s) })
                            ^
quoted
arch/powerpc/include/asm/uaccess.h:28:18: note: in expansion of macro 'MAKE_MM_SEG'
    #define USER_DS  MAKE_MM_SEG(TASK_SIZE - 1)
                     ^~~~~~~~~~~
   arch/powerpc/lib/sstep.c:115:25: note: in expansion of macro 'USER_DS'
     if (__access_ok(ea, 1, USER_DS))
                            ^~~~~~~
   arch/powerpc/include/asm/uaccess.h:58:19: note: expected 'long unsigned int' but argument is of type 'mm_segment_t {aka struct <anonymous>}'
    static inline int __access_ok(int type, unsigned long addr, unsigned long size,
                      ^~~~~~~~~~~
   arch/powerpc/lib/sstep.c:115:6: error: too few arguments to function '__access_ok'
     if (__access_ok(ea, 1, USER_DS))
         ^~~~~~~~~~~
   In file included from include/linux/uaccess.h:14:0,
                    from arch/powerpc/include/asm/sections.h:7,
                    from include/linux/kallsyms.h:15,
                    from include/linux/ftrace.h:11,
                    from include/linux/kprobes.h:42,
                    from arch/powerpc/lib/sstep.c:12:
   arch/powerpc/include/asm/uaccess.h:58:19: note: declared here
    static inline int __access_ok(int type, unsigned long addr, unsigned long size,
                      ^~~~~~~~~~~

vim +/__access_ok +21 arch/powerpc/include/asm/uaccess.h

2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29   9  
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29  10  /*
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29  11   * The fs value determines whether argument validity checking should be
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29  12   * performed or not.  If get_fs() == USER_DS, checking is performed, with
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29  13   * get_fs() == KERNEL_DS, checking is bypassed.
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29  14   *
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29  15   * For historical reasons, these macros are grossly misnamed.
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29  16   *
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29  17   * The fs/ds values are now the highest legal address in the "segment".
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29  18   * This simplifies the checking in the routines below.
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29  19   */
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29  20  
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29 @21  #define MAKE_MM_SEG(s)  ((mm_segment_t) { (s) })
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29  22  
5015b494 include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-31  23  #define KERNEL_DS	MAKE_MM_SEG(~0UL)
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29  24  #ifdef __powerpc64__
5015b494 include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-31  25  /* We use TASK_SIZE_USER64 as TASK_SIZE is not constant */
5015b494 include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-31  26  #define USER_DS		MAKE_MM_SEG(TASK_SIZE_USER64 - 1)
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29  27  #else
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29 @28  #define USER_DS		MAKE_MM_SEG(TASK_SIZE - 1)
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29  29  #endif
2df5e8bc include/asm-powerpc/uaccess.h Stephen Rothwell 2005-10-29  30  

:::::: The code at line 21 was first introduced by commit
:::::: 2df5e8bcca53e528a78ee0e3b114d0d21dd6d043 powerpc: merge uaccess.h

:::::: TO: Stephen Rothwell [off-list ref]
:::::: CC: Stephen Rothwell [off-list ref]

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help