Skip to contentSkip to conversation

initity: try to improve __nocapture annotations

PATCH In review Arnd Bergmann 3 participants 7 messages Feb 1, 2017 – Feb 2, 2017

Subsystems (7)
lore
Share & tools
lore

Arnd Bergmann

author maintainer
#0 lore raw

PATCH 1/1 initity: try to improve __nocapture annotations

There are some additional declarations that got missed in the original patch, and some annotated functions that use the pointer is a correct but nonobvious way:

mm/kasan/kasan.c: In function 'memmove':
mm/kasan/kasan.c:346:7: error: 'memmove' captures its 2 ('src') parameter, please remove it from the nocapture attribute. [-Werror]
void *memmove(void *dest, const void *src, size_t len)

       ^~~~~~~
mm/kasan/kasan.c: In function 'memcpy':
mm/kasan/kasan.c:355:7: error: 'memcpy' captures its 2 ('src') parameter, please remove it from the nocapture attribute. [-Werror]
 void *memcpy(void *dest, const void *src, size_t len)
       ^~~~~~

drivers/acpi/acpica/utdebug.c: In function 'acpi_debug_print':
drivers/acpi/acpica/utdebug.c:158:1: error: 'acpi_debug_print' captures its 3 ('function_name') parameter, please remove it from the nocapture attribute. [-Werror]

lib/string.c:893:7: error: 'memchr_inv' captures its 1 ('start') parameter, please remove it from the nocapture attribute. [-Werror]
void *memchr_inv(const void *start, int c, size_t bytes)
lib/string.c: In function 'strnstr':
lib/string.c:832:7: error: 'strnstr' captures its 1 ('s1') parameter, please remove it from the nocapture attribute. [-Werror]
char *strnstr(const char *s1, const char *s2, size_t len)

       ^~~~~~~

lib/string.c:832:7: error: 'strnstr' captures its 2 ('s2') parameter, please remove it from the nocapture attribute. [-Werror]

I'm not sure if these are all appropriate fixes, please have a careful look

Fixes c2bc07665495 ("initify: Mark functions with the __nocapture attribute")
---
 drivers/acpi/acpica/utdebug.c        | 2 +-
 include/acpi/acpixf.h                | 2 +-
 include/asm-generic/asm-prototypes.h | 8 ++++----
 include/linux/string.h               | 2 +-
 lib/string.c                         | 2 +-
 mm/kasan/kasan.c                     | 4 ++--
 6 files changed, 10 insertions(+), 10 deletions(-)
drivers/acpi/acpica/utdebug.c +1 -1
index 044df9b0356e..de3c9cb305a2 100644
@@ -154,7 +154,7 @@ static const char *acpi_ut_trim_function_name(const char *function_name)
  *
  ******************************************************************************/
 
-void ACPI_INTERNAL_VAR_XFACE
+void __unverified_nocapture(3) ACPI_INTERNAL_VAR_XFACE
 acpi_debug_print(u32 requested_debug_level,
 		 u32 line_number,
 		 const char *function_name,
include/acpi/acpixf.h +1 -1
index 9f4637e9dd92..9644cec5b082 100644
@@ -946,7 +946,7 @@ ACPI_DBG_DEPENDENT_RETURN_VOID(ACPI_PRINTF_LIKE(6) __nocapture(3)
 						const char *module_name,
 						u32 component_id,
 						const char *format, ...))
-ACPI_DBG_DEPENDENT_RETURN_VOID(ACPI_PRINTF_LIKE(6)
+ACPI_DBG_DEPENDENT_RETURN_VOID(ACPI_PRINTF_LIKE(6) __nocapture(3)
 				void ACPI_INTERNAL_VAR_XFACE
 				acpi_debug_print_raw(u32 requested_debug_level,
 						     u32 line_number,
include/asm-generic/asm-prototypes.h +4 -4
index 939869c772b1..ffc0dd7e8ed2 100644
@@ -2,12 +2,12 @@
 #undef __memset
 extern void *__memset(void *, int, __kernel_size_t);
 #undef __memcpy
-extern void *__memcpy(void *, const void *, __kernel_size_t);
+extern void *__memcpy(void *, const void *, __kernel_size_t) __nocapture(2);
 #undef __memmove
-extern void *__memmove(void *, const void *, __kernel_size_t);
+extern void *__memmove(void *, const void *, __kernel_size_t) __nocapture(2);
 #undef memset
 extern void *memset(void *, int, __kernel_size_t);
 #undef memcpy
-extern void *memcpy(void *, const void *, __kernel_size_t);
+extern void *memcpy(void *, const void *, __kernel_size_t) __nocapture(2);
 #undef memmove
-extern void *memmove(void *, const void *, __kernel_size_t);
+extern void *memmove(void *, const void *, __kernel_size_t) __nocapture(2);
include/linux/string.h +1 -1
index 8b3b97e7b2b0..0ee877593464 100644
@@ -76,7 +76,7 @@ static inline __must_check char *strstrip(char *str)
 extern char * strstr(const char *, const char *) __nocapture(-1, 2);
 #endif
 #ifndef __HAVE_ARCH_STRNSTR
-extern char * strnstr(const char *, const char *, size_t) __nocapture(-1, 2);
+extern char * strnstr(const char *, const char *, size_t);
 #endif
 #ifndef __HAVE_ARCH_STRLEN
 extern __kernel_size_t strlen(const char *) __nocapture(1);
lib/string.c +1 -1
index ed83562a53ae..01151a1a0b61 100644
@@ -870,7 +870,7 @@ void *memchr(const void *s, int c, size_t n)
 EXPORT_SYMBOL(memchr);
 #endif
 
-static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes)
+static __always_inline void *check_bytes8(const u8 *start, u8 value, unsigned int bytes)
 {
 	while (bytes) {
 		if (*start != value)
mm/kasan/kasan.c +2 -2
index 5f6e09c88d25..ebc02ee1118e 100644
@@ -343,7 +343,7 @@ void *memset(void *addr, int c, size_t len)
 }
 
 #undef memmove
-void *memmove(void *dest, const void *src, size_t len)
+__unverified_nocapture(2) void *memmove(void *dest, const void *src, size_t len)
 {
 	check_memory_region((unsigned long)src, len, false, _RET_IP_);
 	check_memory_region((unsigned long)dest, len, true, _RET_IP_);
@@ -352,7 +352,7 @@ void *memmove(void *dest, const void *src, size_t len)
 }
 
 #undef memcpy
-void *memcpy(void *dest, const void *src, size_t len)
+__unverified_nocapture(2) void *memcpy(void *dest, const void *src, size_t len)
 {
 	check_memory_region((unsigned long)src, len, false, _RET_IP_);
 	check_memory_region((unsigned long)dest, len, true, _RET_IP_);
Signature · 1 line
2.9.0
#1 lore raw
Quoted 41 lines · Arnd Bergmann

There are some additional declarations that got missed in the original patch, and some annotated functions that use the pointer is a correct but nonobvious way:

mm/kasan/kasan.c: In function 'memmove':
mm/kasan/kasan.c:346:7: error: 'memmove' captures its 2 ('src') parameter, please remove it from the nocapture attribute. [-Werror]
void *memmove(void *dest, const void *src, size_t len)

       ^~~~~~~
mm/kasan/kasan.c: In function 'memcpy':
mm/kasan/kasan.c:355:7: error: 'memcpy' captures its 2 ('src') parameter, please remove it from the nocapture attribute. [-Werror]
 void *memcpy(void *dest, const void *src, size_t len)
       ^~~~~~

drivers/acpi/acpica/utdebug.c: In function 'acpi_debug_print':
drivers/acpi/acpica/utdebug.c:158:1: error: 'acpi_debug_print' captures its 3 ('function_name') parameter, please remove it from the nocapture attribute. [-Werror]

lib/string.c:893:7: error: 'memchr_inv' captures its 1 ('start') parameter, please remove it from the nocapture attribute. [-Werror]
void *memchr_inv(const void *start, int c, size_t bytes)
lib/string.c: In function 'strnstr':
lib/string.c:832:7: error: 'strnstr' captures its 1 ('s1') parameter, please remove it from the nocapture attribute. [-Werror]
char *strnstr(const char *s1, const char *s2, size_t len)

       ^~~~~~~

lib/string.c:832:7: error: 'strnstr' captures its 2 ('s2') parameter, please remove it from the nocapture attribute. [-Werror]

I'm not sure if these are all appropriate fixes, please have a careful look

Fixes c2bc07665495 ("initify: Mark functions with the __nocapture attribute")
---
 drivers/acpi/acpica/utdebug.c        | 2 +-
 include/acpi/acpixf.h                | 2 +-
 include/asm-generic/asm-prototypes.h | 8 ++++----
 include/linux/string.h               | 2 +-
 lib/string.c                         | 2 +-
 mm/kasan/kasan.c                     | 4 ++--
 6 files changed, 10 insertions(+), 10 deletions(-)
drivers/acpi/acpica/utdebug.c +0 -0
index 044df9b0356e..de3c9cb305a2 100644

drivers/acpi/acpica/utdebug.c static const char *acpi_ut_trim_function_name(const char *function_name) · line 157

Quoted 5 lines
drivers/acpi/acpica/utdebug.c +1 -1
@@ -154,7 +154,7 @@ static const char *acpi_ut_trim_function_name(const char *function_name)
  *
  ******************************************************************************/
 
-void ACPI_INTERNAL_VAR_XFACE
+void __unverified_nocapture(3) ACPI_INTERNAL_VAR_XFACE

Generally speaking, there is a problem with adding annotations like this to ACPICA code.

We get that code from an external project (upstream ACPICA) and the more Linux-specific stuff is there in it, the more difficult to maintain it becomes.

Thanks,
Rafael

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 51 lines · Rafael J. Wysocki
Quoted 41 lines · Arnd Bergmann

There are some additional declarations that got missed in the original patch, and some annotated functions that use the pointer is a correct but nonobvious way:

mm/kasan/kasan.c: In function 'memmove':
mm/kasan/kasan.c:346:7: error: 'memmove' captures its 2 ('src') parameter, please remove it from the nocapture attribute. [-Werror]
void *memmove(void *dest, const void *src, size_t len)

       ^~~~~~~
mm/kasan/kasan.c: In function 'memcpy':
mm/kasan/kasan.c:355:7: error: 'memcpy' captures its 2 ('src') parameter, please remove it from the nocapture attribute. [-Werror]
 void *memcpy(void *dest, const void *src, size_t len)
       ^~~~~~

drivers/acpi/acpica/utdebug.c: In function 'acpi_debug_print':
drivers/acpi/acpica/utdebug.c:158:1: error: 'acpi_debug_print' captures its 3 ('function_name') parameter, please remove it from the nocapture attribute. [-Werror]

lib/string.c:893:7: error: 'memchr_inv' captures its 1 ('start') parameter, please remove it from the nocapture attribute. [-Werror]
void *memchr_inv(const void *start, int c, size_t bytes)
lib/string.c: In function 'strnstr':
lib/string.c:832:7: error: 'strnstr' captures its 1 ('s1') parameter, please remove it from the nocapture attribute. [-Werror]
char *strnstr(const char *s1, const char *s2, size_t len)

       ^~~~~~~

lib/string.c:832:7: error: 'strnstr' captures its 2 ('s2') parameter, please remove it from the nocapture attribute. [-Werror]

I'm not sure if these are all appropriate fixes, please have a careful look

Fixes c2bc07665495 ("initify: Mark functions with the __nocapture attribute")
---
 drivers/acpi/acpica/utdebug.c        | 2 +-
 include/acpi/acpixf.h                | 2 +-
 include/asm-generic/asm-prototypes.h | 8 ++++----
 include/linux/string.h               | 2 +-
 lib/string.c                         | 2 +-
 mm/kasan/kasan.c                     | 4 ++--
 6 files changed, 10 insertions(+), 10 deletions(-)
drivers/acpi/acpica/utdebug.c +0 -0
index 044df9b0356e..de3c9cb305a2 100644

drivers/acpi/acpica/utdebug.c static const char *acpi_ut_trim_function_name(const char *function_name) · line 157

Quoted 5 lines
drivers/acpi/acpica/utdebug.c +1 -1
@@ -154,7 +154,7 @@ static const char *acpi_ut_trim_function_name(const char *function_name)
  *
  ******************************************************************************/
 
-void ACPI_INTERNAL_VAR_XFACE
+void __unverified_nocapture(3) ACPI_INTERNAL_VAR_XFACE

Generally speaking, there is a problem with adding annotations like this to ACPICA code.

Quoted 3 lines

We get that code from an external project (upstream ACPICA) and the more Linux-specific stuff is there in it, the more difficult to maintain it becomes.

We need to find a way to solve this. Why can't take take our changes? Or better yet, why can't we keep a delta from them if they won't take them?

-Kees

Signature · 8 lines
Kees Cook
Pixel Security

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw
Quoted 52 lines · Kees Cook
Quoted 51 lines · Rafael J. Wysocki
Quoted 41 lines · Arnd Bergmann

There are some additional declarations that got missed in the original patch, and some annotated functions that use the pointer is a correct but nonobvious way:

mm/kasan/kasan.c: In function 'memmove':
mm/kasan/kasan.c:346:7: error: 'memmove' captures its 2 ('src') parameter, please remove it from the nocapture attribute. [-Werror]
void *memmove(void *dest, const void *src, size_t len)

       ^~~~~~~
mm/kasan/kasan.c: In function 'memcpy':
mm/kasan/kasan.c:355:7: error: 'memcpy' captures its 2 ('src') parameter, please remove it from the nocapture attribute. [-Werror]
 void *memcpy(void *dest, const void *src, size_t len)
       ^~~~~~

drivers/acpi/acpica/utdebug.c: In function 'acpi_debug_print':
drivers/acpi/acpica/utdebug.c:158:1: error: 'acpi_debug_print' captures its 3 ('function_name') parameter, please remove it from the nocapture attribute. [-Werror]

lib/string.c:893:7: error: 'memchr_inv' captures its 1 ('start') parameter, please remove it from the nocapture attribute. [-Werror]
void *memchr_inv(const void *start, int c, size_t bytes)
lib/string.c: In function 'strnstr':
lib/string.c:832:7: error: 'strnstr' captures its 1 ('s1') parameter, please remove it from the nocapture attribute. [-Werror]
char *strnstr(const char *s1, const char *s2, size_t len)

       ^~~~~~~

lib/string.c:832:7: error: 'strnstr' captures its 2 ('s2') parameter, please remove it from the nocapture attribute. [-Werror]

I'm not sure if these are all appropriate fixes, please have a careful look

Fixes c2bc07665495 ("initify: Mark functions with the __nocapture attribute")
---
 drivers/acpi/acpica/utdebug.c        | 2 +-
 include/acpi/acpixf.h                | 2 +-
 include/asm-generic/asm-prototypes.h | 8 ++++----
 include/linux/string.h               | 2 +-
 lib/string.c                         | 2 +-
 mm/kasan/kasan.c                     | 4 ++--
 6 files changed, 10 insertions(+), 10 deletions(-)
drivers/acpi/acpica/utdebug.c +0 -0
index 044df9b0356e..de3c9cb305a2 100644

drivers/acpi/acpica/utdebug.c static const char *acpi_ut_trim_function_name(const char *function_name) · line 157

Quoted 5 lines
drivers/acpi/acpica/utdebug.c +1 -1
@@ -154,7 +154,7 @@ static const char *acpi_ut_trim_function_name(const char *function_name)
  *
  ******************************************************************************/
 
-void ACPI_INTERNAL_VAR_XFACE
+void __unverified_nocapture(3) ACPI_INTERNAL_VAR_XFACE

Generally speaking, there is a problem with adding annotations like this to ACPICA code.

Quoted 5 lines
Quoted 3 lines

We get that code from an external project (upstream ACPICA) and the more Linux-specific stuff is there in it, the more difficult to maintain it becomes.

We need to find a way to solve this. Why can't take take our changes?

Basically because it has to be possible to build their code using other compilers and build environments (some of them sort of exotic).

Quoted 1 line

Or better yet, why can't we keep a delta from them if they won't take them?

The coding style of the original code is different from the kernel one and the process used to keep track of the differences is non-trivial. The more differences there are, the more difficult it becomes to generate patches to backport upstream changes to the kernel code base and the more likely it is to introduce bugs in the process which sort of would defeat the purpose of the whole hardening exercise.

Let me reverse the question, then: Why is it necessary to annotate the ACPICA code this way instead of just leaving it alone?

Thanks,
Rafael

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
Quoted 17 lines · Rafael J. Wysocki
Quoted 16 lines · Kees Cook
Quoted 15 lines · Rafael J. Wysocki

drivers/acpi/acpica/utdebug.c static const char *acpi_ut_trim_function_name(const char *function_name) · line 157

Quoted 10 lines · Arnd Bergmann
drivers/acpi/acpica/utdebug.c +1 -1
index 044df9b0356e..de3c9cb305a2 100644
@@ -154,7 +154,7 @@ static const char *acpi_ut_trim_function_name(const char *function_name)
  *
  ******************************************************************************/
 
-void ACPI_INTERNAL_VAR_XFACE
+void __unverified_nocapture(3) ACPI_INTERNAL_VAR_XFACE

Generally speaking, there is a problem with adding annotations like this to ACPICA code.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

We get that code from an external project (upstream ACPICA) and the more Linux-specific stuff is there in it, the more difficult to maintain it becomes.

We need to find a way to solve this. Why can't take take our changes?

Basically because it has to be possible to build their code using other compilers and build environments (some of them sort of exotic).

Surely those environments can support macros to make this all work sanely?

Quoted 11 lines
Quoted 1 line

Or better yet, why can't we keep a delta from them if they won't take them?

The coding style of the original code is different from the kernel one and the process used to keep track of the differences is non-trivial. The more differences there are, the more difficult it becomes to generate patches to backport upstream changes to the kernel code base and the more likely it is to introduce bugs in the process which sort of would defeat the purpose of the whole hardening exercise.

Let me reverse the question, then: Why is it necessary to annotate the ACPICA code this way instead of just leaving it alone?

With the GCC plugins there are going to be more and more automatic analysis of the kernel code base, and it'll require global changes to the kernel to mark things one way or another, opt in or out of things, etc. We need to be able to treat the kernel code as a single code base, since that's how the plugins see it. Without this, we're restricting the value those plugins bring.

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
#5 lore raw
In reply to Arnd Bergmann
Quoted 41 lines · Arnd Bergmann

There are some additional declarations that got missed in the original patch, and some annotated functions that use the pointer is a correct but nonobvious way:

mm/kasan/kasan.c: In function 'memmove':
mm/kasan/kasan.c:346:7: error: 'memmove' captures its 2 ('src') parameter, please remove it from the nocapture attribute. [-Werror]
void *memmove(void *dest, const void *src, size_t len)

       ^~~~~~~
mm/kasan/kasan.c: In function 'memcpy':
mm/kasan/kasan.c:355:7: error: 'memcpy' captures its 2 ('src') parameter, please remove it from the nocapture attribute. [-Werror]
 void *memcpy(void *dest, const void *src, size_t len)
       ^~~~~~

drivers/acpi/acpica/utdebug.c: In function 'acpi_debug_print':
drivers/acpi/acpica/utdebug.c:158:1: error: 'acpi_debug_print' captures its 3 ('function_name') parameter, please remove it from the nocapture attribute. [-Werror]

lib/string.c:893:7: error: 'memchr_inv' captures its 1 ('start') parameter, please remove it from the nocapture attribute. [-Werror]
void *memchr_inv(const void *start, int c, size_t bytes)
lib/string.c: In function 'strnstr':
lib/string.c:832:7: error: 'strnstr' captures its 1 ('s1') parameter, please remove it from the nocapture attribute. [-Werror]
char *strnstr(const char *s1, const char *s2, size_t len)

       ^~~~~~~

lib/string.c:832:7: error: 'strnstr' captures its 2 ('s2') parameter, please remove it from the nocapture attribute. [-Werror]

I'm not sure if these are all appropriate fixes, please have a careful look

Fixes c2bc07665495 ("initify: Mark functions with the __nocapture attribute")
---
 drivers/acpi/acpica/utdebug.c        | 2 +-
 include/acpi/acpixf.h                | 2 +-
 include/asm-generic/asm-prototypes.h | 8 ++++----
 include/linux/string.h               | 2 +-
 lib/string.c                         | 2 +-
 mm/kasan/kasan.c                     | 4 ++--
 6 files changed, 10 insertions(+), 10 deletions(-)
drivers/acpi/acpica/utdebug.c +0 -0
index 044df9b0356e..de3c9cb305a2 100644

drivers/acpi/acpica/utdebug.c static const char *acpi_ut_trim_function_name(const char *function_name) · line 160

Quoted 8 lines
drivers/acpi/acpica/utdebug.c +1 -1
@@ -154,7 +154,7 @@ static const char *acpi_ut_trim_function_name(const char *function_name)
  *
  ******************************************************************************/
 
-void ACPI_INTERNAL_VAR_XFACE
+void __unverified_nocapture(3) ACPI_INTERNAL_VAR_XFACE
 acpi_debug_print(u32 requested_debug_level,
                 u32 line_number,
                 const char *function_name,

This might be better by marking acpi_ut_trim_function_name() as __nocapture. I'll give it a try...

include/acpi/acpixf.h ACPI_DBG_DEPENDENT_RETURN_VOID(ACPI_PRINTF_LIKE(6) __nocapture(3) · line 952

Quoted 13 lines
include/acpi/acpixf.h +1 -1
index 9f4637e9dd92..9644cec5b082 100644
@@ -946,7 +946,7 @@ ACPI_DBG_DEPENDENT_RETURN_VOID(ACPI_PRINTF_LIKE(6) __nocapture(3)
                                                const char *module_name,
                                                u32 component_id,
                                                const char *format, ...))
-ACPI_DBG_DEPENDENT_RETURN_VOID(ACPI_PRINTF_LIKE(6)
+ACPI_DBG_DEPENDENT_RETURN_VOID(ACPI_PRINTF_LIKE(6) __nocapture(3)
                                void ACPI_INTERNAL_VAR_XFACE
                                acpi_debug_print_raw(u32 requested_debug_level,
                                                     u32 line_number,

I wonder why the plugin needs this at all: function_name (the third arg) isn't even used in the function.

Quoted 11 lines
include/asm-generic/asm-prototypes.h +1 -1
index 939869c772b1..ffc0dd7e8ed2 100644
@@ -2,12 +2,12 @@
 #undef __memset
 extern void *__memset(void *, int, __kernel_size_t);
 #undef __memcpy
-extern void *__memcpy(void *, const void *, __kernel_size_t);
+extern void *__memcpy(void *, const void *, __kernel_size_t) __nocapture(2);
 #undef __memmove

include/asm-generic/asm-prototypes.h line 13

Quoted 10 lines
include/asm-generic/asm-prototypes.h +3 -3
-extern void *__memmove(void *, const void *, __kernel_size_t);
+extern void *__memmove(void *, const void *, __kernel_size_t) __nocapture(2);
 #undef memset
 extern void *memset(void *, int, __kernel_size_t);
 #undef memcpy
-extern void *memcpy(void *, const void *, __kernel_size_t);
+extern void *memcpy(void *, const void *, __kernel_size_t) __nocapture(2);
 #undef memmove
-extern void *memmove(void *, const void *, __kernel_size_t);
+extern void *memmove(void *, const void *, __kernel_size_t) __nocapture(2);

Ah yeah, KASAN. This seems correct.

include/linux/string.h static inline __must_check char *strstrip(char *str) · line 79

Quoted 10 lines
include/linux/string.h +1 -1
index 8b3b97e7b2b0..0ee877593464 100644
@@ -76,7 +76,7 @@ static inline __must_check char *strstrip(char *str)
 extern char * strstr(const char *, const char *) __nocapture(-1, 2);
 #endif
 #ifndef __HAVE_ARCH_STRNSTR
-extern char * strnstr(const char *, const char *, size_t) __nocapture(-1, 2);
+extern char * strnstr(const char *, const char *, size_t);

That doesn't seem right: strnstr doesn't capture...

lib/string.c void *memchr(const void *s, int c, size_t n) · line 873

Quoted 13 lines
include/linux/string.h +0 -0
 #endif
 #ifndef __HAVE_ARCH_STRLEN
 extern __kernel_size_t strlen(const char *) __nocapture(1);
lib/string.c +1 -1
index ed83562a53ae..01151a1a0b61 100644
@@ -870,7 +870,7 @@ void *memchr(const void *s, int c, size_t n)
 EXPORT_SYMBOL(memchr);
 #endif
 
-static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes)
+static __always_inline void *check_bytes8(const u8 *start, u8 value, unsigned int bytes)

Is this from another fix? Seems unrelated?

Quoted 26 lines
lib/string.c +0 -0
 {
        while (bytes) {
                if (*start != value)
mm/kasan/kasan.c +2 -3
index 5f6e09c88d25..ebc02ee1118e 100644
@@ -343,7 +343,7 @@ void *memset(void *addr, int c, size_t len)
 }
 
 #undef memmove
-void *memmove(void *dest, const void *src, size_t len)
+__unverified_nocapture(2) void *memmove(void *dest, const void *src, size_t len)
 {
        check_memory_region((unsigned long)src, len, false, _RET_IP_);
        check_memory_region((unsigned long)dest, len, true, _RET_IP_);
@@ -352,7 +352,7 @@ void *memmove(void *dest, const void *src, size_t len)
 }
 
 #undef memcpy
-void *memcpy(void *dest, const void *src, size_t len)
+__unverified_nocapture(2) void *memcpy(void *dest, const void *src, size_t len)
 {
        check_memory_region((unsigned long)src, len, false, _RET_IP_);
        check_memory_region((unsigned long)dest, len, true, _RET_IP_);
--
Quoted 2 lines

2.9.0

Thanks for the patch! I'll try to reproduce the warnings and get some fixes built if Emese or PaX Team don't beat me to it. :)

-Kees

Signature · 8 lines
Kees Cook
Pixel Security

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
author maintainer
#6 lore raw
Quoted 10 lines · Kees Cook

drivers/acpi/acpica/utdebug.c static const char *acpi_ut_trim_function_name(const char *function_name) · line 160

Quoted 5 lines · Arnd Bergmann
drivers/acpi/acpica/utdebug.c +1 -1
-void ACPI_INTERNAL_VAR_XFACE
+void __unverified_nocapture(3) ACPI_INTERNAL_VAR_XFACE
 acpi_debug_print(u32 requested_debug_level,
                 u32 line_number,
                 const char *function_name,

This might be better by marking acpi_ut_trim_function_name() as __nocapture. I'll give it a try...

I tried that without success: the problem is actually the later acpi_os_printf() that takes the result from acpi_ut_trim_function_name().

Quoted 8 lines
Quoted 8 lines
include/acpi/acpixf.h +0 -0
index 9f4637e9dd92..9644cec5b082 100644
@@ -946,7 +946,7 @@ ACPI_DBG_DEPENDENT_RETURN_VOID(ACPI_PRINTF_LIKE(6) __nocapture(3)
                                                const char *module_name,
                                                u32 component_id,
                                                const char *format, ...))
Quoted 8 lines

include/acpi/acpixf.h ACPI_DBG_DEPENDENT_RETURN_VOID(ACPI_PRINTF_LIKE(6) __nocapture(3) · line 952

Quoted 5 lines
include/acpi/acpixf.h +1 -1
-ACPI_DBG_DEPENDENT_RETURN_VOID(ACPI_PRINTF_LIKE(6)
+ACPI_DBG_DEPENDENT_RETURN_VOID(ACPI_PRINTF_LIKE(6) __nocapture(3)
                                void ACPI_INTERNAL_VAR_XFACE
                                acpi_debug_print_raw(u32 requested_debug_level,
                                                     u32 line_number,

I wonder why the plugin needs this at all: function_name (the third arg) isn't even used in the function.

This one wasn't needed, I should probably have left it out. It just seemed right for consistency to do the same for acpi_debug_print_raw() and acpi_debug_print().

Quoted 4 lines
Quoted 4 lines
include/linux/string.h +0 -0
index 8b3b97e7b2b0..0ee877593464 100644
Quoted 8 lines

include/linux/string.h static inline __must_check char *strstrip(char *str) · line 79

Quoted 6 lines
include/linux/string.h +1 -1
@@ -76,7 +76,7 @@ static inline __must_check char *strstrip(char *str)
 extern char * strstr(const char *, const char *) __nocapture(-1, 2);
 #endif
 #ifndef __HAVE_ARCH_STRNSTR
-extern char * strnstr(const char *, const char *, size_t) __nocapture(-1, 2);
+extern char * strnstr(const char *, const char *, size_t);

That doesn't seem right: strnstr doesn't capture...

Right, so better __unverified_nocapture() then?

Quoted 11 lines
Quoted 11 lines
include/linux/string.h +0 -0
 #endif
 #ifndef __HAVE_ARCH_STRLEN
 extern __kernel_size_t strlen(const char *) __nocapture(1);
lib/string.c +0 -0
index ed83562a53ae..01151a1a0b61 100644
@@ -870,7 +870,7 @@ void *memchr(const void *s, int c, size_t n)
 EXPORT_SYMBOL(memchr);
 #endif
 
Quoted 4 lines

lib/string.c void *memchr(const void *s, int c, size_t n) · line 873

Quoted 2 lines
lib/string.c +1 -1
-static void *check_bytes8(const u8 *start, u8 value, unsigned int bytes)
+static __always_inline void *check_bytes8(const u8 *start, u8 value, unsigned int bytes)

Is this from another fix? Seems unrelated?

This fixed a warning about memchr_inv() for me: when check_bytes8() is inlined, the compiler can see that the argument is not captured, but if gcc decides against inlining, it warns.

Quoted 16 lines
Quoted 16 lines
mm/kasan/kasan.c +1 -1
index 5f6e09c88d25..ebc02ee1118e 100644
@@ -343,7 +343,7 @@ void *memset(void *addr, int c, size_t len)
 }
 
 #undef memmove
-void *memmove(void *dest, const void *src, size_t len)
+__unverified_nocapture(2) void *memmove(void *dest, const void *src, size_t len)
 {
        check_memory_region((unsigned long)src, len, false, _RET_IP_);
        check_memory_region((unsigned long)dest, len, true, _RET_IP_);
@@ -352,7 +352,7 @@ void *memmove(void *dest, const void *src, size_t len)
 }
 
Quoted 12 lines
Quoted 9 lines
mm/kasan/kasan.c +1 -2
 #undef memcpy
-void *memcpy(void *dest, const void *src, size_t len)
+__unverified_nocapture(2) void *memcpy(void *dest, const void *src, size_t len)
 {
        check_memory_region((unsigned long)src, len, false, _RET_IP_);
        check_memory_region((unsigned long)dest, len, true, _RET_IP_);
--

2.9.0

Thanks for the patch! I'll try to reproduce the warnings and get some fixes built if Emese or PaX Team don't beat me to it. :)

I later got more warnings for some of the string functions, but we can deal with them
separately.

Arnd

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>