From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Stephen Rothwell <sfr@canb.auug.org.au>,
Milan Broz <mbroz@redhat.com>, Alasdair G Kergon <agk@redhat.com>
Cc: linux-next@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>
Subject: dm_attr_{name,uuid}_show buffer overflow? (was: Re: linux-next: Tree for January 5)
Date: Mon, 5 Jan 2009 22:41:28 +0100 (CET) [thread overview]
Message-ID: <Pine.LNX.4.64.0901052225400.5451@anakin> (raw)
In-Reply-To: <20090105173517.deeff918.sfr@canb.auug.org.au>
On Mon, 5 Jan 2009, Stephen Rothwell wrote:
> Status of my local build tests will be at
> http://kisskb.ellerman.id.au/linux-next . If maintainers want to give
> advice about cross compilers/configs that work, we are always open to add
> more builds.
On m68k, you get http://kisskb.ellerman.id.au/kisskb/buildresult/65466/:
| ERROR: "strlen" [drivers/md/dm-mod.ko] undefined!
which triggered my attention.
drivers/md/dm-sysfs.c:
| static ssize_t dm_attr_name_show(struct mapped_device *md, char *buf)
| {
| if (dm_copy_name_and_uuid(md, buf, NULL))
| return -EIO;
|
| strncat(buf, "\n", DM_NAME_LEN);
| return strnlen(buf, DM_NAME_LEN);
| }
is turned into:
| .type dm_attr_name_show, @function
| dm_attr_name_show:
| move.l %a3,-(%sp)
| move.l 12(%sp),%a3 | buf, buf
| clr.l -(%sp) |
| move.l %a3,-(%sp) | buf,
| move.l 16(%sp),-(%sp) | md,
| jbsr dm_copy_name_and_uuid |
| lea (12,%sp),%sp |,
| tst.l %d0 |
| jeq .L23 |
| move.w #-5,%a0 |, D.21217
| jbra .L25 |
| .L23:
| move.l %a3,-(%sp) | buf,
| jbsr strlen |
| addq.l #4,%sp |,
| move.w #2560,(%a3,%d0.l) |,* buf
| moveq #127,%d0 |, tmp43
| not.b %d0 | tmp43
| move.l %a3,%a0 | buf, sc.399
| #APP
|
| 1: subq.l #1,%d0 | count
| jcs 2f
| tst.b (%a0)+ | sc.399
| jne 1b
| subq.l #1,%a0 | sc.399
| 2:
| #NO_APP
| sub.l %a3,%a0 | buf, D.21217
| .L25:
| move.l %a0,%d0 | D.21217, <result>
| move.l (%sp)+,%a3
| rts
| .size dm_attr_name_show, .-dm_attr_name_show
So gcc (version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) in my case) is
smart and turns the strncat into a strlen() (without obeying our override of
strlen() in <{linux,asm}/string.h>) followed by an _unconditional_ store.
And I think that's the real bug: `strncat(buf, "\n", DM_NAME_LEN);' copies at
most DM_NAME_LEN characters from source "\n", which has the known size 2,
which is always smaller than DM_NAME_LEN. Hence the check is optimized away,
and the "\n" is _always_ appended!
Probably the intention was to limit the string in _buf_ (not the source string
"\n") to DM_NAME_LEN? If yes, this may cause a buffer overflow.
The same bug is present in dm_attr_uuid_show().
Fixing it will probably get rid of the undefined reference, too (I hope :-)
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
next prev parent reply other threads:[~2009-01-05 21:41 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-05 6:35 linux-next: Tree for January 5 Stephen Rothwell
2009-01-05 17:45 ` linux-next: Tree for January 5 (dm-target) Randy Dunlap
2009-01-06 3:45 ` Cheng Renquan
2009-01-05 20:04 ` linux-next: Tree for January 5 (multimedia build errors) Randy Dunlap
2009-01-06 11:35 ` Mauro Carvalho Chehab
2009-01-05 20:06 ` linux-next: Tree for January 5 (multimedia #2) Randy Dunlap
2009-01-06 11:39 ` Mauro Carvalho Chehab
2009-01-05 20:09 ` linux-next: Tree for January 5 (multimedia #3) Randy Dunlap
2009-01-07 0:36 ` Mauro Carvalho Chehab
2009-01-07 18:34 ` Randy Dunlap
2009-01-07 23:27 ` Mauro Carvalho Chehab
2009-01-07 23:36 ` Randy Dunlap
2009-01-05 20:11 ` [PATCH -next] jbd2: fix printk format warning Randy Dunlap
2009-01-11 18:52 ` Simon Holm Thøgersen
2009-01-11 19:07 ` Randy Dunlap
2009-01-11 19:20 ` Simon Holm Thøgersen
2009-01-05 21:41 ` Geert Uytterhoeven [this message]
2009-01-05 22:18 ` strncat() misuse (was: Re: dm_attr_{name,uuid}_show buffer overflow? (was: Re: linux-next: Tree for January 5)) Geert Uytterhoeven
2009-01-06 1:27 ` Alasdair G Kergon
2009-01-06 2:16 ` Alasdair G Kergon
2009-01-07 14:39 ` Laurent Pinchart
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.0901052225400.5451@anakin \
--to=geert@linux-m68k.org \
--cc=agk@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-next@vger.kernel.org \
--cc=mbroz@redhat.com \
--cc=sfr@canb.auug.org.au \
/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