Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp847476imn; Tue, 26 Jul 2022 10:56:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sp6kLfrBhKJMU6DB8vr6SzKep9JRzZAX/cgicM/1eKR0BlTavcSZ3U+8lSLFEESMA8N7nP X-Received: by 2002:a17:902:eb8f:b0:16d:4215:5f23 with SMTP id q15-20020a170902eb8f00b0016d42155f23mr18161514plg.70.1658858191787; Tue, 26 Jul 2022 10:56:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658858191; cv=none; d=google.com; s=arc-20160816; b=AqtbLsx2Wgsumt2jl/vHPVrbAZMn+JTqFK/k3KOhJZDYgi050m2QVr/hO4EqXGCeZt i/py+i0mJwAoBvFwhFxzpTpMmBrE38Vx1wfAddWayErPu+An1xi5ur9QBX8tfeUuaFHh 9kZHdl8YVcf/ebdjZw/eueSxVem6ZGxQ52/USc2COWa/cLflrhaRaxPXpegfVQ4B4AjT 5240bbFGGTTM1OmC6aCNHNyF3Ble+ufkXtN+OgTfqZ5oE3xKB3odar5PYyvX21UAniUN 5j9Ul65ZiDfDTlTFaZ0L3gJuvH9/TkGMf+4xc2MOxBJ40/f8BdXX1PD4ligcUBwhxffY 8Jew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=bwNQpfheVMsx1MkAAm/jFTcbg70p+wDnfbRK2RaY5fM=; b=ZBmb+09mMkiqlCaTZmPeSc/qaDLnTHDb5QpoL/Dlq2/X6SWkKwRZRI1iunzcnPgNRm cUkaTtkQmHZ2suqWcTq3LuGGnpjd7M7PPXb/MBAO1hgo89BwQaf0wJj6V3LGU/UOzx+Z cVaGiXh6ldWD2+AtLWxZwVDOl9LOsMFfdNzn3nnlUI8nX54OiaJSJX7u5Z4LS6rjngwT eGk+nVwcbdgsPXzQK4rYq0M+d7GzYv+I086tw++2tXPtTgPb5aBgIlIThmO/uBsjEKrF kOTul/SZ93lVYNWx4HwwFIOTTnyLCKpzxFUsuN9344VLuB1BfLZxdSkqd+O8GCmViWmk tZMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CvUlb6Rx; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lr3-20020a17090b4b8300b001f2c217c71csi5991343pjb.153.2022.07.26.10.56.16; Tue, 26 Jul 2022 10:56:31 -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=@kernel.org header.s=k20201202 header.b=CvUlb6Rx; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239117AbiGZRT4 (ORCPT + 99 others); Tue, 26 Jul 2022 13:19:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230170AbiGZRTy (ORCPT ); Tue, 26 Jul 2022 13:19:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 347D31A051; Tue, 26 Jul 2022 10:19:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EBB04B818BF; Tue, 26 Jul 2022 17:19:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95BB0C433D6; Tue, 26 Jul 2022 17:19:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1658855990; bh=qfN7sU2QjHcpSBNkLFgxr5Bfn9PXkpjv/gAO3PLESVs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=CvUlb6RxAI4iOAnGgODfQ66YkVUIQ5nF7awrlSJiQQJpdsYBOO2+gpZFK7Dg+Ccsk fjXEAwXGOorffZQ7rLmwqqDXsb/pZ91c+VpeXstALHfP+ZBKz6QkMweSO3eTlEhTJI s3vip4BatsRJRsEy075U7oHUnKrCj0OD2qigojzZNW+da3zs9xJUlboQ38aoUHVgM2 Y6lCEQxbx/IMXJcULNguUhxqg1yV1oPU+6Np0/ElcVHugy58qvUDsUzHzw+BLW1lNV UgXEr7EfspRIcwlXqw414XIibFx7FVLe3T/vwO3UM7lEu58JfEY5X3tD2OWSVn9/SK su8e44cswuXow== Received: by mail-yb1-f173.google.com with SMTP id f73so26389856yba.10; Tue, 26 Jul 2022 10:19:50 -0700 (PDT) X-Gm-Message-State: AJIora8nxQnsG2cWgVgmcZ0/M8KA0lsMP94MaRYw7rAQuIO9NkHP4R7Q fOL5JRPezJKgdoxY/p0vE3iCYEPbLLoEcJU7Ngs= X-Received: by 2002:a25:55c5:0:b0:670:96cb:a295 with SMTP id j188-20020a2555c5000000b0067096cba295mr13625181ybb.449.1658855989642; Tue, 26 Jul 2022 10:19:49 -0700 (PDT) MIME-Version: 1.0 References: <20220721175147.214642-1-song@kernel.org> In-Reply-To: <20220721175147.214642-1-song@kernel.org> From: Song Liu Date: Tue, 26 Jul 2022 10:19:38 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3] livepatch: Clear relocation targets on a module removal To: live-patching@vger.kernel.org, open list Cc: Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Joe Lawrence , X86 ML , Josh Poimboeuf Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 Hi folks, Could you please share your comments on this one? Thanks, Song On Thu, Jul 21, 2022 at 10:52 AM Song Liu wrote: > > 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 > > --- > > Changes from v2: > 1. Rewrite x86 changes to match current code style. > 2. Remove powerpc changes as there is no test coverage in v3. > 3. Only keep 1/3 of v2. > > v2: https://lore.kernel.org/all/20190905124514.8944-1-mbenes@suse.cz/T/#u > --- [...]