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=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 E6D06C48BDF for ; Tue, 15 Jun 2021 10:53:05 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DC1FE61455 for ; Tue, 15 Jun 2021 10:53:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC1FE61455 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4G44sq48s8z3c2K for ; Tue, 15 Jun 2021 20:53:03 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=kaod.org (client-ip=207.211.30.44; helo=us-smtp-delivery-44.mimecast.com; envelope-from=groug@kaod.org; receiver=) Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4G44sL0Mnwz308f for ; Tue, 15 Jun 2021 20:52:10 +1000 (AEST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-553-KcEw6pD2P5Ws-WiZrgDqYA-1; Tue, 15 Jun 2021 06:51:57 -0400 X-MC-Unique: KcEw6pD2P5Ws-WiZrgDqYA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 729151926DB8; Tue, 15 Jun 2021 10:51:56 +0000 (UTC) Received: from bahia.lan (ovpn-112-248.ams2.redhat.com [10.36.112.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id D5D3860C0F; Tue, 15 Jun 2021 10:51:54 +0000 (UTC) Date: Tue, 15 Jun 2021 12:51:51 +0200 From: Greg Kurz To: Michael Ellerman Subject: Re: [PATCH] powerpc: Fix initrd corruption with relative jump labels Message-ID: <20210615125151.6a27646c@bahia.lan> In-Reply-To: <20210614175740.6721fe0a@bahia.lan> References: <20210614131440.312360-1-mpe@ellerman.id.au> <20210614175740.6721fe0a@bahia.lan> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxppc-dev@lists.ozlabs.org, r.bolshakov@yadro.com, a.kovaleva@yadro.com, dja@axtens.net Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Mon, 14 Jun 2021 17:57:40 +0200 Greg Kurz wrote: > On Mon, 14 Jun 2021 23:14:40 +1000 > Michael Ellerman wrote: >=20 > > Commit b0b3b2c78ec0 ("powerpc: Switch to relative jump labels") switche= d > > 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. > >=20 > > 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. > >=20 > > Unfortunately we missed updating the key to be a relative reference in > > ARCH_STATIC_BRANCH. > >=20 > > 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. > >=20 > > However the code doesn't expect that, it still adds the key value to th= e > > address of the jump_entry (see jump_entry_key()) expecting to get a > > pointer to a key somewhere in kernel data. > >=20 > > 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. > >=20 > > 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. > >=20 > > 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 eithe= r > > cause the system to not boot, or just corrupt one of the files in the > > initrd. > >=20 > > The fix is simply to make the key value relative to the jump_entry > > struct in the ARCH_STATIC_BRANCH macro. > >=20 > > 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 > > --- >=20 > Great thanks for debugging this issue ! I'll try it out tomorrow morning. >=20 This fixes the issue. Great thanks again :) Tested-by: Greg Kurz > Cheers, >=20 > -- > Greg >=20 > > arch/powerpc/include/asm/jump_label.h | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > >=20 > > diff --git a/arch/powerpc/include/asm/jump_label.h b/arch/powerpc/inclu= de/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(s= truct static_key *key, bool > > 1098:=09nop;=09=09=09=09=09\ > > =09.pushsection __jump_table, "aw";=09\ > > =09.long 1098b - ., LABEL - .;=09=09\ > > -=09FTR_ENTRY_LONG KEY;=09=09=09\ > > +=09FTR_ENTRY_LONG KEY - .;=09=09=09\ > > =09.popsection > > #endif > > =20 >=20