Skip to contentSkip to conversation

s390x/ipl: check kernel command line size

PATCH In review Marc Hartmayer 4 participants 6 messages Oct 6, 2021 – Oct 12, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 s390x/ipl: check kernel command line size

Check if the provided kernel command line exceeds the maximum size of the s390x Linux kernel command line size, which is 896 bytes.

---
 hw/s390x/ipl.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +11 -1
index 1821c6faeef3..a58ea58cc736 100644
@@ -38,6 +38,7 @@
 #define KERN_IMAGE_START                0x010000UL
 #define LINUX_MAGIC_ADDR                0x010008UL
 #define KERN_PARM_AREA                  0x010480UL
+#define KERN_PARM_AREA_SIZE             0x000380UL
 #define INITRD_START                    0x800000UL
 #define INITRD_PARM_START               0x010408UL
 #define PARMFILE_START                  0x001000UL
@@ -190,10 +191,19 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp)
          * loader) and it won't work. For this case we force it to 0x10000, too.
          */
         if (pentry == KERN_IMAGE_START || pentry == 0x800) {
-            char *parm_area = rom_ptr(KERN_PARM_AREA, strlen(ipl->cmdline) + 1);
+            size_t cmdline_size = strlen(ipl->cmdline) + 1;
+            char *parm_area = rom_ptr(KERN_PARM_AREA, cmdline_size);
+
             ipl->start_addr = KERN_IMAGE_START;
             /* Overwrite parameters in the kernel image, which are "rom" */
             if (parm_area) {
+                if (cmdline_size > KERN_PARM_AREA_SIZE) {
+                    error_setg(errp,
+                               "kernel command line exceeds maximum size: %lu > %lu",
+                               cmdline_size, KERN_PARM_AREA_SIZE);
+                    return;
+                }
+
                 strcpy(parm_area, ipl->cmdline);
             }
         } else {
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw

Am 06.10.21 um 11:26 schrieb Marc Hartmayer:

Quoted 5 lines

Check if the provided kernel command line exceeds the maximum size of the s390x Linux kernel command line size, which is 896 bytes.

Quoted 38 lines
---
  hw/s390x/ipl.c | 12 +++++++++++-
  1 file changed, 11 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +11 -1
index 1821c6faeef3..a58ea58cc736 100644
@@ -38,6 +38,7 @@
  #define KERN_IMAGE_START                0x010000UL
  #define LINUX_MAGIC_ADDR                0x010008UL
  #define KERN_PARM_AREA                  0x010480UL
+#define KERN_PARM_AREA_SIZE             0x000380UL
  #define INITRD_START                    0x800000UL
  #define INITRD_PARM_START               0x010408UL
  #define PARMFILE_START                  0x001000UL
@@ -190,10 +191,19 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp)
           * loader) and it won't work. For this case we force it to 0x10000, too.
           */
          if (pentry == KERN_IMAGE_START || pentry == 0x800) {
-            char *parm_area = rom_ptr(KERN_PARM_AREA, strlen(ipl->cmdline) + 1);
+            size_t cmdline_size = strlen(ipl->cmdline) + 1;
+            char *parm_area = rom_ptr(KERN_PARM_AREA, cmdline_size);
+
              ipl->start_addr = KERN_IMAGE_START;
              /* Overwrite parameters in the kernel image, which are "rom" */
              if (parm_area) {
+                if (cmdline_size > KERN_PARM_AREA_SIZE) {
+                    error_setg(errp,
+                               "kernel command line exceeds maximum size: %lu > %lu",
+                               cmdline_size, KERN_PARM_AREA_SIZE);
+                    return;
+                }
+
                  strcpy(parm_area, ipl->cmdline);
              }
          } else {
#2 lore raw
In reply to Marc Hartmayer
Quoted 25 lines · Marc Hartmayer

Check if the provided kernel command line exceeds the maximum size of the s390x Linux kernel command line size, which is 896 bytes.

---
  hw/s390x/ipl.c | 12 +++++++++++-
  1 file changed, 11 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +1 -0
index 1821c6faeef3..a58ea58cc736 100644
@@ -38,6 +38,7 @@
  #define KERN_IMAGE_START                0x010000UL
  #define LINUX_MAGIC_ADDR                0x010008UL
  #define KERN_PARM_AREA                  0x010480UL
+#define KERN_PARM_AREA_SIZE             0x000380UL
  #define INITRD_START                    0x800000UL
  #define INITRD_PARM_START               0x010408UL
  #define PARMFILE_START                  0x001000UL
@@ -190,10 +191,19 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp)
           * loader) and it won't work. For this case we force it to 0x10000, too.
           */
          if (pentry == KERN_IMAGE_START || pentry == 0x800) {

hw/s390x/ipl.c static void s390_ipl_realize(DeviceState *dev, Error **errp) · line 202

Quoted 10 lines
hw/s390x/ipl.c +6 -1
-            char *parm_area = rom_ptr(KERN_PARM_AREA, strlen(ipl->cmdline) + 1);
+            size_t cmdline_size = strlen(ipl->cmdline) + 1;
+            char *parm_area = rom_ptr(KERN_PARM_AREA, cmdline_size);
+
              ipl->start_addr = KERN_IMAGE_START;
              /* Overwrite parameters in the kernel image, which are "rom" */
              if (parm_area) {
+                if (cmdline_size > KERN_PARM_AREA_SIZE) {
+                    error_setg(errp,
+                               "kernel command line exceeds maximum size: %lu > %lu",

I think the first %lu should be %zd instead?

Apart from that, the patch looks fine to me... so if you agree, I can fix that up when picking up the patch.

Thomas

Quoted 8 lines
hw/s390x/ipl.c +4 -0
+                               cmdline_size, KERN_PARM_AREA_SIZE);
+                    return;
+                }
+
                  strcpy(parm_area, ipl->cmdline);
              }
          } else {
#3 lore raw
Quoted 30 lines · Thomas Huth
Quoted 29 lines · Marc Hartmayer

Check if the provided kernel command line exceeds the maximum size of the s390x Linux kernel command line size, which is 896 bytes.

---
  hw/s390x/ipl.c | 12 +++++++++++-
  1 file changed, 11 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +4 -1
index 1821c6faeef3..a58ea58cc736 100644
@@ -38,6 +38,7 @@
  #define KERN_IMAGE_START                0x010000UL
  #define LINUX_MAGIC_ADDR                0x010008UL
  #define KERN_PARM_AREA                  0x010480UL
+#define KERN_PARM_AREA_SIZE             0x000380UL
  #define INITRD_START                    0x800000UL
  #define INITRD_PARM_START               0x010408UL
  #define PARMFILE_START                  0x001000UL
@@ -190,10 +191,19 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp)
           * loader) and it won't work. For this case we force it to 0x10000, too.
           */
          if (pentry == KERN_IMAGE_START || pentry == 0x800) {
-            char *parm_area = rom_ptr(KERN_PARM_AREA, strlen(ipl->cmdline) + 1);
+            size_t cmdline_size = strlen(ipl->cmdline) + 1;
+            char *parm_area = rom_ptr(KERN_PARM_AREA, cmdline_size);
+
Quoted 8 lines

hw/s390x/ipl.c static void s390_ipl_realize(DeviceState *dev, Error **errp) · line 202

Quoted 6 lines
hw/s390x/ipl.c +3 -0
              ipl->start_addr = KERN_IMAGE_START;
              /* Overwrite parameters in the kernel image, which are "rom" */
              if (parm_area) {
+                if (cmdline_size > KERN_PARM_AREA_SIZE) {
+                    error_setg(errp,
+                               "kernel command line exceeds maximum size: %lu > %lu",

I think the first %lu should be %zd instead?

Yep, makes sense - thanks!

Quoted 3 lines

Apart from that, the patch looks fine to me... so if you agree, I can fix that up when picking up the patch.

Thanks.

Quoted 13 lines

Thomas

Quoted 8 lines
hw/s390x/ipl.c +4 -0
+                               cmdline_size, KERN_PARM_AREA_SIZE);
+                    return;
+                }
+
                  strcpy(parm_area, ipl->cmdline);
              }
          } else {
Signature · 8 lines
Kind regards / Beste Grüße
   Marc Hartmayer

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Gregor Pillen 
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
#4 lore raw
In reply to Thomas Huth
Quoted 36 lines · Thomas Huth
Quoted 35 lines · Marc Hartmayer

Check if the provided kernel command line exceeds the maximum size of the s390x
Linux kernel command line size, which is 896 bytes.

---
  hw/s390x/ipl.c | 12 +++++++++++-

  1 file changed, 11 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +1 -0
index 1821c6faeef3..a58ea58cc736 100644
@@ -38,6 +38,7 @@
   #define KERN_IMAGE_START                0x010000UL
   #define LINUX_MAGIC_ADDR                0x010008UL
   #define KERN_PARM_AREA                  0x010480UL
+#define KERN_PARM_AREA_SIZE             0x000380UL
   #define INITRD_START                    0x800000UL
   #define INITRD_PARM_START               0x010408UL
   #define PARMFILE_START                  0x001000UL
@@ -190,10 +191,19 @@ static void s390_ipl_realize(DeviceState *dev,
 Error **errp)
            * loader) and it won't work. For this case we force it to

0x10000, too.
           */
          if (pentry == KERN_IMAGE_START || pentry == 0x800) { -            char *parm_area = rom_ptr(KERN_PARM_AREA, strlen(ipl->cmdline) + 1);
+            size_t cmdline_size = strlen(ipl->cmdline) + 1; +            char *parm_area = rom_ptr(KERN_PARM_AREA, cmdline_size); +
              ipl->start_addr = KERN_IMAGE_START;
              /* Overwrite parameters in the kernel image, which are

Quoted 8 lines
Quoted 6 lines

"rom" */
              if (parm_area) {
+                if (cmdline_size > KERN_PARM_AREA_SIZE) { +                    error_setg(errp,
+                               "kernel command line exceeds maximum
size: %lu > %lu",

I think the first %lu should be %zd instead?

%zu ;)

Quoted 5 lines

Apart from that, the patch looks fine to me... so if you agree, I can fix that up when picking up the patch.

 Thomas

#5 lore raw
Quoted 46 lines · Philippe Mathieu-Daudé
Quoted 36 lines · Thomas Huth
Quoted 35 lines · Marc Hartmayer

Check if the provided kernel command line exceeds the maximum size of the s390x
Linux kernel command line size, which is 896 bytes.

---
   hw/s390x/ipl.c | 12 +++++++++++-
   1 file changed, 11 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +1 -0
index 1821c6faeef3..a58ea58cc736 100644
@@ -38,6 +38,7 @@
   #define KERN_IMAGE_START                0x010000UL
   #define LINUX_MAGIC_ADDR                0x010008UL
   #define KERN_PARM_AREA                  0x010480UL
+#define KERN_PARM_AREA_SIZE             0x000380UL
   #define INITRD_START                    0x800000UL
   #define INITRD_PARM_START               0x010408UL
   #define PARMFILE_START                  0x001000UL
@@ -190,10 +191,19 @@ static void s390_ipl_realize(DeviceState *dev,
 Error **errp)
            * loader) and it won't work. For this case we force it to

0x10000, too.
           */
          if (pentry == KERN_IMAGE_START || pentry == 0x800) {
-            char *parm_area = rom_ptr(KERN_PARM_AREA, strlen(ipl->cmdline) + 1);
+            size_t cmdline_size = strlen(ipl->cmdline) + 1; +            char *parm_area = rom_ptr(KERN_PARM_AREA, cmdline_size); +
              ipl->start_addr = KERN_IMAGE_START;
              /* Overwrite parameters in the kernel image, which are

Quoted 8 lines
Quoted 6 lines

"rom" */
              if (parm_area) {
+                if (cmdline_size > KERN_PARM_AREA_SIZE) { +                    error_setg(errp,
+                               "kernel command line exceeds maximum
size: %lu > %lu",

I think the first %lu should be %zd instead?

Quoted 1 line

%zu ;)

All right, queued with %zu on my s390x-next branch:

https://gitlab.com/thuth/qemu/-/commits/s390x-next/

Thomas