When building with Clang we encounter the following warning
(ARCH=hexagon + CONFIG_FRAME_WARN=0):
| ../drivers/misc/lkdtm/bugs.c:107:3: error: format specifies type
| 'unsigned long' but the argument has type 'int' [-Werror,-Wformat]
| REC_STACK_SIZE, recur_count);
| ^~~~~~~~~~~~~~
Cast REC_STACK_SIZE to `unsigned long` to match format specifier `%lu`
as well as maintain symmetry with `#define REC_STACK_SIZE
(_AC(CONFIG_FRAME_WARN, UL) / 2)`.
Link: https://github.com/ClangBuiltLinux/linux/issues/378
Reported-by: Nathan Chancellor <[email protected]>
Suggested-by: Nathan Chancellor <[email protected]>
Suggested-by: Nick Desaulniers <[email protected]>
Signed-off-by: Justin Stitt <[email protected]>
---
Reported by Nathan here:
https://lore.kernel.org/all/[email protected]/
changes from v1 -> v2:
* Use implicit division conversion with `/ nUL` instead of verbose
`(unsigned long)` ~ Thanks Nick
drivers/misc/lkdtm/bugs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c
index 009239ad1d8a..48821f4c2b21 100644
--- a/drivers/misc/lkdtm/bugs.c
+++ b/drivers/misc/lkdtm/bugs.c
@@ -29,7 +29,7 @@ struct lkdtm_list {
#if defined(CONFIG_FRAME_WARN) && (CONFIG_FRAME_WARN > 0)
#define REC_STACK_SIZE (_AC(CONFIG_FRAME_WARN, UL) / 2)
#else
-#define REC_STACK_SIZE (THREAD_SIZE / 8)
+#define REC_STACK_SIZE (THREAD_SIZE / 8UL)
#endif
#define REC_NUM_DEFAULT ((THREAD_SIZE / REC_STACK_SIZE) * 2)
--
2.37.1.359.gd136c6c3e2-goog
On Thu, Jul 21, 2022 at 02:57:06PM -0700, Justin Stitt wrote:
> When building with Clang we encounter the following warning
> (ARCH=hexagon + CONFIG_FRAME_WARN=0):
> | ../drivers/misc/lkdtm/bugs.c:107:3: error: format specifies type
> | 'unsigned long' but the argument has type 'int' [-Werror,-Wformat]
> | REC_STACK_SIZE, recur_count);
> | ^~~~~~~~~~~~~~
>
> Cast REC_STACK_SIZE to `unsigned long` to match format specifier `%lu`
> as well as maintain symmetry with `#define REC_STACK_SIZE
> (_AC(CONFIG_FRAME_WARN, UL) / 2)`.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/378
> Reported-by: Nathan Chancellor <[email protected]>
> Suggested-by: Nathan Chancellor <[email protected]>
Personally, I would drop this; my suggestion was the cast, which we are
not going with anymore. Not worth a v3 unless there are other changes
requested.
> Suggested-by: Nick Desaulniers <[email protected]>
> Signed-off-by: Justin Stitt <[email protected]>
Reviewed-by: Nathan Chancellor <[email protected]>
Tested-by: Nathan Chancellor <[email protected]>
> ---
> Reported by Nathan here:
> https://lore.kernel.org/all/[email protected]/
>
> changes from v1 -> v2:
> * Use implicit division conversion with `/ nUL` instead of verbose
> `(unsigned long)` ~ Thanks Nick
>
> drivers/misc/lkdtm/bugs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c
> index 009239ad1d8a..48821f4c2b21 100644
> --- a/drivers/misc/lkdtm/bugs.c
> +++ b/drivers/misc/lkdtm/bugs.c
> @@ -29,7 +29,7 @@ struct lkdtm_list {
> #if defined(CONFIG_FRAME_WARN) && (CONFIG_FRAME_WARN > 0)
> #define REC_STACK_SIZE (_AC(CONFIG_FRAME_WARN, UL) / 2)
> #else
> -#define REC_STACK_SIZE (THREAD_SIZE / 8)
> +#define REC_STACK_SIZE (THREAD_SIZE / 8UL)
> #endif
> #define REC_NUM_DEFAULT ((THREAD_SIZE / REC_STACK_SIZE) * 2)
>
> --
> 2.37.1.359.gd136c6c3e2-goog
>
>
On July 21, 2022 2:57:06 PM PDT, Justin Stitt <[email protected]> wrote:
>When building with Clang we encounter the following warning
>(ARCH=hexagon + CONFIG_FRAME_WARN=0):
>| ../drivers/misc/lkdtm/bugs.c:107:3: error: format specifies type
>| 'unsigned long' but the argument has type 'int' [-Werror,-Wformat]
>| REC_STACK_SIZE, recur_count);
>| ^~~~~~~~~~~~~~
>
>Cast REC_STACK_SIZE to `unsigned long` to match format specifier `%lu`
>as well as maintain symmetry with `#define REC_STACK_SIZE
>(_AC(CONFIG_FRAME_WARN, UL) / 2)`.
>
>Link: https://github.com/ClangBuiltLinux/linux/issues/378
>Reported-by: Nathan Chancellor <[email protected]>
>Suggested-by: Nathan Chancellor <[email protected]>
>Suggested-by: Nick Desaulniers <[email protected]>
>Signed-off-by: Justin Stitt <[email protected]>
Thanks!
Acked-by: Kees Cook <[email protected]>
Fixes: 24cccab42c419 ("lkdtm/bugs: Adjust recursion test to avoid elision")
--
Kees Cook