Received: from list by lists.gnu.org with archive (Exim 4.71) id 1h9t9T-0001pV-P6 for mharc-grub-devel@gnu.org; Fri, 29 Mar 2019 11:10:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9t9R-0001nR-92 for grub-devel@gnu.org; Fri, 29 Mar 2019 11:10:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9t9O-00050M-Bi for grub-devel@gnu.org; Fri, 29 Mar 2019 11:10:36 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:58764) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9t9M-0004th-6w for grub-devel@gnu.org; Fri, 29 Mar 2019 11:10:32 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x2TF4d4r054286; Fri, 29 Mar 2019 15:10:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=LImO+AD+LJGNJBqAS49r2deIrcEq5Mj4s/w2BvjQvpw=; b=I5128GLxG8CrwzQF3lWsiNRM8mkseuNB9h8GHsgu+QxPA+fd48Yfkwx3UkDHPSaakHPS xFDz6cDKEBHK7wCOzydGDCRz39EtcbVHQrHcqkFv57DegMwudm7JM5B+eg0MTyjbVa9/ IZbJzHO1LWOEqVGdoLaTKL6ARggEvZPw/G8Q473PKn4ohrsSqx8v6rP8OJtddzeAfPjY FvBP9Fn71Z4cnWVvNN/aZy3qkjRJ8w5jjXKGi1UWjb12En8PP27asA9uec7+dpwXpY1t Y4w+/ni04QZr14TesmZRwC1jR7Iz3B90tE42mNI2wDRKQv7TwmZ5ySb0lgZHxzdb+Ao/ SQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2re6g1d1nj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Mar 2019 15:10:15 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x2TFAENr024313 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 29 Mar 2019 15:10:14 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x2TFACXF012176; Fri, 29 Mar 2019 15:10:13 GMT Received: from tomti.i.net-space.pl (/10.175.169.172) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 29 Mar 2019 08:10:12 -0700 From: Daniel Kiper To: grub-devel@gnu.org Cc: andrew.jeddeloh@coreos.com, eric.snowberg@oracle.com, konrad.wilk@oracle.com, phcoder@gmail.com, ross.philipson@oracle.com Subject: [PATCH] loader/i386/linux: Calculate the setup_header length Date: Fri, 29 Mar 2019 16:09:54 +0100 Message-Id: <20190329150954.8099-1-daniel.kiper@oracle.com> X-Mailer: git-send-email 2.11.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9211 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903290108 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Mar 2019 15:10:38 -0000 From: Andrew Jeddeloh Previously the setup_header length was just assumed to be the size of the linux_kernel_params struct. The linux x86 32-bit boot protocol says that the size of the linux_i386_kernel_header is 0x202 + the byte value at 0x201 in the linux_i386_kernel_header. Calculate the size of the header, rather than assume it is the size of the linux_kernel_params struct. Additionally, add some required members to the linux_kernel_params struct and align the content of linux_i386_kernel_header struct with it. New members naming was taken directly from Linux kernel source. linux_kernel_params and linux_i386_kernel_header structs require more cleanup. However, this is not urgent, so, let's do this after release. Just in case... Signed-off-by: Andrew Jeddeloh Signed-off-by: Daniel Kiper --- grub-core/loader/i386/linux.c | 16 +++++++++++++++- include/grub/i386/linux.h | 14 ++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index b6015913b..73e15a90f 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -767,7 +767,21 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), linux_params.kernel_alignment = (1 << align); linux_params.ps_mouse = linux_params.padding10 = 0; - len = sizeof (linux_params) - sizeof (lh); + /* + * The Linux 32-bit boot protocol defines the setup header size + * to be 0x202 + the byte value at 0x201. + */ + len = 0x202 + *((char *) &linux_params.jump + 1); + + /* Verify the struct is big enough so we do not write past the end. */ + if (len > (char *) &linux_params.edd_mbr_sig_buffer - (char *) &linux_params) { + grub_error (GRUB_ERR_BAD_OS, "Linux setup header too big"); + goto fail; + } + + /* We've already read lh so there is no need to read it second time. */ + len -= sizeof(lh); + if (grub_file_read (file, (char *) &linux_params + sizeof (lh), len) != len) { if (!grub_errno) diff --git a/include/grub/i386/linux.h b/include/grub/i386/linux.h index a96059311..ce30e7fb0 100644 --- a/include/grub/i386/linux.h +++ b/include/grub/i386/linux.h @@ -46,6 +46,9 @@ #define VIDEO_CAPABILITY_SKIP_QUIRKS (1 << 0) #define VIDEO_CAPABILITY_64BIT_BASE (1 << 1) /* Frame buffer base is 64-bit. */ +/* Maximum number of MBR signatures to store. */ +#define EDD_MBR_SIG_MAX 16 + #ifdef __x86_64__ #define GRUB_LINUX_EFI_SIGNATURE \ @@ -142,6 +145,7 @@ struct linux_i386_kernel_header grub_uint64_t setup_data; grub_uint64_t pref_address; grub_uint32_t init_size; + grub_uint32_t handover_offset; } GRUB_PACKED; /* Boot parameters for Linux based on 2.6.12. This is used by the setup @@ -273,6 +277,7 @@ struct linux_kernel_params grub_uint8_t padding9[0x1f1 - 0x1e9]; + /* Linux setup header copy - BEGIN. */ grub_uint8_t setup_sects; /* The size of the setup in sectors */ grub_uint16_t root_flags; /* If the root is mounted readonly */ grub_uint16_t syssize; /* obsolete */ @@ -311,9 +316,14 @@ struct linux_kernel_params grub_uint32_t payload_offset; grub_uint32_t payload_length; grub_uint64_t setup_data; - grub_uint8_t pad2[120]; /* 258 */ + grub_uint64_t pref_address; + grub_uint32_t init_size; + grub_uint32_t handover_offset; + /* Linux setup header copy - END. */ + + grub_uint8_t _pad7[40]; + grub_uint32_t edd_mbr_sig_buffer[EDD_MBR_SIG_MAX]; /* 290 */ struct grub_e820_mmap e820_map[(0x400 - 0x2d0) / 20]; /* 2d0 */ - } GRUB_PACKED; #endif /* ! ASM_FILE */ -- 2.11.0