Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1MPH5A-00084U-Oy for mharc-grub-devel@gnu.org; Fri, 10 Jul 2009 10:28:12 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MPH58-00082N-OU for grub-devel@gnu.org; Fri, 10 Jul 2009 10:28:10 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MPH53-0007z7-Im for grub-devel@gnu.org; Fri, 10 Jul 2009 10:28:10 -0400 Received: from [199.232.76.173] (port=39393 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MPH53-0007yw-FC for grub-devel@gnu.org; Fri, 10 Jul 2009 10:28:05 -0400 Received: from mail-pz0-f197.google.com ([209.85.222.197]:46432) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MPH52-0001Ea-5z for grub-devel@gnu.org; Fri, 10 Jul 2009 10:28:05 -0400 Received: by pzk35 with SMTP id 35so644711pzk.14 for ; Fri, 10 Jul 2009 07:28:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=YUwrUKiRjWAPBgGrg56rFAqQpi+0X5fHJTEoy+Cc8EU=; b=lGRwxYGRlsLf5ptG9j1+wlObsG/JT0Fi1U+53TuwuAcLahNEXFsYVo0nQfmaS9Ed8G Su6iPttATH+zQ6SAB+RiHW8GLtjPgfYDCrSGk6Ow+pTtGos2AxpVwoE+HL+tDCLIDU/T iVMXd0pMCcnifmf8ENrBjWgA499sDI8IBGY1I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=v2LJaU9g5YXX4mVnhL8oPt8J4z+t5/v6emhfa1piFDv9Nb/NLJWCR1HnEsxGNPvnss gjC5D31RYBqOz4Za2mmL46kFcQaGyTqIte8E9w6c12247Z41mSNEVKTCYewBd5iked3o /ONtmiNDJC7hr09X3AoqVIjP+l7rN78KjTi+4= MIME-Version: 1.0 Received: by 10.114.95.5 with SMTP id s5mr3335774wab.1.1247236083344; Fri, 10 Jul 2009 07:28:03 -0700 (PDT) In-Reply-To: <20090709160301.GA29422@thorin> References: <20090709160301.GA29422@thorin> Date: Fri, 10 Jul 2009 22:28:03 +0800 Message-ID: From: Bean To: The development of GRUB 2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: Re: OLPC regression, ofdisk stops working X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Jul 2009 14:28:11 -0000 Hi, There is something wrong with r2132, now childtype is a pointer, so sizeof childtype =3D=3D 4, the name would be truncated to 4 characters. diff --git a/kern/ieee1275/openfw.c b/kern/ieee1275/openfw.c index e7979f4..42d9278 100644 --- a/kern/ieee1275/openfw.c +++ b/kern/ieee1275/openfw.c @@ -78,15 +78,15 @@ grub_children_iterate (char *devpath, grub_ssize_t actual; if (grub_ieee1275_get_property (child, "device_type", childtype, - sizeof childtype, &actual)) + IEEE1275_MAX_PROP_LEN, &actual)) continue; - if (grub_ieee1275_package_to_path (child, childpath, sizeof childpat= h, - &actual)) + if (grub_ieee1275_package_to_path (child, childpath, + IEEE1275_MAX_PATH_LEN, &actual)) continue; if (grub_ieee1275_get_property (child, "name", childname, - sizeof childname, &actual)) + IEEE1275_MAX_PATH_LEN, &actual)) continue; grub_sprintf (fullname, "%s/%s", devpath, childname); On Fri, Jul 10, 2009 at 12:03 AM, Robert Millan wrote: > > Hi, > > I got completely puzzled at this one. =A0 Turns out r2132 broke ofdisk on > OLPC. =A0But I don't see anything wrong in this commit. > > I isolated the change that causes this breakage, and it's very confusing. > It turns out that allocating devtype in the heap instead of the stack > causes its result to be truncated to 4 bytes (+ null terminator). > > I'm not sure what can we do about this. =A0If we're certain it's an OFW > bug, perhaps we could workaround it by comparing only the first 4 bytes > of the result. =A0This worked for me: > > - =A0 =A0 =A0if (! grub_strcmp (alias->type, "block")) > + =A0 =A0 =A0if (! grub_strncmp (alias->type, "bloc", 4)) > > (but using the existing "workaround framework") > > but it's scary. =A0I don't know if this 4-byte limit is consistent, or > will differ arbitrarily. =A0Maybe we could issue a warning or so, I don't > know. > > Is there someone else (Bean?) who can reproduce this problem? =A0Does it > fail in the same way? > > On Wed, Apr 22, 2009 at 09:46:55AM +0000, David S. Miller wrote: >> Revision: 2132 >> =A0 =A0 =A0 =A0 =A0 http://svn.sv.gnu.org/viewvc/?view=3Drev&root=3Dgrub= &revision=3D2132 >> Author: =A0 davem >> Date: =A0 =A0 2009-04-22 09:46:54 +0000 (Wed, 22 Apr 2009) >> Log Message: >> ----------- >> =A0 =A0 =A0 * include/grub/ieee1275/ieee1275.h (IEEE1275_MAX_PROP_LEN, >> =A0 =A0 =A0 IEEE1275_MAX_PATH_LEN): Define. >> =A0 =A0 =A0 * kern/ieee1275/openfw.c (grub_children_iterate): Dynamicall= y >> =A0 =A0 =A0 allocate 'childtype', 'childpath', 'childname', and 'fullnam= e'. >> =A0 =A0 =A0 (grub_devalias_iterate): Dynamically allocate 'aliasname' an= d >> =A0 =A0 =A0 'devtype'. =A0Explicitly NULL terminate devalias expansion. >> >> Modified Paths: >> -------------- >> =A0 =A0 trunk/grub2/ChangeLog >> =A0 =A0 trunk/grub2/include/grub/ieee1275/ieee1275.h >> =A0 =A0 trunk/grub2/kern/ieee1275/openfw.c >> >> Modified: trunk/grub2/ChangeLog >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> --- trunk/grub2/ChangeLog =A0 =A0 2009-04-22 09:45:43 UTC (rev 2131) >> +++ trunk/grub2/ChangeLog =A0 =A0 2009-04-22 09:46:54 UTC (rev 2132) >> @@ -3,6 +3,13 @@ >> =A0 =A0 =A0 * kern/ieee1275/mmap.c (grub_machine_mmap_iterate): If size_= cells >> =A0 =A0 =A0 is larger than address_cells, use that value for address_cel= ls too. >> >> + =A0 =A0 * include/grub/ieee1275/ieee1275.h (IEEE1275_MAX_PROP_LEN, >> + =A0 =A0 IEEE1275_MAX_PATH_LEN): Define. >> + =A0 =A0 * kern/ieee1275/openfw.c (grub_children_iterate): Dynamically >> + =A0 =A0 allocate 'childtype', 'childpath', 'childname', and 'fullname'= . >> + =A0 =A0 (grub_devalias_iterate): Dynamically allocate 'aliasname' and >> + =A0 =A0 'devtype'. =A0Explicitly NULL terminate devalias expansion. >> + >> =A02009-04-19 =A0Vladimir Serbinenko >> >> =A0 =A0 =A0 Correct GPT definition >> >> Modified: trunk/grub2/include/grub/ieee1275/ieee1275.h >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> --- trunk/grub2/include/grub/ieee1275/ieee1275.h =A0 =A0 =A02009-04-22 0= 9:45:43 UTC (rev 2131) >> +++ trunk/grub2/include/grub/ieee1275/ieee1275.h =A0 =A0 =A02009-04-22 0= 9:46:54 UTC (rev 2132) >> @@ -39,6 +39,9 @@ >> =A0 =A0unsigned int size; >> =A0}; >> >> +#define IEEE1275_MAX_PROP_LEN =A0 =A0 =A0 =A08192 >> +#define IEEE1275_MAX_PATH_LEN =A0 =A0 =A0 =A0256 >> + >> =A0#ifndef IEEE1275_CALL_ENTRY_FN >> =A0#define IEEE1275_CALL_ENTRY_FN(args) (*grub_ieee1275_entry_fn) (args) >> =A0#endif >> >> Modified: trunk/grub2/kern/ieee1275/openfw.c >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> --- trunk/grub2/kern/ieee1275/openfw.c =A0 =A0 =A0 =A02009-04-22 09:45:4= 3 UTC (rev 2131) >> +++ trunk/grub2/kern/ieee1275/openfw.c =A0 =A0 =A0 =A02009-04-22 09:46:5= 4 UTC (rev 2132) >> @@ -38,6 +38,8 @@ >> =A0{ >> =A0 =A0grub_ieee1275_phandle_t dev; >> =A0 =A0grub_ieee1275_phandle_t child; >> + =A0char *childtype, *childpath; >> + =A0char *childname, *fullname; >> >> =A0 =A0if (grub_ieee1275_finddevice (devpath, &dev)) >> =A0 =A0 =A0return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Unknown device")= ; >> @@ -45,13 +47,33 @@ >> =A0 =A0if (grub_ieee1275_child (dev, &child)) >> =A0 =A0 =A0return grub_error (GRUB_ERR_BAD_DEVICE, "Device has no childr= en"); >> >> + =A0childtype =3D grub_malloc (IEEE1275_MAX_PROP_LEN); >> + =A0if (!childtype) >> + =A0 =A0return grub_errno; >> + =A0childpath =3D grub_malloc (IEEE1275_MAX_PATH_LEN); >> + =A0if (!childpath) >> + =A0 =A0{ >> + =A0 =A0 =A0grub_free (childtype); >> + =A0 =A0 =A0return grub_errno; >> + =A0 =A0} >> + =A0childname =3D grub_malloc (IEEE1275_MAX_PROP_LEN); >> + =A0if (!childname) >> + =A0 =A0{ >> + =A0 =A0 =A0grub_free (childpath); >> + =A0 =A0 =A0grub_free (childtype); >> + =A0 =A0 =A0return grub_errno; >> + =A0 =A0} >> + =A0fullname =3D grub_malloc (IEEE1275_MAX_PATH_LEN); >> + =A0if (!fullname) >> + =A0 =A0{ >> + =A0 =A0 =A0grub_free (childname); >> + =A0 =A0 =A0grub_free (childpath); >> + =A0 =A0 =A0grub_free (childtype); >> + =A0 =A0 =A0return grub_errno; >> + =A0 =A0} >> + >> =A0 =A0do >> =A0 =A0 =A0{ >> - =A0 =A0 =A0/* XXX: Don't use hardcoded path lengths. =A0*/ >> - =A0 =A0 =A0char childtype[64]; >> - =A0 =A0 =A0char childpath[64]; >> - =A0 =A0 =A0char childname[64]; >> - =A0 =A0 =A0char fullname[64]; >> =A0 =A0 =A0 =A0struct grub_ieee1275_devalias alias; >> =A0 =A0 =A0 =A0grub_ssize_t actual; >> >> @@ -76,6 +98,11 @@ >> =A0 =A0 =A0} >> =A0 =A0while (grub_ieee1275_peer (child, &child)); >> >> + =A0grub_free (fullname); >> + =A0grub_free (childname); >> + =A0grub_free (childpath); >> + =A0grub_free (childtype); >> + >> =A0 =A0return 0; >> =A0} >> >> @@ -85,13 +112,23 @@ >> =A0grub_devalias_iterate (int (*hook) (struct grub_ieee1275_devalias *al= ias)) >> =A0{ >> =A0 =A0grub_ieee1275_phandle_t aliases; >> - =A0char aliasname[32]; >> + =A0char *aliasname, *devtype; >> =A0 =A0grub_ssize_t actual; >> =A0 =A0struct grub_ieee1275_devalias alias; >> >> =A0 =A0if (grub_ieee1275_finddevice ("/aliases", &aliases)) >> =A0 =A0 =A0return -1; >> >> + =A0aliasname =3D grub_malloc (IEEE1275_MAX_PROP_LEN); >> + =A0if (!aliasname) >> + =A0 =A0return grub_errno; >> + =A0devtype =3D grub_malloc (IEEE1275_MAX_PROP_LEN); >> + =A0if (!devtype) >> + =A0 =A0{ >> + =A0 =A0 =A0grub_free (aliasname); >> + =A0 =A0 =A0return grub_errno; >> + =A0 =A0} >> + >> =A0 =A0/* Find the first property. =A0*/ >> =A0 =A0aliasname[0] =3D '\0'; >> >> @@ -100,8 +137,6 @@ >> =A0 =A0 =A0 =A0grub_ieee1275_phandle_t dev; >> =A0 =A0 =A0 =A0grub_ssize_t pathlen; >> =A0 =A0 =A0 =A0char *devpath; >> - =A0 =A0 =A0/* XXX: This should be large enough for any possible case. = =A0*/ >> - =A0 =A0 =A0char devtype[64]; >> >> =A0 =A0 =A0 =A0grub_dprintf ("devalias", "devalias name =3D %s\n", alias= name); >> >> @@ -111,9 +146,17 @@ >> =A0 =A0 =A0 =A0if (!grub_strcmp (aliasname, "name")) >> =A0 =A0 =A0 continue; >> >> + =A0 =A0 =A0/* Sun's OpenBoot often doesn't zero terminate the device a= lias >> + =A0 =A0 =A0strings, so we will add a NULL byte at the end explicitly. = =A0*/ >> + =A0 =A0 =A0pathlen +=3D 1; >> + >> =A0 =A0 =A0 =A0devpath =3D grub_malloc (pathlen); >> =A0 =A0 =A0 =A0if (! devpath) >> - =A0 =A0 return grub_errno; >> + =A0 =A0 { >> + =A0 =A0 =A0 grub_free (devtype); >> + =A0 =A0 =A0 grub_free (aliasname); >> + =A0 =A0 =A0 return grub_errno; >> + =A0 =A0 } >> >> =A0 =A0 =A0 =A0if (grub_ieee1275_get_property (aliases, aliasname, devpa= th, pathlen, >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = &actual)) >> @@ -121,6 +164,7 @@ >> =A0 =A0 =A0 =A0 grub_dprintf ("devalias", "get_property (%s) failed\n", = aliasname); >> =A0 =A0 =A0 =A0 goto nextprop; >> =A0 =A0 =A0 } >> + =A0 =A0 =A0devpath [actual] =3D '\0'; >> >> =A0 =A0 =A0 =A0if (grub_ieee1275_finddevice (devpath, &dev)) >> =A0 =A0 =A0 { >> @@ -144,6 +188,8 @@ >> =A0 =A0 =A0 =A0grub_free (devpath); >> =A0 =A0 =A0} >> >> + =A0grub_free (devtype); >> + =A0grub_free (aliasname); >> =A0 =A0return 0; >> =A0} >> >> >> >> >> > > -- > Robert Millan > > =A0The DRM opt-in fallacy: "Your data belongs to us. We will decide when = (and > =A0how) you may access your data; but nobody's threatening your freedom: = we > =A0still allow you to remove your data and not access it at all." > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > http://lists.gnu.org/mailman/listinfo/grub-devel > --=20 Bean