Re: [PATCH] init - fix building bug and potential buffer overflow

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Cyrill Gorcunov
Date: Thursday, May 15, 2008 - 11:05 am

[Andrew Morton - Thu, May 15, 2008 at 10:58:03AM -0700]
| On Wed, 14 May 2008 19:44:02 +0400 Cyrill Gorcunov <gorcunov@gmail.com> wrote:
| 
| > This patch does fix build bug on m68k wich does not have strncat in straight way.
| > 
| > What is more important - my previous patch
| > 
| > commit e662e1cfd434aa234b72fbc781f1d70211cb785b
| > Author: Cyrill Gorcunov <gorcunov@gmail.com>
| > Date:   Mon May 12 14:02:22 2008 -0700
| > 
| >     init: don't lose initcall return values
| > 
| > has introduced potential buffer overflow by wrong calculation
| > of string accumulator size.
| > 
| > Many thanks Andreas Schwab and Geert Uytterhoeven for helping
| > to catch and fix the bug.
| > 
| > Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
| > ---
| > 
| > Index: linux-2.6.git/init/main.c
| > ===================================================================
| > --- linux-2.6.git.orig/init/main.c	2008-05-14 17:55:10.000000000 +0400
| > +++ linux-2.6.git/init/main.c	2008-05-14 19:11:18.000000000 +0400
| > @@ -702,7 +702,7 @@ static void __init do_initcalls(void)
| >  
| >  	for (call = __initcall_start; call < __initcall_end; call++) {
| >  		ktime_t t0, t1, delta;
| > -		char msgbuf[40];
| > +		char msgbuf[64];
| >  		int result;
| >  
| >  		if (initcall_debug) {
| > @@ -729,11 +729,11 @@ static void __init do_initcalls(void)
| >  			sprintf(msgbuf, "error code %d ", result);
| >  
| >  		if (preempt_count() != count) {
| > -			strncat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
| > +			strcat(msgbuf, "preemption imbalance ");
| >  			preempt_count() = count;
| >  		}
| >  		if (irqs_disabled()) {
| > -			strncat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
| > +			strcat(msgbuf, "disabled interrupts ");
| >  			local_irq_enable();
| >  		}
| >  		if (msgbuf[0]) {
| 
| umm, why can't m68k call strncat() from init/main.c??
| 

there some problem with headers iirc, we have to declare it first or
use some gcc option (as Adrian suggested). Actually I would prefer to use
strlcat there but it seems it would fail to build too. Originally I've messed
strlcat with strncat :(

		- Cyrill -
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH] init - fix building bug and potential buffer o ..., Cyrill Gorcunov, (Thu May 15, 11:05 am)
Re: [PATCH] init - fix building bug and potential buffer o ..., Geert Uytterhoeven, (Thu May 15, 12:47 pm)
[PATCH] Add a void * alternative to print_fn_descriptor_sy ..., Abhijit Menon-Sen, (Thu May 15, 4:41 pm)
Re: [PATCH] init - fix building bug and potential buffer o ..., Geert Uytterhoeven, (Fri May 16, 12:00 am)