From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A907AC32753 for ; Wed, 31 Jul 2019 05:46:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6F33B2067D for ; Wed, 31 Jul 2019 05:46:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="myVCrKCs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726992AbfGaFqf (ORCPT ); Wed, 31 Jul 2019 01:46:35 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:44971 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725290AbfGaFqf (ORCPT ); Wed, 31 Jul 2019 01:46:35 -0400 Received: by mail-pg1-f195.google.com with SMTP id i18so31348501pgl.11 for ; Tue, 30 Jul 2019 22:46:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p6QGy8H2ePkXvIW5OjCWCW9I4ubm5QJ73F/M0Ennkq8=; b=myVCrKCsUFUksjU5eNgjiIaA9FiRUzXksa0sJK+WMZU4MNuZfbc/0b5ZilY2qgy1/l GLkSUm/uHbtvGQsfDM3NPdt6ChOEMfNd92HNAN9hpvivQhK1C6KW4NXuiWHpu6IMzujz m8cwwClKrpq+JIe0qk7yvJQo51TrzIOQpErU5Q1Sj/x+mtlOHOHWqRIcbfHCuLo1V3yJ 2yqeiFIVJgG5snASpyKwboXglUUhh5yNXJ4XvAbX3MpBx2u7M0KEhp2ISp/smboasPls qOIZPjCLDvcEfxPQsLcr3Qk7EgYsGymFH1negtqSoUWN8IRrgSJAs6ZjGHP/4kGNWvx0 lz/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p6QGy8H2ePkXvIW5OjCWCW9I4ubm5QJ73F/M0Ennkq8=; b=R+ARxsoC2SlHH7ICosK6dmP1791+Iq/VtCHc+sLZTMNzCsZ2ozwwPbL82MlLB06iS4 JiiMSDgNV4XRFiikhDUvf0rTnoUR9mpxzaFX6qvkciNBqfvU0wOfQHpq2ThazV2k6bM6 ONfwCdPAZ8cgNdwllr1tavq+z7JsULGwAfccZpSdtunZpfuuH9bn1haCwt9Wj9Pcd96i yaRK6uJHqb7IP86yCfVYwvbOrwXGTJQESKmcVmbWU0+oX05Zn8NswCLuaA20/KnB4WoD pMAQAmbj9resCuECBG4dJs4Ca6pHlyWN7Ahtzn94kp4QPtRk+GfWkchn7PzeU0b+Gsj4 GEig== X-Gm-Message-State: APjAAAUdvbbIPinHRsiUMb2z+QYwfDGqc6YzzuZMzPugbDeUqwE+PhAJ cRTnaMF5YkvhBUZxGaJ4MC0= X-Google-Smtp-Source: APXvYqydX2FUe1au42qKaH66YrtwLMR+lMYDdn0iHnkcuMcXIRsHv+6j70Y5e1qxgCLf9viuONJPsQ== X-Received: by 2002:a63:e907:: with SMTP id i7mr110370211pgh.84.1564551994819; Tue, 30 Jul 2019 22:46:34 -0700 (PDT) Received: from blueforge.nvidia.com (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id k70sm648127pje.14.2019.07.30.22.46.34 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 30 Jul 2019 22:46:34 -0700 (PDT) From: john.hubbard@gmail.com X-Google-Original-From: jhubbard@nvidia.com To: "H . Peter Anvin" Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, LKML , John Hubbard Subject: [PATCH v2] x86/boot: save fields explicitly, zero out everything else Date: Tue, 30 Jul 2019 22:46:27 -0700 Message-Id: <20190731054627.5627-2-jhubbard@nvidia.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190731054627.5627-1-jhubbard@nvidia.com> References: <20190731054627.5627-1-jhubbard@nvidia.com> MIME-Version: 1.0 X-NVConfidentiality: public 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 Recent gcc compilers (gcc 9.1) generate warnings about an out of bounds memset, if you trying memset across several fields of a struct. This generated a couple of warnings on x86_64 builds. Fix this by explicitly saving the fields in struct boot_params that are intended to be preserved, and zeroing all the rest. Suggested-by: Thomas Gleixner Suggested-by: H. Peter Anvin Signed-off-by: John Hubbard --- arch/x86/include/asm/bootparam_utils.h | 62 +++++++++++++++++++------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/arch/x86/include/asm/bootparam_utils.h b/arch/x86/include/asm/bootparam_utils.h index 101eb944f13c..514aee24b8de 100644 --- 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) { /* @@ -35,21 +49,39 @@ static void sanitize_boot_params(struct boot_params *boot_params) * problems again. */ if (boot_params->sentinel) { - /* fields in boot_params are left uninitialized, clear them */ - boot_params->acpi_rsdp_addr = 0; - 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(acpi_rsdp_addr), + 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)); } } -- 2.22.0