* [PATCH] lkdtm/bugs: In lkdtm_HUNG_TASK() use BUG(), not BUG_ON(1)
@ 2024-01-26 15:28 Douglas Anderson
2024-01-26 15:58 ` Doug Anderson
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Douglas Anderson @ 2024-01-26 15:28 UTC (permalink / raw)
To: Kees Cook
Cc: Douglas Anderson, Arnd Bergmann, Greg Kroah-Hartman, linux-kernel
In commit edb6538da3df ("lkdtm/bugs: Adjust lkdtm_HUNG_TASK() to avoid
tail call optimization") we marked lkdtm_HUNG_TASK() as
__noreturn. The compiler gets unhappy if it thinks a __noreturn
function might return, so there's a BUG_ON(1) at the end. Any human
can see that the function won't return and the compiler can figure
that out too. Except when it can't.
The MIPS architecture defines HAVE_ARCH_BUG_ON and defines its own
version of BUG_ON(). The MIPS version of BUG_ON() is not a macro but
is instead an inline function. Apparently this prevents the compiler
from realizing that the condition to BUG_ON() is constant and that the
function will never return.
Let's change the BUG_ON(1) to just BUG(), which it should have been to
begin with. The only reason I used BUG_ON(1) to begin with was because
I was used to using WARN_ON(1) when writing test code and WARN() and
BUG() are oddly inconsistent in this manner. :-/
Fixes: edb6538da3df ("lkdtm/bugs: Adjust lkdtm_HUNG_TASK() to avoid tail call optimization")
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---
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 d1222d3eda2f..b92767d6bdd2 100644
--- a/drivers/misc/lkdtm/bugs.c
+++ b/drivers/misc/lkdtm/bugs.c
@@ -298,7 +298,7 @@ static void __noreturn lkdtm_HUNG_TASK(void)
{
set_current_state(TASK_UNINTERRUPTIBLE);
schedule();
- BUG_ON(1);
+ BUG();
}
static volatile unsigned int huge = INT_MAX - 2;
--
2.43.0.429.g432eaa2c6b-goog
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] lkdtm/bugs: In lkdtm_HUNG_TASK() use BUG(), not BUG_ON(1)
2024-01-26 15:28 [PATCH] lkdtm/bugs: In lkdtm_HUNG_TASK() use BUG(), not BUG_ON(1) Douglas Anderson
@ 2024-01-26 15:58 ` Doug Anderson
2024-01-26 16:08 ` Arnd Bergmann
2024-01-26 18:30 ` Kees Cook
2 siblings, 0 replies; 4+ messages in thread
From: Doug Anderson @ 2024-01-26 15:58 UTC (permalink / raw)
To: Kees Cook; +Cc: Arnd Bergmann, Greg Kroah-Hartman, linux-kernel
Hi,
On Fri, Jan 26, 2024 at 7:29 AM Douglas Anderson <dianders@chromium.org> wrote:
>
> In commit edb6538da3df ("lkdtm/bugs: Adjust lkdtm_HUNG_TASK() to avoid
> tail call optimization") we marked lkdtm_HUNG_TASK() as
> __noreturn. The compiler gets unhappy if it thinks a __noreturn
> function might return, so there's a BUG_ON(1) at the end. Any human
> can see that the function won't return and the compiler can figure
> that out too. Except when it can't.
>
> The MIPS architecture defines HAVE_ARCH_BUG_ON and defines its own
> version of BUG_ON(). The MIPS version of BUG_ON() is not a macro but
> is instead an inline function. Apparently this prevents the compiler
> from realizing that the condition to BUG_ON() is constant and that the
> function will never return.
>
> Let's change the BUG_ON(1) to just BUG(), which it should have been to
> begin with. The only reason I used BUG_ON(1) to begin with was because
> I was used to using WARN_ON(1) when writing test code and WARN() and
> BUG() are oddly inconsistent in this manner. :-/
>
> Fixes: edb6538da3df ("lkdtm/bugs: Adjust lkdtm_HUNG_TASK() to avoid tail call optimization")
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> ---
>
> drivers/misc/lkdtm/bugs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Ugh. I just realized I forgot these. Kees: hopefully you can add them...
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202401262204.wUFKRYZF-lkp@intel.com/
-Doug
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] lkdtm/bugs: In lkdtm_HUNG_TASK() use BUG(), not BUG_ON(1)
2024-01-26 15:28 [PATCH] lkdtm/bugs: In lkdtm_HUNG_TASK() use BUG(), not BUG_ON(1) Douglas Anderson
2024-01-26 15:58 ` Doug Anderson
@ 2024-01-26 16:08 ` Arnd Bergmann
2024-01-26 18:30 ` Kees Cook
2 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2024-01-26 16:08 UTC (permalink / raw)
To: Doug Anderson, Kees Cook; +Cc: Greg Kroah-Hartman, linux-kernel
On Fri, Jan 26, 2024, at 16:28, Douglas Anderson wrote:
> In commit edb6538da3df ("lkdtm/bugs: Adjust lkdtm_HUNG_TASK() to avoid
> tail call optimization") we marked lkdtm_HUNG_TASK() as
> __noreturn. The compiler gets unhappy if it thinks a __noreturn
> function might return, so there's a BUG_ON(1) at the end. Any human
> can see that the function won't return and the compiler can figure
> that out too. Except when it can't.
>
> The MIPS architecture defines HAVE_ARCH_BUG_ON and defines its own
> version of BUG_ON(). The MIPS version of BUG_ON() is not a macro but
> is instead an inline function. Apparently this prevents the compiler
> from realizing that the condition to BUG_ON() is constant and that the
> function will never return.
>
> Let's change the BUG_ON(1) to just BUG(), which it should have been to
> begin with. The only reason I used BUG_ON(1) to begin with was because
> I was used to using WARN_ON(1) when writing test code and WARN() and
> BUG() are oddly inconsistent in this manner. :-/
>
> Fixes: edb6538da3df ("lkdtm/bugs: Adjust lkdtm_HUNG_TASK() to avoid
> tail call optimization")
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> ---
Acked-by: Arnd Bergmann <arnd@arndb.de>
> schedule();
> - BUG_ON(1);
> + BUG();
> }
Yes, this is a common problem that I've fixed in other
places before.
Arnd
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] lkdtm/bugs: In lkdtm_HUNG_TASK() use BUG(), not BUG_ON(1)
2024-01-26 15:28 [PATCH] lkdtm/bugs: In lkdtm_HUNG_TASK() use BUG(), not BUG_ON(1) Douglas Anderson
2024-01-26 15:58 ` Doug Anderson
2024-01-26 16:08 ` Arnd Bergmann
@ 2024-01-26 18:30 ` Kees Cook
2 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2024-01-26 18:30 UTC (permalink / raw)
To: Douglas Anderson
Cc: Kees Cook, Arnd Bergmann, Greg Kroah-Hartman, linux-kernel
On Fri, 26 Jan 2024 07:28:53 -0800, Douglas Anderson wrote:
> In commit edb6538da3df ("lkdtm/bugs: Adjust lkdtm_HUNG_TASK() to avoid
> tail call optimization") we marked lkdtm_HUNG_TASK() as
> __noreturn. The compiler gets unhappy if it thinks a __noreturn
> function might return, so there's a BUG_ON(1) at the end. Any human
> can see that the function won't return and the compiler can figure
> that out too. Except when it can't.
>
> [...]
Applied to for-next/hardening, thanks!
[1/1] lkdtm/bugs: In lkdtm_HUNG_TASK() use BUG(), not BUG_ON(1)
https://git.kernel.org/kees/c/34b82a2fb747
Take care,
--
Kees Cook
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-01-26 18:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-26 15:28 [PATCH] lkdtm/bugs: In lkdtm_HUNG_TASK() use BUG(), not BUG_ON(1) Douglas Anderson
2024-01-26 15:58 ` Doug Anderson
2024-01-26 16:08 ` Arnd Bergmann
2024-01-26 18:30 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®