Skip to content

Commit f142010

Browse files
mhartmayhuth
authored andcommitted
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. Reported-by: Sven Schnelle <[email protected]> Signed-off-by: Marc Hartmayer <[email protected]> Message-Id: <[email protected]> Reviewed-by: Christian Borntraeger <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> [thuth: Adjusted format specifier for size_t] Signed-off-by: Thomas Huth <[email protected]>
1 parent bfd9a76 commit f142010

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

hw/s390x/ipl.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#define KERN_IMAGE_START 0x010000UL
3939
#define LINUX_MAGIC_ADDR 0x010008UL
4040
#define KERN_PARM_AREA 0x010480UL
41+
#define KERN_PARM_AREA_SIZE 0x000380UL
4142
#define INITRD_START 0x800000UL
4243
#define INITRD_PARM_START 0x010408UL
4344
#define PARMFILE_START 0x001000UL
@@ -190,10 +191,19 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp)
190191
* loader) and it won't work. For this case we force it to 0x10000, too.
191192
*/
192193
if (pentry == KERN_IMAGE_START || pentry == 0x800) {
193-
char *parm_area = rom_ptr(KERN_PARM_AREA, strlen(ipl->cmdline) + 1);
194+
size_t cmdline_size = strlen(ipl->cmdline) + 1;
195+
char *parm_area = rom_ptr(KERN_PARM_AREA, cmdline_size);
196+
194197
ipl->start_addr = KERN_IMAGE_START;
195198
/* Overwrite parameters in the kernel image, which are "rom" */
196199
if (parm_area) {
200+
if (cmdline_size > KERN_PARM_AREA_SIZE) {
201+
error_setg(errp,
202+
"kernel command line exceeds maximum size: %zu > %lu",
203+
cmdline_size, KERN_PARM_AREA_SIZE);
204+
return;
205+
}
206+
197207
strcpy(parm_area, ipl->cmdline);
198208
}
199209
} else {

0 commit comments

Comments
 (0)