Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp46679pxj; Tue, 15 Jun 2021 19:41:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhE+fcBcrGD6muTxX+0G6DAAlA6NQlXtpZ1I5I8BcyT6KiYb53ojlQGuzhuJeVbYAtlJy1 X-Received: by 2002:a05:6638:2707:: with SMTP id m7mr2042339jav.66.1623811292416; Tue, 15 Jun 2021 19:41:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623811292; cv=none; d=google.com; s=arc-20160816; b=UtOgbJoAct6cHifNnDH8OJ9mullMMJapDsKJr4yfjfEVogMkxTjLiVixWB1SEQspw4 WGY08kesWeHlQg3ROLXqos11pdYzpsYKwfez9b67o3hPjORFvNpTRL8570K/rdScavoH R1a5sLlTIC5/oJWKxpUPOU6T1LWFW3nQib2e3OpwRrAo0xyzPwQGGBzNNVst7bjxIj7s q7/wHOtgc+XrukQXpA40po4LY5+STa571+yyts222UW3XEGcuQ5f4BM2uyXnA96hglLl 9pDK7gHB3Ap6t9Wuy5Bfjejse1Wqnf+Fjzv+UH+UPKkBdhPlPHO5ns5kFya4fS1JNU7J gXZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=joPTg38So0KTMTsiYC7143BJ1pzExjdFPA9HfN+WWBc=; b=WTmzq8VcwTRsS1dTEI0T8xwWanPv15o9t2AO0r1UFd2jsFM/9uSj2h5CEnPMMmJXG7 xgxUYxfxYHiUr0UJQLb1sbfYtG+eNB6AKp20s6q0RjWnqdQ+Gg/CzkEwRspjhu0JTNFk ExVkmrQ1xJWysTCDdFd2lMFf49qV8ru7x1WihbpmgBfrSx45ubvTinO/IhC1hJdVsLws 9hhfwjvhjMACr7xQcip/7UcPgpt5YoPFxVMJfTZeVBztXBUBw0HVW6VLZgZREG6Wp/SM inFNW5ZEFtlAqCT6gydgo3OtdaTLiFjNNqVz2llBzEDxJFd/gbOdS7WaJAnLhrVoiJXr xaYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b="Lz/Ng2gG"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i2si664746iol.50.2021.06.15.19.41.19; Tue, 15 Jun 2021 19:41:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b="Lz/Ng2gG"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231964AbhFPCmv (ORCPT + 99 others); Tue, 15 Jun 2021 22:42:51 -0400 Received: from ozlabs.org ([203.11.71.1]:39523 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231287AbhFPCmu (ORCPT ); Tue, 15 Jun 2021 22:42:50 -0400 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4G4TvH2Cwlz9sTD; Wed, 16 Jun 2021 12:40:43 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ellerman.id.au; s=201909; t=1623811244; bh=fAOxWCCUqkqRWTT3Osv85acAWAHitkHmIfoMB/o2TUE=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=Lz/Ng2gGouKD1PHFlUlCnZRvKgC5bG2BrrqX2PRNWdejhXTaEEyIeEOqjXb12ND9Z lc3IVqFyNyLvQMQvaO9Hm6/h+UYs7bUH1TOYQGmbdTvKi24aHNeKjXTknSLcLiIVrn 8ihXvNq73r5qty1HKS8yxN8Zn8pYE20eB3l7jtnYdk6HFX9ws238b/KhClvpLqK21n Zth3zU2kVeZag85kYywY/3gJm2TCkhuEuRP3U/X+0z8A8UO6YRI0lArHLsROkHiCO1 ClIAspa7RmydpOMctT242mM8UitpOYeEfC2CLYcVO25hqNINxJwJDlkBWPBZyWXcR/ 2ZY9eHltVwEEQ== From: Michael Ellerman To: Roman Bolshakov Cc: linuxppc-dev@lists.ozlabs.org, dja@axtens.net, christophe.leroy@csgroup.eu, a.kovaleva@yadro.com, groug@kaod.org, Linus Torvalds , linux-kernel@vger.kernel.org Subject: Re: [PATCH] powerpc: Fix initrd corruption with relative jump labels In-Reply-To: References: <20210614131440.312360-1-mpe@ellerman.id.au> Date: Wed, 16 Jun 2021 12:40:42 +1000 Message-ID: <87pmwmsf9x.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Roman Bolshakov writes: > On Mon, Jun 14, 2021 at 11:14:40PM +1000, Michael Ellerman wrote: >> Commit b0b3b2c78ec0 ("powerpc: Switch to relative jump labels") switched >> us to using relative jump labels. That involves changing the code, >> target and key members in struct jump_entry to be relative to the >> address of the jump_entry, rather than absolute addresses. >> >> We have two static inlines that create a struct jump_entry, >> arch_static_branch() and arch_static_branch_jump(), as well as an asm >> macro ARCH_STATIC_BRANCH, which is used by the pseries-only hypervisor >> tracing code. >> >> Unfortunately we missed updating the key to be a relative reference in >> ARCH_STATIC_BRANCH. >> >> That causes a pseries kernel to have a handful of jump_entry structs >> with bad key values. Instead of being a relative reference they instead >> hold the full address of the key. >> >> However the code doesn't expect that, it still adds the key value to the >> address of the jump_entry (see jump_entry_key()) expecting to get a >> pointer to a key somewhere in kernel data. >> >> The table of jump_entry structs sits in rodata, which comes after the >> kernel text. In a typical build this will be somewhere around 15MB. The >> address of the key will be somewhere in data, typically around 20MB. >> Adding the two values together gets us a pointer somewhere around 45MB. >> >> We then call static_key_set_entries() with that bad pointer and modify >> some members of the struct static_key we think we are pointing at. >> >> A pseries kernel is typically ~30MB in size, so writing to ~45MB won't >> corrupt the kernel itself. However if we're booting with an initrd, >> depending on the size and exact location of the initrd, we can corrupt >> the initrd. Depending on how exactly we corrupt the initrd it can either >> cause the system to not boot, or just corrupt one of the files in the >> initrd. >> >> The fix is simply to make the key value relative to the jump_entry >> struct in the ARCH_STATIC_BRANCH macro. >> >> Fixes: b0b3b2c78ec0 ("powerpc: Switch to relative jump labels") >> Reported-by: Anastasia Kovaleva >> Reported-by: Roman Bolshakov >> Reported-by: Greg Kurz >> Reported-by: Daniel Axtens >> Signed-off-by: Michael Ellerman >> --- >> arch/powerpc/include/asm/jump_label.h | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/arch/powerpc/include/asm/jump_label.h b/arch/powerpc/include/asm/jump_label.h >> index 2d5c6bec2b4f..93ce3ec25387 100644 >> --- a/arch/powerpc/include/asm/jump_label.h >> +++ b/arch/powerpc/include/asm/jump_label.h >> @@ -50,7 +50,7 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool >> 1098: nop; \ >> .pushsection __jump_table, "aw"; \ >> .long 1098b - ., LABEL - .; \ >> - FTR_ENTRY_LONG KEY; \ >> + FTR_ENTRY_LONG KEY - .; \ >> .popsection >> #endif >> >> -- >> 2.25.1 >> > > Thanks for fixing the issue, Michael. > > Perhaps the fix should go to v5.13-rc7 if Linus plans to do it. It'd be > good to avoid broken initrd on pseries guests in the release. Yes it's in my fixes branch and I'll ask Linus to pull that before the next rc. cheers