Skip to content

Commit cb7380d

Browse files
committed
compiler.h: Move C string helpers into C-only kernel section
The C kernel helpers for evaluating C Strings were positioned where they were visible to assembly inclusion, which was not intended. Move them into the kernel and C-only area of the header so future changes won't confuse the assembler. Fixes: d7a516c ("compiler.h: Fix undefined BUILD_BUG_ON_ZERO()") Fixes: 559048d ("string: Check for "nonstring" attribute on strscpy() arguments") Reviewed-by: Miguel Ojeda <[email protected]> Signed-off-by: Kees Cook <[email protected]>
1 parent 78bba60 commit cb7380d

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

include/linux/compiler.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,19 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
214214
__v; \
215215
})
216216

217+
#ifdef __CHECKER__
218+
#define __BUILD_BUG_ON_ZERO_MSG(e, msg) (0)
219+
#else /* __CHECKER__ */
220+
#define __BUILD_BUG_ON_ZERO_MSG(e, msg) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
221+
#endif /* __CHECKER__ */
222+
223+
/* &a[0] degrades to a pointer: a different type from an array */
224+
#define __must_be_array(a) __BUILD_BUG_ON_ZERO_MSG(__same_type((a), &(a)[0]), "must be array")
225+
226+
/* Require C Strings (i.e. NUL-terminated) lack the "nonstring" attribute. */
227+
#define __must_be_cstr(p) \
228+
__BUILD_BUG_ON_ZERO_MSG(__annotated(p, nonstring), "must be cstr (NUL-terminated)")
229+
217230
#endif /* __KERNEL__ */
218231

219232
/**
@@ -254,19 +267,6 @@ static inline void *offset_to_ptr(const int *off)
254267

255268
#define __ADDRESSABLE_ASM_STR(sym) __stringify(__ADDRESSABLE_ASM(sym))
256269

257-
#ifdef __CHECKER__
258-
#define __BUILD_BUG_ON_ZERO_MSG(e, msg) (0)
259-
#else /* __CHECKER__ */
260-
#define __BUILD_BUG_ON_ZERO_MSG(e, msg) ((int)sizeof(struct {_Static_assert(!(e), msg);}))
261-
#endif /* __CHECKER__ */
262-
263-
/* &a[0] degrades to a pointer: a different type from an array */
264-
#define __must_be_array(a) __BUILD_BUG_ON_ZERO_MSG(__same_type((a), &(a)[0]), "must be array")
265-
266-
/* Require C Strings (i.e. NUL-terminated) lack the "nonstring" attribute. */
267-
#define __must_be_cstr(p) \
268-
__BUILD_BUG_ON_ZERO_MSG(__annotated(p, nonstring), "must be cstr (NUL-terminated)")
269-
270270
/*
271271
* This returns a constant expression while determining if an argument is
272272
* a constant expression, most importantly without evaluating the argument.

0 commit comments

Comments
 (0)