s390/os_info: Fix array size in struct os_info
authorSven Schnelle <svens@linux.ibm.com>
Fri, 26 Apr 2024 06:02:06 +0000 (08:02 +0200)
committerAlexander Gordeev <agordeev@linux.ibm.com>
Mon, 29 Apr 2024 15:33:29 +0000 (17:33 +0200)
gcc's -Warray-bounds warned about an out-of-bounds access to
the entry array contained in struct os_info. This doesn't trigger
a bug right now because there's a large reserved space after the
array. Nevertheless fix this, and also add a BUILD_BUG_ON to make
sure struct os_info is always exactly on page in size.

Fixes: f4cac27dc0d6 ("s390/crash: Use old os_info to create PT_LOAD headers")
Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
arch/s390/include/asm/os_info.h
arch/s390/kernel/os_info.c

index dea2b37b635ed88eaaa032fb20ad2426bb6ef172..3ee9e8f5ceae7a1353673125048d08332aef7d34 100644 (file)
@@ -27,6 +27,7 @@
 #define OS_INFO_IMAGE_START    10
 #define OS_INFO_IMAGE_END      11
 #define OS_INFO_IMAGE_PHYS     12
+#define OS_INFO_MAX            13
 
 #define OS_INFO_FLAG_REIPL_CLEAR       (1UL << 0)
 
@@ -46,8 +47,8 @@ struct os_info {
        u16     version_minor;
        u64     crashkernel_addr;
        u64     crashkernel_size;
-       struct os_info_entry entry[10];
-       u8      reserved[3864];
+       struct os_info_entry entry[OS_INFO_MAX];
+       u8      reserved[3804];
 } __packed;
 
 void os_info_init(void);
index cb73860c048d2a582f5f7fdc95f74ac4848d3928..b695f980bbde030806925e6fce10969a69651ee5 100644 (file)
@@ -73,6 +73,7 @@ void __init os_info_init(void)
 {
        struct lowcore *abs_lc;
 
+       BUILD_BUG_ON(sizeof(struct os_info) != PAGE_SIZE);
        os_info.version_major = OS_INFO_VERSION_MAJOR;
        os_info.version_minor = OS_INFO_VERSION_MINOR;
        os_info.magic = OS_INFO_MAGIC;