Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp933120rwe; Wed, 31 Aug 2022 13:49:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR46y+5pq38NEQsaIPf75bApsuadI/Ny/vrvLdb6VHqndKsyOfmCZ8qJnmvO9HO1mHrhfHyl X-Received: by 2002:a05:6a00:a8f:b0:530:3c05:4644 with SMTP id b15-20020a056a000a8f00b005303c054644mr28221699pfl.79.1661978965390; Wed, 31 Aug 2022 13:49:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661978965; cv=none; d=google.com; s=arc-20160816; b=HruDSel5Qh7GcyLoNuSb/S260OKZynGlivF096Wx4PZyHMkDPPfeWCcCfmB6+VO2aU YSq1JZIv+54QhFauqhCvWyFvpUlfnque14XY5OFNxmYFh8Oz24Bn0jK/sKOUTdr6Wbzv NaB9WV3HUiCoIZ/auF+cfEr5Vb5BgRUWH7HR+/vhY9F5b3FxgHns6XFhfvI2pujBh5Rb LSCEAHZhN8sDemdJ+GF0OBwcFOC1xM6ShpHZlkZ/o2W+mu/+5l41PC9UG+zec8oOV6hv TyCLgYh5xXMG3AYW2dMy61EdKrDqw1jO6uBsrB5Q3b80G3a6Hfj5mcYKucTL0JmK0XgT iE+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=r8Nlq9zif2fq3bbnp4BvyqOxlH6TzAD6XgndQmzpQAs=; b=g17DzengRbQ4X9GFYwYHIO6QbuWyPDjO9QV9A12V9sa7XrLwDn0QBb+2cD7WYiP/AY MSZxFOO1WVj027oLaZBJKJlErEfPEdxN3bCdP/x0bDx0Il6QwoX0c3ye5rdY121ecTdq bogy34tUOnBd3nJnPGD2KX9eKwNYKpPHDFO653GHRwdpuOJ16+bIq+4aASmgGfgJ5sHM jMvN0w7OLrudklUkFlFMbSYhvMvCRsB+dqNe2QbnrdvpyL9p4JzRnBOuq0JP2JXZgCY0 achKidqFypXdg2mK3hnyT4hJ23T5o3U3ctAhDj6Cjp4KMDkxUdKfZKd0e9eSsdW/h8hR IPdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c8McsmIE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p3-20020a62ab03000000b00538170c6f05si10301475pff.290.2022.08.31.13.49.12; Wed, 31 Aug 2022 13:49:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c8McsmIE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231332AbiHaUGp (ORCPT + 99 others); Wed, 31 Aug 2022 16:06:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbiHaUGn (ORCPT ); Wed, 31 Aug 2022 16:06:43 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95FBFC6964 for ; Wed, 31 Aug 2022 13:06:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661976401; h=from:from: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=r8Nlq9zif2fq3bbnp4BvyqOxlH6TzAD6XgndQmzpQAs=; b=c8McsmIEGC8v/2Pr1l2zWgaKSsi+CNTLD8mgQM4yH+d7Q+W+gslxRkY1rp3dELXZivnDDm gc6t5g1M1uber1LSGFgEkvD9UaHolCRIaRW9prxhnWIXzoBO1g/91XL8egr0wzBlwaFX7w 1VGohntdJHFaeizZf//8Tc7gbF1gJCM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-47-qbPjvfqnMcab3ym6Nz1UkA-1; Wed, 31 Aug 2022 16:06:36 -0400 X-MC-Unique: qbPjvfqnMcab3ym6Nz1UkA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 363188037AF; Wed, 31 Aug 2022 20:06:36 +0000 (UTC) Received: from redhat.com (unknown [10.22.32.220]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A4B2492C3B; Wed, 31 Aug 2022 20:06:35 +0000 (UTC) Date: Wed, 31 Aug 2022 16:06:33 -0400 From: Joe Lawrence To: Song Liu Cc: Christophe Leroy , "live-patching@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "pmladek@suse.com" , "jikos@kernel.org" , "x86@kernel.org" , Josh Poimboeuf , "mbenes@suse.cz" , "linuxppc-dev@lists.ozlabs.org" , "jpoimboe@kernel.org" Subject: Re: [PATCH v5] livepatch: Clear relocation targets on a module removal Message-ID: References: <20220830185313.76402-1-song@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 31, 2022 at 10:05:43AM -0700, Song Liu wrote: > On Wed, Aug 31, 2022 at 1:01 AM Christophe Leroy > wrote: > > > > > > > > Le 30/08/2022 ? 20:53, Song Liu a ?crit : > > > From: Miroslav Benes > > > > > > Josh reported a bug: > > > > > > When the object to be patched is a module, and that module is > > > rmmod'ed and reloaded, it fails to load with: > > > > > > module: x86/modules: Skipping invalid relocation target, existing value is nonzero for type 2, loc 00000000ba0302e9, val ffffffffa03e293c > > > livepatch: failed to initialize patch 'livepatch_nfsd' for module 'nfsd' (-8) > > > livepatch: patch 'livepatch_nfsd' failed for module 'nfsd', refusing to load module 'nfsd' > > > > > > The livepatch module has a relocation which references a symbol > > > in the _previous_ loading of nfsd. When apply_relocate_add() > > > tries to replace the old relocation with a new one, it sees that > > > the previous one is nonzero and it errors out. > > > > > > On ppc64le, we have a similar issue: > > > > > > module_64: livepatch_nfsd: Expected nop after call, got e8410018 at e_show+0x60/0x548 [livepatch_nfsd] > > > livepatch: failed to initialize patch 'livepatch_nfsd' for module 'nfsd' (-8) > > > livepatch: patch 'livepatch_nfsd' failed for module 'nfsd', refusing to load module 'nfsd' > > > > > > He also proposed three different solutions. We could remove the error > > > check in apply_relocate_add() introduced by commit eda9cec4c9a1 > > > ("x86/module: Detect and skip invalid relocations"). However the check > > > is useful for detecting corrupted modules. > > > > > > We could also deny the patched modules to be removed. If it proved to be > > > a major drawback for users, we could still implement a different > > > approach. The solution would also complicate the existing code a lot. > > > > > > We thus decided to reverse the relocation patching (clear all relocation > > > targets on x86_64). The solution is not > > > universal and is too much arch-specific, but it may prove to be simpler > > > in the end. > > > > > > Reported-by: Josh Poimboeuf > > > Signed-off-by: Miroslav Benes > > > Signed-off-by: Song Liu > > > > > > --- > > > > > > NOTE: powerpc code has not be tested. > > > > > > Changes v4 = v5: > > > 1. Fix compile with powerpc. > > > > Not completely it seems. > > > > CC kernel/livepatch/core.o > > kernel/livepatch/core.c: In function 'klp_clear_object_relocations': > > kernel/livepatch/core.c:352:50: error: passing argument 1 of > > 'clear_relocate_add' from incompatible pointer type > > [-Werror=incompatible-pointer-types] > > 352 | clear_relocate_add(pmod->klp_info->sechdrs, > > | ~~~~~~~~~~~~~~^~~~~~~~~ > > | | > > | Elf32_Shdr * > > {aka struct elf32_shdr *} > > In file included from kernel/livepatch/core.c:19: > > ./include/linux/moduleloader.h:76:37: note: expected 'Elf64_Shdr *' {aka > > 'struct elf64_shdr *'} but argument is of type 'Elf32_Shdr *' {aka > > 'struct elf32_shdr *'} > > 76 | void clear_relocate_add(Elf64_Shdr *sechdrs, > > | ~~~~~~~~~~~~^~~~~~~ > > cc1: some warnings being treated as errors > > > > > > Fixup: > > > > diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h > > index d22b36b84b4b..958e6da7f475 100644 > > --- a/include/linux/moduleloader.h > > +++ b/include/linux/moduleloader.h > > @@ -73,7 +73,7 @@ int apply_relocate_add(Elf_Shdr *sechdrs, > > unsigned int relsec, > > struct module *mod); > > #ifdef CONFIG_LIVEPATCH > > -void clear_relocate_add(Elf64_Shdr *sechdrs, > > +void clear_relocate_add(Elf_Shdr *sechdrs, > > const char *strtab, > > unsigned int symindex, > > unsigned int relsec, > > > > > > But then the link fails. > > > > LD .tmp_vmlinux.kallsyms1 > > powerpc64-linux-ld: kernel/livepatch/core.o: in function > > `klp_cleanup_module_patches_limited': > > core.c:(.text+0xdb4): undefined reference to `clear_relocate_add' > > Hmm.. I am not seeing either error. Could you please share your .config file? > > Thanks, > Song > If it's any help, I see the same build error Christophe reported using the 'cross-dev' script that's in my klp-convert-tree [1]. $ BUILD_ARCHES="ppc32" ./cross-dev config $ BUILD_ARCHES="ppc32" ./cross-dev build -j$(nproc) (The kernel will be built in /tmp/klp-convert-ppc32 btw.) Applying the header file fix results in the same linker error, too. [1] https://github.com/joe-lawrence/klp-convert-tree/tree/klp-convert-v7-devel+song -- Joe