mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Roman Zippel <zippel@linux-m68k.org>,
	Andreas Schwab <schwab@suse.de>,
	LKML <linux-kernel@vger.kernel.org>,
	Linux/m68k <linux-m68k@vger.kernel.org>
Subject: Re: [PATCH] init - fix building bug and potential buffer overflow
Date: Thu, 15 May 2008 21:47:26 +0200 (CEST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0805152132530.22059@anakin> (raw)
In-Reply-To: <20080515180528.GC7481@cvg>

On Thu, 15 May 2008, Cyrill Gorcunov wrote:
> [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

gcc turns the strncat() into an implicit call to strlen() and some form
of expanded memcpy(). E.g.


	if (preempt_count() != count) {
		strncat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
		preempt_count() = count;
	}

becomes

        cmp.l 884(%a2),%d6      | <variable>.thread.info.preempt_count, count
        jeq .L61        |
        move.l %d7,-(%sp)       | tmp76,
        jbsr strlen     |
        addq.l #4,%sp   |,
        move.l %d7,%a0  | tmp76, tmp80
        add.l %d0,%a0   |, tmp80
        move.l #1886545253,(%a0)+       |,
        move.l #1836086377,(%a0)+       |,
        move.l #1869488233,(%a0)+       |,
        move.l #1835164012,(%a0)+       |,
        move.l #1634624357,(%a0)+       |,
        move.w #8192,(%a0)      |,* D.28541
        move.l %d6,884(%a2)     | count, <variable>.thread.info.preempt_count
.L61:

All other explicit calls to strlen() are inlined, as per
include/asm-m68k/string.h.

> strlcat there but it seems it would fail to build too. Originally I've messed
> strlcat with strncat :(

Actually it build and runs fine after s/strncat/strlcat/...

Gr{oetje,eeting}s,

						Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
							    -- Linus Torvalds

  reply	other threads:[~2008-05-15 19:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-14 15:44 Cyrill Gorcunov
2008-05-15 17:58 ` Andrew Morton
2008-05-15 18:05   ` Cyrill Gorcunov
2008-05-15 19:47     ` Geert Uytterhoeven [this message]
2008-05-15 20:22       ` Cyrill Gorcunov
2008-05-15 20:49         ` Andrew Morton
2008-05-15 21:15           ` Linus Torvalds
2008-05-15 21:45             ` Andrew Morton
2008-05-15 23:41               ` [PATCH] Add a void * alternative to print_fn_descriptor_symbol() Abhijit Menon-Sen
2008-05-16  1:47               ` [PATCH] init - fix building bug and potential buffer overflow Linus Torvalds
2008-05-15 22:44             ` Rene Herman
2008-05-16  3:29           ` Cyrill Gorcunov
2008-05-16  4:17             ` Cyrill Gorcunov
2008-05-16  7:00           ` Geert Uytterhoeven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0805152132530.22059@anakin \
    --to=geert@linux-m68k.org \
    --cc=akpm@linux-foundation.org \
    --cc=gorcunov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@vger.kernel.org \
    --cc=schwab@suse.de \
    --cc=torvalds@linux-foundation.org \
    --cc=zippel@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®