013-disable-Wattribute-alias-warning-for-SYSCALL_DEFINEx.patch 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. From: Arnd Bergmann <[email protected]>
  2. Date: Tue, 19 Jun 2018 13:14:57 -0700
  3. Subject: [PATCH] disable -Wattribute-alias warning for SYSCALL_DEFINEx()
  4. gcc-8 warns for every single definition of a system call entry
  5. point, e.g.:
  6. include/linux/compat.h:56:18: error: 'compat_sys_rt_sigprocmask' alias between functions of incompatible types 'long int(int, compat_sigset_t *, compat_sigset_t *, compat_size_t)' {aka 'long int(int, struct <anonymous> *, struct <anonymous> *, unsigned int)'} and 'long int(long int, long int, long int, long int)' [-Werror=attribute-alias]
  7. asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))\
  8. ^~~~~~~~~~
  9. include/linux/compat.h:45:2: note: in expansion of macro 'COMPAT_SYSCALL_DEFINEx'
  10. COMPAT_SYSCALL_DEFINEx(4, _##name, __VA_ARGS__)
  11. ^~~~~~~~~~~~~~~~~~~~~~
  12. kernel/signal.c:2601:1: note: in expansion of macro 'COMPAT_SYSCALL_DEFINE4'
  13. COMPAT_SYSCALL_DEFINE4(rt_sigprocmask, int, how, compat_sigset_t __user *, nset,
  14. ^~~~~~~~~~~~~~~~~~~~~~
  15. include/linux/compat.h:60:18: note: aliased declaration here
  16. asmlinkage long compat_SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__))\
  17. ^~~~~~~~~~
  18. The new warning seems reasonable in principle, but it doesn't
  19. help us here, since we rely on the type mismatch to sanitize the
  20. system call arguments. After I reported this as GCC PR82435, a new
  21. -Wno-attribute-alias option was added that could be used to turn the
  22. warning off globally on the command line, but I'd prefer to do it a
  23. little more fine-grained.
  24. Interestingly, turning a warning off and on again inside of
  25. a single macro doesn't always work, in this case I had to add
  26. an extra statement inbetween and decided to copy the __SC_TEST
  27. one from the native syscall to the compat syscall macro. See
  28. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83256 for more details
  29. about this.
  30. [[email protected]:
  31. - Rebase atop current master.
  32. - Split GCC & version arguments to __diag_ignore() in order to match
  33. changes to the preceding patch.
  34. - Add the comment argument to match the preceding patch.]
  35. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82435
  36. Signed-off-by: Arnd Bergmann <[email protected]>
  37. Signed-off-by: Paul Burton <[email protected]>
  38. Tested-by: Christophe Leroy <[email protected]>
  39. Tested-by: Stafford Horne <[email protected]>
  40. Signed-off-by: Masahiro Yamada <[email protected]>
  41. ---
  42. --- a/include/linux/compat.h
  43. +++ b/include/linux/compat.h
  44. @@ -48,6 +48,9 @@
  45. COMPAT_SYSCALL_DEFINEx(6, _##name, __VA_ARGS__)
  46. #define COMPAT_SYSCALL_DEFINEx(x, name, ...) \
  47. + __diag_push(); \
  48. + __diag_ignore(GCC, 8, "-Wattribute-alias", \
  49. + "Type aliasing is used to sanitize syscall arguments");\
  50. asmlinkage long compat_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))\
  51. __attribute__((alias(__stringify(compat_SyS##name)))); \
  52. static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__));\
  53. @@ -56,6 +59,7 @@
  54. { \
  55. return C_SYSC##name(__MAP(x,__SC_DELOUSE,__VA_ARGS__)); \
  56. } \
  57. + __diag_pop(); \
  58. static inline long C_SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__))
  59. #ifndef compat_user_stack_pointer
  60. --- a/include/linux/syscalls.h
  61. +++ b/include/linux/syscalls.h
  62. @@ -208,6 +208,9 @@ static inline int is_syscall_trace_event
  63. #define __PROTECT(...) asmlinkage_protect(__VA_ARGS__)
  64. #define __SYSCALL_DEFINEx(x, name, ...) \
  65. + __diag_push(); \
  66. + __diag_ignore(GCC, 8, "-Wattribute-alias", \
  67. + "Type aliasing is used to sanitize syscall arguments");\
  68. asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \
  69. __attribute__((alias(__stringify(SyS##name)))); \
  70. static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \
  71. @@ -219,6 +222,7 @@ static inline int is_syscall_trace_event
  72. __PROTECT(x, ret,__MAP(x,__SC_ARGS,__VA_ARGS__)); \
  73. return ret; \
  74. } \
  75. + __diag_pop(); \
  76. static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__))
  77. /*