All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jurij Smakov <jurij@wooyd.org>
To: sparclinux@vger.kernel.org
Subject: Problems with setting devices' bus_id on sparc32
Date: Fri, 27 Oct 2006 06:55:03 +0000	[thread overview]
Message-ID: <20061027065502.GA4108@droopy.oc.cox.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 983 bytes --]

Hi,

While investigating Debian bug #394697 [0] on sparc32, I've found that 
in a couple of places the bus_id field of struct device is set by 
copying the dp->path_component_name (obtained from prom) without any 
length checking. In most cases it happens to work, however on 
SparcStation5 for some devices this string is over 20 chars long (like 
'power-management@4,a0000000'), and that exceeds the amount of memory 
allocated for bus_id (which is BUS_ID_SIZE == 20). So, blindly 
copying the names into bus_id using strcpy() leads to all kinds of bad 
things. The attached hackish patch replaces strcpy() by strlcpy() in 
two places, making it possible to boot SS5 again (tested in QEMU, 
where vanilla 2.6.18 fails to boot with symptoms identical to the ones
described in the bug).

[0] http://bugs.debian.org/394697

Best regards,
-- 
Jurij Smakov                                           jurij@wooyd.org
Key: http://www.wooyd.org/pgpkey/                      KeyID: C99E03CC

[-- Attachment #2: bus-id-size.patch --]
[-- Type: text/plain, Size: 1035 bytes --]

diff -aur a/arch/sparc/kernel/of_device.c b/arch/sparc/kernel/of_device.c
--- a/arch/sparc/kernel/of_device.c	2006-09-19 20:42:06.000000000 -0700
+++ b/arch/sparc/kernel/of_device.c	2006-10-26 22:53:50.000000000 -0700
@@ -652,7 +652,7 @@
 	if (!parent)
 		strcpy(op->dev.bus_id, "root");
 	else
-		strcpy(op->dev.bus_id, dp->path_component_name);
+		strlcpy(op->dev.bus_id, dp->path_component_name, BUS_ID_SIZE);
 
 	if (of_device_register(op)) {
 		printk("%s: Could not register of device.\n",
diff -aur a/drivers/sbus/sbus.c b/drivers/sbus/sbus.c
--- a/drivers/sbus/sbus.c	2006-09-19 20:42:06.000000000 -0700
+++ b/drivers/sbus/sbus.c	2006-10-26 22:53:19.000000000 -0700
@@ -61,7 +61,7 @@
 	else
 		sdev->ofdev.dev.parent = &sdev->bus->ofdev.dev;
 	sdev->ofdev.dev.bus = &sbus_bus_type;
-	strcpy(sdev->ofdev.dev.bus_id, dp->path_component_name);
+	strlcpy(sdev->ofdev.dev.bus_id, dp->path_component_name, BUS_ID_SIZE);
 
 	if (of_device_register(&sdev->ofdev) != 0)
 		printk(KERN_DEBUG "sbus: device registration error for %s!\n",

             reply	other threads:[~2006-10-27  6:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-27  6:55 Jurij Smakov [this message]
2006-10-27  7:22 ` Problems with setting devices' bus_id on sparc32 David Miller

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=20061027065502.GA4108@droopy.oc.cox.net \
    --to=jurij@wooyd.org \
    --cc=sparclinux@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.