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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98E6EC4167B for ; Wed, 29 Nov 2023 12:28:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iueIsB9R0indb8L9u0WxUe7G5ZRKp0F4Ab8cTVvlYcM=; b=s3xI3UF/RVa136 e35/iPXK/PPEturBectwcSiPE3CGEH+coDdmVfWh7D8vvltBRRSwFM8jkadHLJqQDV4BJVNGf1qVC 8unGpIn0rQdvy/Dj36lRCUfxBIq8jxx+PKK36APao2MP/QXH5vACbMCimrPMxBuWXXIIsHHq1xZ1m P+Z3cNXTYRwxr9Ea9cBymfeQnofsmNfMCtUyfOCHCCU+0vVmW6aM2/347dxHgC2Hgf1pewAVVMu2R QByDz0/rr1STZWxr3Cqgn/INW3Hzm1UWFcIyFENwmF181QXWdZgh4cFRC2gFv2PWhZwx0U5C70+I8 Xo6GjHVPthaq8E1t6ePQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r8JfW-008Jad-1J; Wed, 29 Nov 2023 12:27:54 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r8JfT-008JZW-0b for linux-arm-kernel@lists.infradead.org; Wed, 29 Nov 2023 12:27:52 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 1DADEB83A48; Wed, 29 Nov 2023 12:27:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BCF4C433C7; Wed, 29 Nov 2023 12:27:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701260868; bh=eeqdy4BvL+1XYyzuPvPu6LpMKadvirAJrOWDKblcc1U=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=d1TFDMTbMXdPLi5ADGEKfloM1xbpJBzPyk1JRpVQXkaP2vnm2W0nR3x/brhVyWcgd N3pAmiSyCi2U5lydjAzJnyrOYKi074FacOHGPTdzZEyPI0EZ0Y8Z/gDa9spgbolTs8 W2TfodS+LaZ9g63/CqVaidgtoPWk8VLIKUAj/6BtgjMAS0OkpnrxqPMjYRiuTxqMUe 6BgiB1lFod4UllLb4/S4kGextU4b3HlQolR1oE1VyiEN3frHNBs2oKHBwJt7qJkneq uE8/L+/rTT3qbg4pfdka7/qKwrPRv4jwVN9M4zfNrFVlkeoO9DqOTf4531RN1dl1ND HspB4DCfv862Q== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1r8JfO-00HVaA-54; Wed, 29 Nov 2023 12:27:46 +0000 Date: Wed, 29 Nov 2023 12:27:45 +0000 Message-ID: <865y1kd9ry.wl-maz@kernel.org> From: Marc Zyngier To: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, Ard Biesheuvel , Catalin Marinas , Will Deacon , Mark Rutland , Ryan Roberts , Anshuman Khandual , Kees Cook Subject: Re: [PATCH v6 11/41] arm64: kernel: Manage absolute relocations in code built under pi/ In-Reply-To: <20231129111555.3594833-54-ardb@google.com> References: <20231129111555.3594833-43-ardb@google.com> <20231129111555.3594833-54-ardb@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: ardb@google.com, linux-arm-kernel@lists.infradead.org, ardb@kernel.org, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, ryan.roberts@arm.com, anshuman.khandual@arm.com, keescook@chromium.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231129_042751_521680_48E08D52 X-CRM114-Status: GOOD ( 30.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, 29 Nov 2023 11:16:07 +0000, Ard Biesheuvel wrote: > > From: Ard Biesheuvel > > The mini C runtime runs before relocations are processed, and so it > cannot rely on statically initialized pointer variables. > > Add a check to ensure that such code does not get introduced by > accident, by going over the relocations in each object, identifying the > ones that operate on data sections that are part of the executable > image, and raising an error if any relocations of type R_AARCH64_ABS64 > exist. Note that such relocations are permitted in other places (e.g., > debug sections) and will never occur in compiler generated code sections > when using the small code model, so only check sections that have > SHF_ALLOC set and SHF_EXECINSTR cleared. > > To accommodate cases where statically initialized symbol references are > unavoidable, introduce a special case for ELF input data sections that > have ".rodata.prel64" in their names, and in these cases, instead of > rejecting any encountered ABS64 relocations, convert them into PREL64 > relocations, which don't require any runtime fixups. Note that the code > in question must still be modified to deal with this, as it needs to > convert the 64-bit signed offsets into absolute addresses before use. > > Signed-off-by: Ard Biesheuvel > --- > arch/arm64/kernel/pi/Makefile | 9 +- > arch/arm64/kernel/pi/pi.h | 18 +++ > arch/arm64/kernel/pi/relacheck.c | 130 ++++++++++++++++++++ > 3 files changed, 155 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kernel/pi/Makefile b/arch/arm64/kernel/pi/Makefile > index c844a0546d7f..bc32a431fe35 100644 > --- a/arch/arm64/kernel/pi/Makefile > +++ b/arch/arm64/kernel/pi/Makefile > @@ -22,11 +22,16 @@ KCSAN_SANITIZE := n > UBSAN_SANITIZE := n > KCOV_INSTRUMENT := n > > +hostprogs := relacheck > + > +quiet_cmd_piobjcopy = $(quiet_cmd_objcopy) > + cmd_piobjcopy = $(cmd_objcopy) && $(obj)/relacheck $(@) $(<) > + > $(obj)/%.pi.o: OBJCOPYFLAGS := --prefix-symbols=__pi_ \ > --remove-section=.note.gnu.property \ > --prefix-alloc-sections=.init > -$(obj)/%.pi.o: $(obj)/%.o FORCE > - $(call if_changed,objcopy) > +$(obj)/%.pi.o: $(obj)/%.o $(obj)/relacheck FORCE > + $(call if_changed,piobjcopy) > > $(obj)/lib-%.o: $(srctree)/lib/%.c FORCE > $(call if_changed_rule,cc_o_c) > diff --git a/arch/arm64/kernel/pi/pi.h b/arch/arm64/kernel/pi/pi.h > new file mode 100644 > index 000000000000..7c2d9bbf0ff9 > --- /dev/null > +++ b/arch/arm64/kernel/pi/pi.h > @@ -0,0 +1,18 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +// Copyright 2023 Google LLC > +// Author: Ard Biesheuvel > + > +#define __prel64_initconst __section(".init.rodata.prel64") > + > +#define PREL64(type, name) union { type *name; prel64_t name ## _prel; } > + > +#define prel64_pointer(__d) (typeof(__d))prel64_to_pointer(&__d##_prel) > + > +typedef volatile signed long prel64_t; > + > +static inline void *prel64_to_pointer(const prel64_t *offset) > +{ > + if (!*offset) > + return NULL; > + return (void *)offset + *offset; > +} Is there any use for these definitions before the override code gets moved to pi/ in patch 21? It is otherwise a bit odd to see two sets of definitions between patches 15 and 20. Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel