public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] objtool: check: Fix NULL pointer dereference
@ 2020-03-31  0:20 Gustavo A. R. Silva
  2020-03-31 22:04 ` Josh Poimboeuf
  0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2020-03-31  0:20 UTC (permalink / raw)
  To: Josh Poimboeuf, Peter Zijlstra; +Cc: linux-kernel, Gustavo A. R. Silva

In case func is null, there is a null pointer dereference at 2029:

2029                 WARN("%s uses BP as a scratch register",
2030                      func->name);

Fix this by null-checking func.

Addresses-Coverity-ID: 1492002 ("Dereference after null check")
Fixes: c705cecc8431 ("objtool: Track original function across branches")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 tools/objtool/check.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index e3bb76358148..182cc48fa892 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2025,7 +2025,7 @@ static int validate_return(struct symbol *func, struct instruction *insn, struct
 		return 1;
 	}
 
-	if (state->bp_scratch) {
+	if (func && state->bp_scratch) {
 		WARN("%s uses BP as a scratch register",
 		     func->name);
 		return 1;
-- 
2.26.0


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

* Re: [PATCH] objtool: check: Fix NULL pointer dereference
  2020-03-31  0:20 [PATCH] objtool: check: Fix NULL pointer dereference Gustavo A. R. Silva
@ 2020-03-31 22:04 ` Josh Poimboeuf
  2020-03-31 22:27   ` Gustavo A. R. Silva
  0 siblings, 1 reply; 3+ messages in thread
From: Josh Poimboeuf @ 2020-03-31 22:04 UTC (permalink / raw)
  To: Gustavo A. R. Silva; +Cc: Peter Zijlstra, linux-kernel

On Mon, Mar 30, 2020 at 07:20:40PM -0500, Gustavo A. R. Silva wrote:
> In case func is null, there is a null pointer dereference at 2029:
> 
> 2029                 WARN("%s uses BP as a scratch register",
> 2030                      func->name);
> 
> Fix this by null-checking func.
> 
> Addresses-Coverity-ID: 1492002 ("Dereference after null check")
> Fixes: c705cecc8431 ("objtool: Track original function across branches")
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>  tools/objtool/check.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index e3bb76358148..182cc48fa892 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -2025,7 +2025,7 @@ static int validate_return(struct symbol *func, struct instruction *insn, struct
>  		return 1;
>  	}
>  
> -	if (state->bp_scratch) {
> +	if (func && state->bp_scratch) {
>  		WARN("%s uses BP as a scratch register",
>  		     func->name);
>  		return 1;

We should still do the warning even if there's no func.  I'll make a
slightly different patch which unconditionally uses WARN_FUNC().

I'll give you Reported-by credit and keep the coverity tag.  Thanks!

-- 
Josh


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

* Re: [PATCH] objtool: check: Fix NULL pointer dereference
  2020-03-31 22:04 ` Josh Poimboeuf
@ 2020-03-31 22:27   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2020-03-31 22:27 UTC (permalink / raw)
  To: Josh Poimboeuf; +Cc: Peter Zijlstra, linux-kernel



On 3/31/20 17:04, Josh Poimboeuf wrote:
> On Mon, Mar 30, 2020 at 07:20:40PM -0500, Gustavo A. R. Silva wrote:
>> In case func is null, there is a null pointer dereference at 2029:
>>
>> 2029                 WARN("%s uses BP as a scratch register",
>> 2030                      func->name);
>>
>> Fix this by null-checking func.
>>
>> Addresses-Coverity-ID: 1492002 ("Dereference after null check")
>> Fixes: c705cecc8431 ("objtool: Track original function across branches")
>> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
>> ---
>>  tools/objtool/check.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
>> index e3bb76358148..182cc48fa892 100644
>> --- a/tools/objtool/check.c
>> +++ b/tools/objtool/check.c
>> @@ -2025,7 +2025,7 @@ static int validate_return(struct symbol *func, struct instruction *insn, struct
>>  		return 1;
>>  	}
>>  
>> -	if (state->bp_scratch) {
>> +	if (func && state->bp_scratch) {
>>  		WARN("%s uses BP as a scratch register",
>>  		     func->name);
>>  		return 1;
> 
> We should still do the warning even if there's no func.  I'll make a
> slightly different patch which unconditionally uses WARN_FUNC().
> 

Awesome. :)

> I'll give you Reported-by credit and keep the coverity tag.  Thanks!
> 

Great.

Thanks
--
Gustavo

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

end of thread, other threads:[~2020-03-31 22:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-31  0:20 [PATCH] objtool: check: Fix NULL pointer dereference Gustavo A. R. Silva
2020-03-31 22:04 ` Josh Poimboeuf
2020-03-31 22:27   ` Gustavo A. R. Silva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox