All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/hw_breakpoints: Return -EINVAL in default case in hw_breakpoint_arch_parse
@ 2019-03-07 21:27 Nathan Chancellor
  2019-03-08  0:53 ` Nick Desaulniers
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nathan Chancellor @ 2019-03-07 21:27 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov
  Cc: H. Peter Anvin, x86, linux-kernel, clang-built-linux,
	Nick Desaulniers, Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

arch/x86/kernel/hw_breakpoint.c:355:2: warning: variable 'align' is used
uninitialized whenever switch default is taken
[-Wsometimes-uninitialized]

It's not wrong but we can see that arch_build_bp_info will only ever
initialize hw->len to one of the specified switch cases. We can easily
silence Clang by just returning -EINVAL in the default case so that we
can never use align without initializing it first.

Link: https://github.com/ClangBuiltLinux/linux/issues/392
Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
 arch/x86/kernel/hw_breakpoint.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c
index ff9bfd40429e..d73083021002 100644
--- a/arch/x86/kernel/hw_breakpoint.c
+++ b/arch/x86/kernel/hw_breakpoint.c
@@ -354,6 +354,7 @@ int hw_breakpoint_arch_parse(struct perf_event *bp,
 #endif
 	default:
 		WARN_ON_ONCE(1);
+		return -EINVAL;
 	}
 
 	/*
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/hw_breakpoints: Return -EINVAL in default case in hw_breakpoint_arch_parse
  2019-03-07 21:27 [PATCH] x86/hw_breakpoints: Return -EINVAL in default case in hw_breakpoint_arch_parse Nathan Chancellor
@ 2019-03-08  0:53 ` Nick Desaulniers
  2019-03-20 19:10 ` Nathan Chancellor
  2019-03-22 16:13 ` [tip:x86/urgent] x86/hw_breakpoints: Make default case in hw_breakpoint_arch_parse() return an error tip-bot for Nathan Chancellor
  2 siblings, 0 replies; 4+ messages in thread
From: Nick Desaulniers @ 2019-03-08  0:53 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin,
	x86, LKML, clang-built-linux

On Thu, Mar 7, 2019 at 1:28 PM Nathan Chancellor
<natechancellor@gmail.com> wrote:
>
> When building with -Wsometimes-uninitialized, Clang warns:
>
> arch/x86/kernel/hw_breakpoint.c:355:2: warning: variable 'align' is used
> uninitialized whenever switch default is taken
> [-Wsometimes-uninitialized]
>
> It's not wrong but we can see that arch_build_bp_info will only ever
> initialize hw->len to one of the specified switch cases. We can easily
> silence Clang by just returning -EINVAL in the default case so that we
> can never use align without initializing it first.

And the call site just bubbles up return codes anyways.  Thanks for sending.
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

>
> Link: https://github.com/ClangBuiltLinux/linux/issues/392
> Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> ---
>  arch/x86/kernel/hw_breakpoint.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c
> index ff9bfd40429e..d73083021002 100644
> --- a/arch/x86/kernel/hw_breakpoint.c
> +++ b/arch/x86/kernel/hw_breakpoint.c
> @@ -354,6 +354,7 @@ int hw_breakpoint_arch_parse(struct perf_event *bp,
>  #endif
>         default:
>                 WARN_ON_ONCE(1);
> +               return -EINVAL;
>         }
>
>         /*
> --
> 2.21.0
>


-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/hw_breakpoints: Return -EINVAL in default case in hw_breakpoint_arch_parse
  2019-03-07 21:27 [PATCH] x86/hw_breakpoints: Return -EINVAL in default case in hw_breakpoint_arch_parse Nathan Chancellor
  2019-03-08  0:53 ` Nick Desaulniers
@ 2019-03-20 19:10 ` Nathan Chancellor
  2019-03-22 16:13 ` [tip:x86/urgent] x86/hw_breakpoints: Make default case in hw_breakpoint_arch_parse() return an error tip-bot for Nathan Chancellor
  2 siblings, 0 replies; 4+ messages in thread
From: Nathan Chancellor @ 2019-03-20 19:10 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov
  Cc: H. Peter Anvin, x86, linux-kernel, clang-built-linux, Nick Desaulniers

On Thu, Mar 07, 2019 at 02:27:56PM -0700, Nathan Chancellor wrote:
> When building with -Wsometimes-uninitialized, Clang warns:
> 
> arch/x86/kernel/hw_breakpoint.c:355:2: warning: variable 'align' is used
> uninitialized whenever switch default is taken
> [-Wsometimes-uninitialized]
> 
> It's not wrong but we can see that arch_build_bp_info will only ever
> initialize hw->len to one of the specified switch cases. We can easily
> silence Clang by just returning -EINVAL in the default case so that we
> can never use align without initializing it first.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/392
> Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
> ---
>  arch/x86/kernel/hw_breakpoint.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c
> index ff9bfd40429e..d73083021002 100644
> --- a/arch/x86/kernel/hw_breakpoint.c
> +++ b/arch/x86/kernel/hw_breakpoint.c
> @@ -354,6 +354,7 @@ int hw_breakpoint_arch_parse(struct perf_event *bp,
>  #endif
>  	default:
>  		WARN_ON_ONCE(1);
> +		return -EINVAL;
>  	}
>  
>  	/*
> -- 
> 2.21.0
> 

Gentle ping (if there was a response to this, I didn't receive it). I
know I sent it in the middle of a merge window so I get if it slipped
through the cracks.

Thanks,
Nathan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [tip:x86/urgent] x86/hw_breakpoints: Make default case in hw_breakpoint_arch_parse() return an error
  2019-03-07 21:27 [PATCH] x86/hw_breakpoints: Return -EINVAL in default case in hw_breakpoint_arch_parse Nathan Chancellor
  2019-03-08  0:53 ` Nick Desaulniers
  2019-03-20 19:10 ` Nathan Chancellor
@ 2019-03-22 16:13 ` tip-bot for Nathan Chancellor
  2 siblings, 0 replies; 4+ messages in thread
From: tip-bot for Nathan Chancellor @ 2019-03-22 16:13 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: ndesaulniers, linux-kernel, mingo, tglx, bp, hpa, natechancellor

Commit-ID:  e898e69d6b9475bf123f99b3c5d1a67bb7cb2361
Gitweb:     https://git.kernel.org/tip/e898e69d6b9475bf123f99b3c5d1a67bb7cb2361
Author:     Nathan Chancellor <natechancellor@gmail.com>
AuthorDate: Thu, 7 Mar 2019 14:27:56 -0700
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Fri, 22 Mar 2019 17:08:17 +0100

x86/hw_breakpoints: Make default case in hw_breakpoint_arch_parse() return an error

When building with -Wsometimes-uninitialized, Clang warns:

arch/x86/kernel/hw_breakpoint.c:355:2: warning: variable 'align' is used
uninitialized whenever switch default is taken
[-Wsometimes-uninitialized]

The default cannot be reached because arch_build_bp_info() initializes
hw->len to one of the specified cases. Nevertheless the warning is valid
and returning -EINVAL makes sure that this cannot be broken by future
modifications.

Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: clang-built-linux@googlegroups.com
Link: https://github.com/ClangBuiltLinux/linux/issues/392
Link: https://lkml.kernel.org/r/20190307212756.4648-1-natechancellor@gmail.com

---
 arch/x86/kernel/hw_breakpoint.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c
index ff9bfd40429e..d73083021002 100644
--- a/arch/x86/kernel/hw_breakpoint.c
+++ b/arch/x86/kernel/hw_breakpoint.c
@@ -354,6 +354,7 @@ int hw_breakpoint_arch_parse(struct perf_event *bp,
 #endif
 	default:
 		WARN_ON_ONCE(1);
+		return -EINVAL;
 	}
 
 	/*

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-03-22 16:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-07 21:27 [PATCH] x86/hw_breakpoints: Return -EINVAL in default case in hw_breakpoint_arch_parse Nathan Chancellor
2019-03-08  0:53 ` Nick Desaulniers
2019-03-20 19:10 ` Nathan Chancellor
2019-03-22 16:13 ` [tip:x86/urgent] x86/hw_breakpoints: Make default case in hw_breakpoint_arch_parse() return an error tip-bot for Nathan Chancellor

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.