From nobody Thu May 7 20:14:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9742C433EF for ; Thu, 19 May 2022 10:58:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237129AbiESK6I (ORCPT ); Thu, 19 May 2022 06:58:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237103AbiESK5u (ORCPT ); Thu, 19 May 2022 06:57:50 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E492AF318; Thu, 19 May 2022 03:57:48 -0700 (PDT) Date: Thu, 19 May 2022 10:57:45 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1652957866; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J5hF/bHk1y8swl6RY8ccIcAYUWyxFzuRI8+1R2iO9g0=; b=4wvYumcfH78Z8NYbMz7VHfcbmVSzcdm5n+Yg56nRYAm+6uuMOP0HYsGxCOWWBta8p6I62m yqO04Mb3azHXwQF4HBzqzzvAKPZKK80uYgJtbE7JvZ6kLt8F8x2R3dHESkf7X6E4qIiRaP 98WqOX5GuMoZTXC3VnC/3ygXV02BQJm/ado4Rq0x1apZLx5PD5gxEbQvOi/D5atCICvsmE 4cIgaVmxeEcYi/6XHmRsmxwsT3MbKzjenbJvq5ZcqnNDZed4AQz8glfKpuZ97TbnN2pqzs 9qHiZgk0llSPGqQwF2zOmArUxANG1TyitAz2CmwGe52Ou+URkXxUZVqPY3FaMw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1652957866; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J5hF/bHk1y8swl6RY8ccIcAYUWyxFzuRI8+1R2iO9g0=; b=UiL9NX0j831CVo3cMDeBr1OOaIuCWeW0dCfFMBCDj6USw3T2n6Ar3V+Nt7sfqiBfU82ONk RNOOcLWYHXXVmCAw== From: "tip-bot2 for Kees Cook" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/build] x86/boot: Wrap literal addresses in absolute_pointer() Cc: Kees Cook , Borislav Petkov , Guenter Roeck , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220227195918.705219-1-keescook@chromium.org> References: <20220227195918.705219-1-keescook@chromium.org> MIME-Version: 1.0 Message-ID: <165295786522.4207.8444671821505639816.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/build branch of tip: Commit-ID: aeb84412037b89e06f45e382f044da6f200e12f8 Gitweb: https://git.kernel.org/tip/aeb84412037b89e06f45e382f044da6f2= 00e12f8 Author: Kees Cook AuthorDate: Sun, 27 Feb 2022 11:59:18 -08:00 Committer: Borislav Petkov CommitterDate: Thu, 19 May 2022 12:47:30 +02:00 x86/boot: Wrap literal addresses in absolute_pointer() GCC 11 (incorrectly[1]) assumes that literal values cast to (void *) should be treated like a NULL pointer with an offset, and raises diagnostics when doing bounds checking under -Warray-bounds. GCC 12 got "smarter" about finding these: In function 'rdfs8', inlined from 'vga_recalc_vertical' at /srv/code/arch/x86/boot/video-m= ode.c:124:29, inlined from 'set_mode' at /srv/code/arch/x86/boot/video-mode.c:163:3: /srv/code/arch/x86/boot/boot.h:114:9: warning: array subscript 0 is outsi= de array bounds of 'u8[0]' {aka 'unsigned char[]'} [-Warray-bounds] 114 | asm volatile("movb %%fs:%1,%0" : "=3Dq" (v) : "m" (*(u8 *= )addr)); | ^~~ This has been solved in other places[2] already by using the recently added absolute_pointer() macro. Do the same here. [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99578 [2] https://lore.kernel.org/all/20210912160149.2227137-1-linux@roeck-us.n= et/ Signed-off-by: Kees Cook Signed-off-by: Borislav Petkov Reviewed-by: Guenter Roeck Link: https://lore.kernel.org/r/20220227195918.705219-1-keescook@chromium.o= rg --- arch/x86/boot/boot.h | 36 ++++++++++++++++++++++++------------ arch/x86/boot/main.c | 2 +- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h index 34c9dbb..686a9d7 100644 --- a/arch/x86/boot/boot.h +++ b/arch/x86/boot/boot.h @@ -110,66 +110,78 @@ typedef unsigned int addr_t; =20 static inline u8 rdfs8(addr_t addr) { + u8 *ptr =3D (u8 *)absolute_pointer(addr); u8 v; - asm volatile("movb %%fs:%1,%0" : "=3Dq" (v) : "m" (*(u8 *)addr)); + asm volatile("movb %%fs:%1,%0" : "=3Dq" (v) : "m" (*ptr)); return v; } static inline u16 rdfs16(addr_t addr) { + u16 *ptr =3D (u16 *)absolute_pointer(addr); u16 v; - asm volatile("movw %%fs:%1,%0" : "=3Dr" (v) : "m" (*(u16 *)addr)); + asm volatile("movw %%fs:%1,%0" : "=3Dr" (v) : "m" (*ptr)); return v; } static inline u32 rdfs32(addr_t addr) { + u32 *ptr =3D (u32 *)absolute_pointer(addr); u32 v; - asm volatile("movl %%fs:%1,%0" : "=3Dr" (v) : "m" (*(u32 *)addr)); + asm volatile("movl %%fs:%1,%0" : "=3Dr" (v) : "m" (*ptr)); return v; } =20 static inline void wrfs8(u8 v, addr_t addr) { - asm volatile("movb %1,%%fs:%0" : "+m" (*(u8 *)addr) : "qi" (v)); + u8 *ptr =3D (u8 *)absolute_pointer(addr); + asm volatile("movb %1,%%fs:%0" : "+m" (*ptr) : "qi" (v)); } static inline void wrfs16(u16 v, addr_t addr) { - asm volatile("movw %1,%%fs:%0" : "+m" (*(u16 *)addr) : "ri" (v)); + u16 *ptr =3D (u16 *)absolute_pointer(addr); + asm volatile("movw %1,%%fs:%0" : "+m" (*ptr) : "ri" (v)); } static inline void wrfs32(u32 v, addr_t addr) { - asm volatile("movl %1,%%fs:%0" : "+m" (*(u32 *)addr) : "ri" (v)); + u32 *ptr =3D (u32 *)absolute_pointer(addr); + asm volatile("movl %1,%%fs:%0" : "+m" (*ptr) : "ri" (v)); } =20 static inline u8 rdgs8(addr_t addr) { + u8 *ptr =3D (u8 *)absolute_pointer(addr); u8 v; - asm volatile("movb %%gs:%1,%0" : "=3Dq" (v) : "m" (*(u8 *)addr)); + asm volatile("movb %%gs:%1,%0" : "=3Dq" (v) : "m" (*ptr)); return v; } static inline u16 rdgs16(addr_t addr) { + u16 *ptr =3D (u16 *)absolute_pointer(addr); u16 v; - asm volatile("movw %%gs:%1,%0" : "=3Dr" (v) : "m" (*(u16 *)addr)); + asm volatile("movw %%gs:%1,%0" : "=3Dr" (v) : "m" (*ptr)); return v; } static inline u32 rdgs32(addr_t addr) { + u32 *ptr =3D (u32 *)absolute_pointer(addr); u32 v; - asm volatile("movl %%gs:%1,%0" : "=3Dr" (v) : "m" (*(u32 *)addr)); + asm volatile("movl %%gs:%1,%0" : "=3Dr" (v) : "m" (*ptr)); return v; } =20 static inline void wrgs8(u8 v, addr_t addr) { - asm volatile("movb %1,%%gs:%0" : "+m" (*(u8 *)addr) : "qi" (v)); + u8 *ptr =3D (u8 *)absolute_pointer(addr); + asm volatile("movb %1,%%gs:%0" : "+m" (*ptr) : "qi" (v)); } static inline void wrgs16(u16 v, addr_t addr) { - asm volatile("movw %1,%%gs:%0" : "+m" (*(u16 *)addr) : "ri" (v)); + u16 *ptr =3D (u16 *)absolute_pointer(addr); + asm volatile("movw %1,%%gs:%0" : "+m" (*ptr) : "ri" (v)); } static inline void wrgs32(u32 v, addr_t addr) { - asm volatile("movl %1,%%gs:%0" : "+m" (*(u32 *)addr) : "ri" (v)); + u32 *ptr =3D (u32 *)absolute_pointer(addr); + asm volatile("movl %1,%%gs:%0" : "+m" (*ptr) : "ri" (v)); } =20 /* Note: these only return true/false, not a signed return value! */ diff --git a/arch/x86/boot/main.c b/arch/x86/boot/main.c index e3add85..c421af5 100644 --- a/arch/x86/boot/main.c +++ b/arch/x86/boot/main.c @@ -33,7 +33,7 @@ static void copy_boot_params(void) u16 cl_offset; }; const struct old_cmdline * const oldcmd =3D - (const struct old_cmdline *)OLD_CL_ADDRESS; + absolute_pointer(OLD_CL_ADDRESS); =20 BUILD_BUG_ON(sizeof(boot_params) !=3D 4096); memcpy(&boot_params.hdr, &hdr, sizeof(hdr));