diff mbox series

[v2,08/16] objtool: Fix SEGFAULT

Message ID 20220829055223.24767-9-sv@linux.ibm.com (mailing list archive)
State Superseded
Headers show
Series objtool: Enable and implement --mcount option on powerpc | expand

Commit Message

Sathvika Vasireddy Aug. 29, 2022, 5:52 a.m. UTC
From: Christophe Leroy <christophe.leroy@csgroup.eu>

find_insn() will return NULL in case of failure. Check insn in order
to avoid a kernel Oops for NULL pointer dereference.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 tools/objtool/check.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Peter Zijlstra Sept. 1, 2022, 7:20 p.m. UTC | #1
On Mon, Aug 29, 2022 at 11:22:15AM +0530, Sathvika Vasireddy wrote:
> From: Christophe Leroy <christophe.leroy@csgroup.eu>
> 
> find_insn() will return NULL in case of failure. Check insn in order
> to avoid a kernel Oops for NULL pointer dereference.
> 
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
>  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 91678252a9b6..ed2fdfeb1d9c 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -205,7 +205,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
>  		return false;
>  
>  	insn = find_insn(file, func->sec, func->offset);
> -	if (!insn->func)
> +	if (!insn || !insn->func)
>  		return false;

I suppose this is ok, but how can the lookup for func->sec, func->offset
*not* find an instruction ?!
Christophe Leroy Sept. 2, 2022, 8:06 a.m. UTC | #2
Le 01/09/2022 à 21:20, Peter Zijlstra a écrit :
> On Mon, Aug 29, 2022 at 11:22:15AM +0530, Sathvika Vasireddy wrote:
>> From: Christophe Leroy <christophe.leroy@csgroup.eu>
>>
>> find_insn() will return NULL in case of failure. Check insn in order
>> to avoid a kernel Oops for NULL pointer dereference.
>>
>> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
>> ---
>>   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 91678252a9b6..ed2fdfeb1d9c 100644
>> --- a/tools/objtool/check.c
>> +++ b/tools/objtool/check.c
>> @@ -205,7 +205,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
>>   		return false;
>>   
>>   	insn = find_insn(file, func->sec, func->offset);
>> -	if (!insn->func)
>> +	if (!insn || !insn->func)
>>   		return false;
> 
> I suppose this is ok, but how can the lookup for func->sec, func->offset
> *not* find an instruction ?!

That happened to me at the begining when the port to powerpc was not 
fully functionnal.

I guess that could also happen with a corrupted object file so better 
safe than sorry.
Peter Zijlstra Sept. 2, 2022, 8:42 a.m. UTC | #3
On Fri, Sep 02, 2022 at 08:06:28AM +0000, Christophe Leroy wrote:
> 
> 
> Le 01/09/2022 à 21:20, Peter Zijlstra a écrit :
> > On Mon, Aug 29, 2022 at 11:22:15AM +0530, Sathvika Vasireddy wrote:
> >> From: Christophe Leroy <christophe.leroy@csgroup.eu>
> >>
> >> find_insn() will return NULL in case of failure. Check insn in order
> >> to avoid a kernel Oops for NULL pointer dereference.
> >>
> >> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> >> ---
> >>   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 91678252a9b6..ed2fdfeb1d9c 100644
> >> --- a/tools/objtool/check.c
> >> +++ b/tools/objtool/check.c
> >> @@ -205,7 +205,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
> >>   		return false;
> >>   
> >>   	insn = find_insn(file, func->sec, func->offset);
> >> -	if (!insn->func)
> >> +	if (!insn || !insn->func)
> >>   		return false;
> > 
> > I suppose this is ok, but how can the lookup for func->sec, func->offset
> > *not* find an instruction ?!
> 
> That happened to me at the begining when the port to powerpc was not 
> fully functionnal.
> 
> I guess that could also happen with a corrupted object file so better 
> safe than sorry.

Fair enough.

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
diff mbox series

Patch

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 91678252a9b6..ed2fdfeb1d9c 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -205,7 +205,7 @@  static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
 		return false;
 
 	insn = find_insn(file, func->sec, func->offset);
-	if (!insn->func)
+	if (!insn || !insn->func)
 		return false;
 
 	func_for_each_insn(file, func, insn) {