All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Long linux kernel command lines
@ 2009-02-10 18:02 Jan Alsenz
  2009-02-10 19:58 ` phcoder
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Jan Alsenz @ 2009-02-10 18:02 UTC (permalink / raw)
  To: Grub-devel


[-- Attachment #1.1: Type: text/plain, Size: 696 bytes --]

Hello!

I just noticed, that the pc linux loader (loader/i386/pc/linux.c) always
truncates the kernel command line to less than 256 characters.
Well since I needed a longer command line, I fixed this problem.

I found a patch on this list from last year (
http://lists.gnu.org/archive/html/grub-devel/2008-05/msg00005.html ),
which apparently was lost in some other discussion.
I didn't use it, because I think my version works better with older kernels.

I tested this on my machine and it worked without a problem with a
2.6.27 kernel.

It would be great if you could add this (or something like it), so I can
switch to the official version again.

Thanks and Regards,

Jan

[-- Attachment #1.2: pc_linux_loader.patch --]
[-- Type: text/plain, Size: 2135 bytes --]

--- loader/i386/pc/linux.c.orig	2009-02-10 17:45:05.000000000 +0100
+++ loader/i386/pc/linux.c	2009-02-10 17:25:22.000000000 +0100
@@ -30,6 +30,7 @@
 #include <grub/rescue.h>
 #include <grub/dl.h>
 #include <grub/cpu/linux.h>
+#include <grub/mm.h>
 
 #define GRUB_LINUX_CL_OFFSET		0x9000
 #define GRUB_LINUX_CL_END_OFFSET	0x90FF
@@ -38,11 +39,15 @@
 
 static grub_size_t linux_mem_size;
 static int loaded;
+static char* kernel_cl_space = NULL;
+#define GRUB_LINUX_CL_MAX_SIZE 0x1000  /* maximum defined for linux kernels */
 
 static grub_err_t
 grub_linux_unload (void)
 {
   grub_dl_unref (my_mod);
+  grub_free(kernel_cl_space);
+  kernel_cl_space = NULL;
   loaded = 0;
   return GRUB_ERR_NONE;
 }
@@ -119,9 +124,10 @@
 	  lh.loadflags |= GRUB_LINUX_FLAG_CAN_USE_HEAP;
 	}
       
-      if (grub_le_to_cpu16 (lh.version) >= 0x0202)
-	lh.cmd_line_ptr = grub_linux_real_addr + GRUB_LINUX_CL_OFFSET;
-      else
+      if (grub_le_to_cpu16 (lh.version) >= 0x0202) {
+    	  kernel_cl_space = grub_malloc(GRUB_LINUX_CL_MAX_SIZE);
+    	  lh.cmd_line_ptr = kernel_cl_space;
+      } else
 	{
 	  lh.cl_magic = grub_cpu_to_le16 (GRUB_LINUX_CL_MAGIC);
 	  lh.cl_offset = grub_cpu_to_le16 (GRUB_LINUX_CL_OFFSET);
@@ -245,16 +251,25 @@
 		 ((GRUB_LINUX_MAX_SETUP_SECTS - setup_sects - 1)
 		  << GRUB_DISK_SECTOR_BITS));
 
+  /* Choose the command line area */
+  char* cl_end;
+  if (kernel_cl_space) {
+	  dest = kernel_cl_space;
+	  cl_end = dest + GRUB_LINUX_CL_MAX_SIZE - 1;
+  } else {
+	  dest = grub_linux_tmp_addr + GRUB_LINUX_CL_OFFSET;
+	  cl_end = grub_linux_tmp_addr + GRUB_LINUX_CL_END_OFFSET;
+  }
+  
   /* Specify the boot file.  */
-  dest = grub_stpcpy (grub_linux_tmp_addr + GRUB_LINUX_CL_OFFSET,
+  dest = grub_stpcpy (dest,
 		      "BOOT_IMAGE=");
   dest = grub_stpcpy (dest, argv[0]);
   
   /* Copy kernel parameters.  */
   for (i = 1;
        i < argc
-	 && dest + grub_strlen (argv[i]) + 1 < (grub_linux_tmp_addr
-						+ GRUB_LINUX_CL_END_OFFSET);
+	 && dest + grub_strlen (argv[i]) + 1 < cl_end;
        i++)
     {
       *dest++ = ' ';

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 260 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Long linux kernel command lines
  2009-02-10 18:02 [PATCH] Long linux kernel command lines Jan Alsenz
@ 2009-02-10 19:58 ` phcoder
  2009-02-10 20:09   ` Jan Alsenz
  2009-02-11 12:48 ` Jan Alsenz
  2009-02-21 14:57 ` Robert Millan
  2 siblings, 1 reply; 7+ messages in thread
From: phcoder @ 2009-02-10 19:58 UTC (permalink / raw)
  To: The development of GRUB 2

Hello!
I don't know the linux booting protocol in details but it looks like you 
patch replaces one arbitrary limit (256) by another (4096). Is there any 
way of avoiding any arbitrary limit at all wothout modyfiing boot protocol?
Thanks
Vladimir 'phcoder' Serbinenko
Jan Alsenz wrote:
> Hello!
> 
> I just noticed, that the pc linux loader (loader/i386/pc/linux.c) always
> truncates the kernel command line to less than 256 characters.
> Well since I needed a longer command line, I fixed this problem.
> 
> I found a patch on this list from last year (
> http://lists.gnu.org/archive/html/grub-devel/2008-05/msg00005.html ),
> which apparently was lost in some other discussion.
> I didn't use it, because I think my version works better with older kernels.
> 
> I tested this on my machine and it worked without a problem with a
> 2.6.27 kernel.
> 
> It would be great if you could add this (or something like it), so I can
> switch to the official version again.
> 
> Thanks and Regards,
> 
> Jan
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Long linux kernel command lines
  2009-02-10 19:58 ` phcoder
@ 2009-02-10 20:09   ` Jan Alsenz
  0 siblings, 0 replies; 7+ messages in thread
From: Jan Alsenz @ 2009-02-10 20:09 UTC (permalink / raw)
  To: The development of GRUB 2

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

Hi!

I also don't know the exact details, it sure would be better to have some kind
of detection!

But the limit I set is not that arbitrary:
--- Quote from Documentation/kernel-parameters.txt ---
The number of kernel parameters is not limited, but the length of the
complete command line (parameters including spaces etc.) is limited to
a fixed number of characters. This limit depends on the architecture
and is between 256 and 4096 characters. It is defined in the file
./include/asm/setup.h as COMMAND_LINE_SIZE.
--- Quote end ---

And from what I've seen in the kernel code the maximum supported length is
copied from lh.cmd_line_ptr into kernel space and processed.

Greets,

Jan



phcoder schrieb:
> Hello!
> I don't know the linux booting protocol in details but it looks like you
> patch replaces one arbitrary limit (256) by another (4096). Is there any
> way of avoiding any arbitrary limit at all wothout modyfiing boot protocol?
> Thanks
> Vladimir 'phcoder' Serbinenko
> Jan Alsenz wrote:
>> Hello!
>>
>> I just noticed, that the pc linux loader (loader/i386/pc/linux.c) always
>> truncates the kernel command line to less than 256 characters.
>> Well since I needed a longer command line, I fixed this problem.
>>
>> I found a patch on this list from last year (
>> http://lists.gnu.org/archive/html/grub-devel/2008-05/msg00005.html ),
>> which apparently was lost in some other discussion.
>> I didn't use it, because I think my version works better with older
>> kernels.
>>
>> I tested this on my machine and it worked without a problem with a
>> 2.6.27 kernel.
>>
>> It would be great if you could add this (or something like it), so I can
>> switch to the official version again.
>>
>> Thanks and Regards,
>>
>> Jan
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> http://lists.gnu.org/mailman/listinfo/grub-devel
> 
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
> 


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Long linux kernel command lines
  2009-02-10 18:02 [PATCH] Long linux kernel command lines Jan Alsenz
  2009-02-10 19:58 ` phcoder
@ 2009-02-11 12:48 ` Jan Alsenz
  2009-02-21 14:57 ` Robert Millan
  2 siblings, 0 replies; 7+ messages in thread
From: Jan Alsenz @ 2009-02-11 12:48 UTC (permalink / raw)
  To: Grub-devel


[-- Attachment #1.1: Type: text/plain, Size: 1049 bytes --]

Hi again!

I checked the boot protocol documentation and found that since version
2.06 (kernel 2.6.22) there is a field with the supported command line size.

I updated my patch to respect this field if it is present, otherwise the
maximum 4k buffer is used.

Greets,

Jan


Jan Alsenz schrieb:
> Hello!
> 
> I just noticed, that the pc linux loader (loader/i386/pc/linux.c) always
> truncates the kernel command line to less than 256 characters.
> Well since I needed a longer command line, I fixed this problem.
> 
> I found a patch on this list from last year (
> http://lists.gnu.org/archive/html/grub-devel/2008-05/msg00005.html ),
> which apparently was lost in some other discussion.
> I didn't use it, because I think my version works better with older kernels.
> 
> I tested this on my machine and it worked without a problem with a
> 2.6.27 kernel.
> 
> It would be great if you could add this (or something like it), so I can
> switch to the official version again.
> 
> Thanks and Regards,
> 
> Jan
> 

[-- Attachment #1.2: pc_linux_loader.patch --]
[-- Type: text/plain, Size: 3351 bytes --]

--- loader/i386/pc/linux.c.orig	2009-02-11 10:56:27.000000000 +0100
+++ loader/i386/pc/linux.c	2009-02-11 10:56:38.000000000 +0100
@@ -30,6 +30,7 @@
 #include <grub/rescue.h>
 #include <grub/dl.h>
 #include <grub/cpu/linux.h>
+#include <grub/mm.h>
 
 #define GRUB_LINUX_CL_OFFSET		0x9000
 #define GRUB_LINUX_CL_END_OFFSET	0x90FF
@@ -38,11 +39,15 @@
 
 static grub_size_t linux_mem_size;
 static int loaded;
+static char* kernel_cl_space = NULL;
+#define GRUB_LINUX_CL_MAX_SIZE 0x1000  /* maximum defined for linux kernels */
 
 static grub_err_t
 grub_linux_unload (void)
 {
   grub_dl_unref (my_mod);
+  grub_free(kernel_cl_space);
+  kernel_cl_space = NULL;
   loaded = 0;
   return GRUB_ERR_NONE;
 }
@@ -119,9 +124,14 @@
 	  lh.loadflags |= GRUB_LINUX_FLAG_CAN_USE_HEAP;
 	}
       
-      if (grub_le_to_cpu16 (lh.version) >= 0x0202)
-	lh.cmd_line_ptr = grub_linux_real_addr + GRUB_LINUX_CL_OFFSET;
-      else
+      if (grub_le_to_cpu16 (lh.version) >= 0x0202) {
+          if (grub_le_to_cpu16 (lh.version) >= 0x0206) {
+        	  kernel_cl_space = grub_malloc(lh.cmdline_size+1);
+          } else {
+        	  kernel_cl_space = grub_malloc(GRUB_LINUX_CL_MAX_SIZE);
+          }
+    	  lh.cmd_line_ptr = kernel_cl_space;
+      } else
 	{
 	  lh.cl_magic = grub_cpu_to_le16 (GRUB_LINUX_CL_MAGIC);
 	  lh.cl_offset = grub_cpu_to_le16 (GRUB_LINUX_CL_OFFSET);
@@ -245,16 +255,29 @@
 		 ((GRUB_LINUX_MAX_SETUP_SECTS - setup_sects - 1)
 		  << GRUB_DISK_SECTOR_BITS));
 
+  /* Choose the command line area */
+  char* cl_end;
+  if (kernel_cl_space) {
+	  dest = kernel_cl_space;
+      if (grub_le_to_cpu16 (lh.version) >= 0x0206) {
+    	  cl_end = dest + lh.cmdline_size;
+      } else {
+    	  cl_end = dest + GRUB_LINUX_CL_MAX_SIZE - 1;
+      }
+  } else {
+	  dest = grub_linux_tmp_addr + GRUB_LINUX_CL_OFFSET;
+	  cl_end = grub_linux_tmp_addr + GRUB_LINUX_CL_END_OFFSET;
+  }
+  
   /* Specify the boot file.  */
-  dest = grub_stpcpy (grub_linux_tmp_addr + GRUB_LINUX_CL_OFFSET,
+  dest = grub_stpcpy (dest,
 		      "BOOT_IMAGE=");
   dest = grub_stpcpy (dest, argv[0]);
   
   /* Copy kernel parameters.  */
   for (i = 1;
        i < argc
-	 && dest + grub_strlen (argv[i]) + 1 < (grub_linux_tmp_addr
-						+ GRUB_LINUX_CL_END_OFFSET);
+	 && dest + grub_strlen (argv[i]) + 1 < cl_end;
        i++)
     {
       *dest++ = ' ';
--- include/grub/i386/linux.h.orig	2009-02-11 10:43:01.000000000 +0100
+++ include/grub/i386/linux.h	2009-02-11 10:50:33.000000000 +0100
@@ -123,6 +123,15 @@
   grub_uint16_t pad1;			/* Unused */
   char *cmd_line_ptr;			/* Points to the kernel command line */
   grub_uint32_t initrd_addr_max;        /* Highest address for initrd */
+  /* 2.05+ */
+  grub_uint32_t kernel_alignment;	/* Physical addr alignment required for kernel */
+  grub_uint8_t relocatable_kernel;	/* Whether kernel is relocatable or not */
+  grub_uint8_t pad2[3];				/* Unused */
+  /* 2.06+ */
+  grub_uint32_t cmdline_size;		/* Maximum size of the kernel command line */
+  /* 2.07+ */
+  grub_uint32_t hardware_subarch;	/* Hardware subarchitecture */
+  grub_uint64_t hardware_subarch_data;	/* Subarchitecture-specific data */
 } __attribute__ ((packed));
 
 /* Boot parameters for Linux based on 2.6.12. This is used by the setup

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 260 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Long linux kernel command lines
  2009-02-10 18:02 [PATCH] Long linux kernel command lines Jan Alsenz
  2009-02-10 19:58 ` phcoder
  2009-02-11 12:48 ` Jan Alsenz
@ 2009-02-21 14:57 ` Robert Millan
  2009-02-21 15:34   ` Jan Alsenz
  2 siblings, 1 reply; 7+ messages in thread
From: Robert Millan @ 2009-02-21 14:57 UTC (permalink / raw)
  To: The development of GRUB 2

On Tue, Feb 10, 2009 at 07:02:56PM +0100, Jan Alsenz wrote:
> Hello!
> 
> I just noticed, that the pc linux loader (loader/i386/pc/linux.c) always
> truncates the kernel command line to less than 256 characters.
> Well since I needed a longer command line, I fixed this problem.

Hi,

Thanks for your effort, but note that this can't be changed carelessly.  It's
possible we have this limit for backward compatibility.

If newer versions of Linux allow a longer cmdline, our code should check for
that instead.

Also, would be cool if you can check whether loader/i386/linux.c also has
this problem.

-- 
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Long linux kernel command lines
  2009-02-21 14:57 ` Robert Millan
@ 2009-02-21 15:34   ` Jan Alsenz
  2009-04-10 23:37     ` phcoder
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Alsenz @ 2009-02-21 15:34 UTC (permalink / raw)
  To: The development of GRUB 2

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

Robert Millan wrote:
> On Tue, Feb 10, 2009 at 07:02:56PM +0100, Jan Alsenz wrote:
>> Hello!
>>
>> I just noticed, that the pc linux loader (loader/i386/pc/linux.c) always
>> truncates the kernel command line to less than 256 characters.
>> Well since I needed a longer command line, I fixed this problem.
> 
> Hi,
> 
> Thanks for your effort, but note that this can't be changed carelessly.  It's
> possible we have this limit for backward compatibility.
> 
> If newer versions of Linux allow a longer cmdline, our code should check for
> that instead.

If you look at the patch I send on Feb 11, I think it does all the necessary checks.

> Also, would be cool if you can check whether loader/i386/linux.c also has
> this problem.

Well, it uses a fixed 4k command-line area. But I don't know, if this is a
problem there.

Greets,

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] Long linux kernel command lines
  2009-02-21 15:34   ` Jan Alsenz
@ 2009-04-10 23:37     ` phcoder
  0 siblings, 0 replies; 7+ messages in thread
From: phcoder @ 2009-04-10 23:37 UTC (permalink / raw)
  To: The development of GRUB 2, janalsenz

Grüüzzi
This part (now named linux16) is kept for backward compatibility only. 
And it looks like current implementation of linux command doesn't suffer 
this limitation. Can you confirm?
BTW I'm at ETH too
Jan Alsenz wrote:
> Robert Millan wrote:
>> On Tue, Feb 10, 2009 at 07:02:56PM +0100, Jan Alsenz wrote:
>>> Hello!
>>>
>>> I just noticed, that the pc linux loader (loader/i386/pc/linux.c) always
>>> truncates the kernel command line to less than 256 characters.
>>> Well since I needed a longer command line, I fixed this problem.
>> Hi,
>>
>> Thanks for your effort, but note that this can't be changed carelessly.  It's
>> possible we have this limit for backward compatibility.
>>
>> If newer versions of Linux allow a longer cmdline, our code should check for
>> that instead.
> 
> If you look at the patch I send on Feb 11, I think it does all the necessary checks.
> 
>> Also, would be cool if you can check whether loader/i386/linux.c also has
>> this problem.
> 
> Well, it uses a fixed 4k command-line area. But I don't know, if this is a
> problem there.
> 
> Greets,
> 
> Jan
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel


-- 

Regards
Vladimir 'phcoder' Serbinenko



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-04-10 23:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-10 18:02 [PATCH] Long linux kernel command lines Jan Alsenz
2009-02-10 19:58 ` phcoder
2009-02-10 20:09   ` Jan Alsenz
2009-02-11 12:48 ` Jan Alsenz
2009-02-21 14:57 ` Robert Millan
2009-02-21 15:34   ` Jan Alsenz
2009-04-10 23:37     ` phcoder

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.