Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5236614ybl; Tue, 27 Aug 2019 01:18:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwGegRoLVxoRWZIn8sg5C9oBKtPBdpFD/2/PR5rSWZKnQKmP9MwNQSSM0WByKcVSuRWpbrb X-Received: by 2002:a63:ed55:: with SMTP id m21mr20203947pgk.343.1566893909116; Tue, 27 Aug 2019 01:18:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566893909; cv=none; d=google.com; s=arc-20160816; b=DHaFxHOC0dmRj/4uLjW1OLlN5L610Ddox8NrmYqYJMrU1WAROv/3FmF4hMy/Ku46xi pTobW/TEhf3vk8vYbJXpJ3y13xWCAQ2Bnrn/TExVBpQWhjz6Z+pHaGwYtGuJgYHFZSqf SMtCssaLerTgvR2IV/2+63v0SYXZR2ZqnHKNJcuNFg4LSb5Vc3N1dL98v/i/ZmfEs54W wSdqljmF2gIYdxYn4FaavPe3QP4zdJnAPX0HO7ENR0fdD3VgWDwzJ4vLcUJKohlQ4P79 H/JXJt6drMYLkUNulKJvA1vAllrAirVeeytTnZiMry+0vwNn7A6cjCNyq1tdB8ds3g8b 3VPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FupI/l1ozBayTYWebKVzY3d7xT49ijJB2p4Nnacbt78=; b=BMCXdDk+brw27DqONLVOXWYydRNle2XTfcF9b7oqV2frZ3gCHDr2iG1d72Q0SVZ/My z0l2gZGe4Hqw1Lm+R27oMJIP20pETa+gg/YZQyvJmodP+PK569q2q9I8nZZwKnrMxo0k Phvliax9l4a/61wINI3IdmDw1YX7xNui/ukiFTZSkj+qZxUU5HI3TgQGRqlB8IHb/thZ dmpVIa1RjuEm5OtbtL+QO7OilKWpzKiITX/6pzL7IFn3uXAms75fxpU673eQHT6jl0/R urmBQnrPdTriBPAoVb49CKM6nlwAfYFNHLYSv/NJUJ9O9q7G4Rfp21LNAaLkP8RMPpyi p4bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YYzMhsX8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6si11019789pge.44.2019.08.27.01.18.13; Tue, 27 Aug 2019 01:18:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YYzMhsX8; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729989AbfH0IQg (ORCPT + 99 others); Tue, 27 Aug 2019 04:16:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:45236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729128AbfH0Hxm (ORCPT ); Tue, 27 Aug 2019 03:53:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 733C8206BA; Tue, 27 Aug 2019 07:53:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566892421; bh=AQEVTXZQxGBQ9YFF+5HCo/xdoTw+hiPIi6RUAuY8E94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YYzMhsX8QHxNmvqbH61fuyV7PCv1FFnFwFTnU6jtfXbF7Ijbb3whSrbzMlvdYFzy2 uVGHFr1cV99+6zxjOGP/e4dL0PAVUrcSqTR9TDdq8fUZ8asrbxABd1+2COYtPTjHOY uSZvgqtfnzUcVC+8f8oNTHUq4YY5pCXha3+UtMDQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , "H. Peter Anvin" , John Hubbard Subject: [PATCH 4.14 47/62] x86/boot: Save fields explicitly, zero out everything else Date: Tue, 27 Aug 2019 09:50:52 +0200 Message-Id: <20190827072703.235192413@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190827072659.803647352@linuxfoundation.org> References: <20190827072659.803647352@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Hubbard commit a90118c445cc7f07781de26a9684d4ec58bfcfd1 upstream. Recent gcc compilers (gcc 9.1) generate warnings about an out of bounds memset, if the memset goes accross several fields of a struct. This generated a couple of warnings on x86_64 builds in sanitize_boot_params(). Fix this by explicitly saving the fields in struct boot_params that are intended to be preserved, and zeroing all the rest. [ tglx: Tagged for stable as it breaks the warning free build there as well ] Suggested-by: Thomas Gleixner Suggested-by: H. Peter Anvin Signed-off-by: John Hubbard Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20190731054627.5627-2-jhubbard@nvidia.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/bootparam_utils.h | 60 +++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 13 deletions(-) --- a/arch/x86/include/asm/bootparam_utils.h +++ b/arch/x86/include/asm/bootparam_utils.h @@ -18,6 +18,20 @@ * Note: efi_info is commonly left uninitialized, but that field has a * private magic, so it is better to leave it unchanged. */ + +#define sizeof_mbr(type, member) ({ sizeof(((type *)0)->member); }) + +#define BOOT_PARAM_PRESERVE(struct_member) \ + { \ + .start = offsetof(struct boot_params, struct_member), \ + .len = sizeof_mbr(struct boot_params, struct_member), \ + } + +struct boot_params_to_save { + unsigned int start; + unsigned int len; +}; + static void sanitize_boot_params(struct boot_params *boot_params) { /* @@ -36,19 +50,39 @@ static void sanitize_boot_params(struct */ if (boot_params->sentinel) { /* fields in boot_params are left uninitialized, clear them */ - memset(&boot_params->ext_ramdisk_image, 0, - (char *)&boot_params->efi_info - - (char *)&boot_params->ext_ramdisk_image); - memset(&boot_params->kbd_status, 0, - (char *)&boot_params->hdr - - (char *)&boot_params->kbd_status); - memset(&boot_params->_pad7[0], 0, - (char *)&boot_params->edd_mbr_sig_buffer[0] - - (char *)&boot_params->_pad7[0]); - memset(&boot_params->_pad8[0], 0, - (char *)&boot_params->eddbuf[0] - - (char *)&boot_params->_pad8[0]); - memset(&boot_params->_pad9[0], 0, sizeof(boot_params->_pad9)); + static struct boot_params scratch; + char *bp_base = (char *)boot_params; + char *save_base = (char *)&scratch; + int i; + + const struct boot_params_to_save to_save[] = { + BOOT_PARAM_PRESERVE(screen_info), + BOOT_PARAM_PRESERVE(apm_bios_info), + BOOT_PARAM_PRESERVE(tboot_addr), + BOOT_PARAM_PRESERVE(ist_info), + BOOT_PARAM_PRESERVE(hd0_info), + BOOT_PARAM_PRESERVE(hd1_info), + BOOT_PARAM_PRESERVE(sys_desc_table), + BOOT_PARAM_PRESERVE(olpc_ofw_header), + BOOT_PARAM_PRESERVE(efi_info), + BOOT_PARAM_PRESERVE(alt_mem_k), + BOOT_PARAM_PRESERVE(scratch), + BOOT_PARAM_PRESERVE(e820_entries), + BOOT_PARAM_PRESERVE(eddbuf_entries), + BOOT_PARAM_PRESERVE(edd_mbr_sig_buf_entries), + BOOT_PARAM_PRESERVE(edd_mbr_sig_buffer), + BOOT_PARAM_PRESERVE(e820_table), + BOOT_PARAM_PRESERVE(eddbuf), + }; + + memset(&scratch, 0, sizeof(scratch)); + + for (i = 0; i < ARRAY_SIZE(to_save); i++) { + memcpy(save_base + to_save[i].start, + bp_base + to_save[i].start, to_save[i].len); + } + + memcpy(boot_params, save_base, sizeof(*boot_params)); } }