Re: [XenPPC] [PATCH] Parse Xen command line properly

2006-10-02 Thread Jimi Xenidis

On Oct 2, 2006, at 12:23 AM, Amos Waterland wrote:

 > We are improperly feeding the entire boot parameter string to Xen's
 > generic command line parser.  This can have unexpected results when
 > one of the dom0 parameters, such as console=X, has meaning to the
 > Xen parser.  First reported by Maria Butrico.

On Oct 2, 2006, at 6:36 AM, Maria Butrico wrote:

 > A long overdue comment about the size of the buffer buff and the
 > size of the buffer bootargs also 256 bytes in boot_of.c.

Amos, Maria good catch.

Amos, the concept of "--" as a separation string is really a boot_of.c
concept not really a Xen one.  For example, if we ever get the GRUB
bootloader to work, it will be unnecessary to pack them all in one
string.

Will this patch work for you?

diff -r 77373497916f xen/arch/powerpc/boot_of.c
--- a/xen/arch/powerpc/boot_of.cSun Oct 01 20:40:44 2006 -0400
+++ b/xen/arch/powerpc/boot_of.cMon Oct 02 08:04:11 2006 -0400
@@ -40,11 +40,12 @@ static ulong of_vec;
 static ulong of_vec;
 static ulong of_msr;
 static int of_out;
-static char bootargs[256];
 
 #define COMMAND_LINE_SIZE 512
 static char builtin_cmdline[COMMAND_LINE_SIZE]
 __attribute__((section("__builtin_cmdline"))) = CMDLINE;
+
+static char bootargs[COMMAND_LINE_SIZE];
 
 extern struct ns16550_defaults ns16550;
 
@@ -465,8 +466,13 @@ static void boot_of_bootargs(multiboot_i
 int rc;
 
 rc = of_getprop(bof_chosen, "bootargs", &bootargs, sizeof (bootargs));
+if (rc > sizeof (bootargs))
+of_panic("bootargs[] not big enough for /chosen/bootargs\n");
+
 if (rc == OF_FAILURE || bootargs[0] == '\0') {
-strlcpy(bootargs, builtin_cmdline, sizeof(bootargs));
+if (sizeof(bootargs) < sizeof(builtin_cmdline))
+of_panic("bootargs[] not big enough for builtin_cmdline\n");
+strcpy(bootargs, builtin_cmdline);
 }
 
 mbi->flags |= MBI_CMDLINE;
@@ -1023,6 +1029,8 @@ static void * __init boot_of_module(ulon
   mods[mod].mod_start, mods[mod].mod_end);
 p = strstr((char *)(ulong)mbi->cmdline, sepr);
 if (p != NULL) {
+/* terminate the Xen portion */
+*(char *)p = '\0';
 p += sizeof (sepr) - 1;
 mods[mod].string = (u32)(ulong)p;
 of_printf("%s: dom0 mod string: %s\n", __func__, p);

___
Xen-ppc-devel mailing list
Xen-ppc-devel@lists.xensource.com
http://lists.xensource.com/xen-ppc-devel


[Fwd: Re: [XenPPC] [PATCH] Parse Xen command line properly]

2006-10-02 Thread Maria Butrico


--- Begin Message ---
A long overdue comment about the size of the buffer buff and the size of 
the buffer bootargs also 256 bytes in boot_of.c.  With the long file 
name for our nfs roots, combined with long names for our initialization 
scripts, I have actually gotten over the limit.  Naturally this occurred 
just shortly before an important deadline.   My current command line, 
for linux only, is 208 characters. 


Amos Waterland wrote:

We are improperly feeding the entire boot parameter string to Xen's
generic command line parser.  This can have unexpected results when one
of the dom0 parameters, such as console=X, has meaning to the Xen
parser.  First reported by Maria Butrico.

Signed-off-by: Amos Waterland <[EMAIL PROTECTED]>

---

 setup.c |   16 ++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff -r 261c458e46af xen/arch/powerpc/setup.c
--- a/xen/arch/powerpc/setup.c  Fri Sep 29 18:13:27 2006 -0400
+++ b/xen/arch/powerpc/setup.c  Mon Oct 02 00:17:07 2006 -0400
@@ -279,8 +279,20 @@ static void __init __start_xen(multiboot
 ticks_per_usec = timebase_freq / 100ULL;
 
 /* Parse the command-line options. */

-if ((mbi->flags & MBI_CMDLINE) && (mbi->cmdline != 0))
-cmdline_parse(__va((ulong)mbi->cmdline));
+if ((mbi->flags & MBI_CMDLINE) && (mbi->cmdline != 0)) {
+char *end, *src = (char *)(ulong)mbi->cmdline;
+char buff[256];
+
+end = strstr(src, "--");
+
+if (end && (end - src < sizeof(buff))) {
+strlcpy(buff, src, end - src);
+} else {
+strlcpy(buff, src, sizeof(buff));
+}
+
+cmdline_parse(buff);
+}
 
 /* We initialise the serial devices very early so we can get debugging. */

 ns16550.io_base = 0x3f8;

___
Xen-ppc-devel mailing list
Xen-ppc-devel@lists.xensource.com
http://lists.xensource.com/xen-ppc-devel
  



--- End Message ---
___
Xen-ppc-devel mailing list
Xen-ppc-devel@lists.xensource.com
http://lists.xensource.com/xen-ppc-devel