On 17/06/25 16:31, Shreenidhi Shedi wrote:
On 11/06/25 01:34, Shreenidhi Shedi wrote:
On 23/05/25 22:22, Shreenidhi Shedi wrote:
On 20/05/25 19:15, Daniel Kiper wrote:
On Mon, May 19, 2025 at 11:49:55PM +0530, Shreenidhi Shedi wrote:
From: Shreenidhi Shedi <shreenidhi.sh...@broadcom.com>
Previously, the command line construction function
(grub_create_loader_cmdline) escaped single and double quotes,
which is
unnecessary and potentially problematic since the kernel command line
handler does not support escaped quotes. This patch removes the
escaping
of these characters, ensuring that the constructed command line is
passed to the kernel as intended.
For example:
In /boot/grub/grub.cfg
...
set user_cmdline="dyndbg='+p; func smp_callin -p'"
...
menuentry "Photon" {
linux /boot/$photon_linux root=$rootpartition $photon_cmdline
$systemd_cmdline $user_cmdline
if [ -f /boot/$photon_initrd ]; then
initrd /boot/$photon_initrd
fi
}
...
Post reboot,
$ cat /proc/cmdline
... dyndbg=\'+p; func smp_callin -p\'
AFIACT Vladimir has more complete fix for this issue. I asked him to
post it once again...
Daniel
Hi Daniel,
Can you please add Vladimir to this thread? This is a regression and
if we can get a better fix, I can test it and provide an update.
Hi Daniel and Vladimir,
I tested the Vladimir's patch which he gave at
https://lists.gnu.org/archive/html/grub-devel/2025-05/msg00182.html
I managed to get it working with few tweaks. I introduced a special
arg 'noescape' to set noescape argument to 1 while calling
'grub_create_loader_cmdline' function. In the given patch it is hard
coded to 0. Is there any other way to set it to 1?
I have a question, what is the significance of escaping the quotes
while creating kernel command line args while Linux kernel doesn't
support escape sequences in command line args?
Hi Daniel,
Gentle reminder on this query.
From 1e062220d64ce1cf491ad670f368c06072668d2b Mon Sep 17 00:00:00 2001
From: Shreenidhi Shedi <shreenidhi.sh...@broadcom.com>
Date: Wed, 14 May 2025 14:47:15 +0530
Subject: [PATCH v3 1/1] cmdline: fix command line parsing in grub
Previously, the command line construction function
(grub_create_loader_cmdline) escaped single and double quotes, which is
unnecessary and potentially problematic since the kernel command line
handler does not support escaped quotes. This patch removes the escaping
of these characters, ensuring that the constructed command line is
passed to the kernel as intended.
For example:
In /boot/grub/grub.cfg
...
set user_cmdline="dyndbg='+p; func smp_callin -p'"
...
menuentry "Photon" {
linux /boot/$photon_linux root=$rootpartition $photon_cmdline
$systemd_cmdline $user_cmdline
if [ -f /boot/$photon_initrd ]; then
initrd /boot/$photon_initrd
fi
}
...
Post reboot,
$ cat /proc/cmdline
... dyndbg=\'+p; func smp_callin -p\'
Signed-off-by: Shreenidhi Shedi <shreenidhi.sh...@broadcom.com>
Reviewed-by: Alexey Makhalov <alexey.makha...@broadcom.com>
---
grub-core/lib/cmdline.c | 52 +++++++++++++++++------------------------
1 file changed, 21 insertions(+), 31 deletions(-)
diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c
index ed0b149dc..dfb661a7f 100644
--- a/grub-core/lib/cmdline.c
+++ b/grub-core/lib/cmdline.c
@@ -20,51 +20,45 @@
#include <grub/lib/cmdline.h>
#include <grub/misc.h>
-static unsigned int check_arg (char *c, int *has_space)
+static unsigned int
+check_arg (char *c, int *has_space)
{
- int space = 0;
unsigned int size = 0;
while (*c)
{
- if (*c == '\\' || *c == '\'' || *c == '"')
- size++;
- else if (*c == ' ')
- space = 1;
-
+ if (*c == ' ')
+ {
+ if (*has_space == 0)
+ {
+ *has_space = 1;
+ size += 2;
+ }
+ }
size++;
c++;
}
- if (space)
- size += 2;
-
- if (has_space)
- *has_space = space;
-
- return size;
+ /* For separator space or NULL. */
+ return size + 1;
}
-unsigned int grub_loader_cmdline_size (int argc, char *argv[])
+unsigned int
+grub_loader_cmdline_size (int argc, char *argv[])
{
int i;
unsigned int size = 0;
for (i = 0; i < argc; i++)
- {
- size += check_arg (argv[i], 0);
- size++; /* Separator space or NULL. */
- }
+ size += check_arg (argv[i], 0);
- if (size == 0)
- size = 1;
-
- return size;
+ return size ? size : 1;
}
grub_err_t
grub_create_loader_cmdline (int argc, char *argv[], char *buf,
- grub_size_t size, enum grub_verify_string_type type)
+ grub_size_t size,
+ enum grub_verify_string_type type)
{
int i, space;
unsigned int arg_size;
@@ -73,8 +67,8 @@ grub_create_loader_cmdline (int argc, char *argv[],
char *buf,
for (i = 0; i < argc; i++)
{
c = argv[i];
- arg_size = check_arg(argv[i], &space);
- arg_size++; /* Separator space or NULL. */
+ space = 0;
+ arg_size = check_arg (argv[i], &space);
if (size < arg_size)
break;
@@ -86,11 +80,7 @@ grub_create_loader_cmdline (int argc, char *argv[],
char *buf,
while (*c)
{
- if (*c == '\\' || *c == '\'' || *c == '"')
- *buf++ = '\\';
-
- *buf++ = *c;
- c++;
+ *buf++ = *c++;
}
if (space)
--
2.50.1
Sending this for completeness, some hunks were missed in second patch in
all revisions. In case if someone needs this.
--
Shedi
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel