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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC4D1C61D97 for ; Wed, 25 Jan 2023 19:03:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235984AbjAYTDn (ORCPT ); Wed, 25 Jan 2023 14:03:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229496AbjAYTDl (ORCPT ); Wed, 25 Jan 2023 14:03:41 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04C5FDBCB; Wed, 25 Jan 2023 11:03:39 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 94BBC6155F; Wed, 25 Jan 2023 19:03:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAF3CC433EF; Wed, 25 Jan 2023 19:03:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674673418; bh=XeT3qSPMBwmHYZ4zvlYQg6u5mZJtG0QjkOeNOOP32w4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=I3XZcPQfHwnAYUCtYNTwNlpXKTZnXyv7Q0IfVNLD+wYLAMooFQQBKesHIfGyRcIQx trjuWggsnElsdzUdzrBCegOmeCsLwny9v6QHEeeWVO/21G8k9vx4sgxLYri3/QRT2l i0bzshvQIZmJinOGyGOnUk4Nb9ikFMt1QIaeUYUoWzhskId0DONSp2iRB3gG8e0+4b gq45KZrH+P4GHeCRQ8I6zGDvEIhqg0EkNl4rJUJf9i9PVYpxHcCwscZvBmbdNR02Kt HHM5Hx/hOfcYAqVqrK8sCQYs0yOgC541MxtQjufjMjlQL8IFct8LR18DjsAav9I+/7 BCm3LT4abGHvA== Date: Wed, 25 Jan 2023 11:03:36 -0800 From: Josh Poimboeuf To: Song Liu Cc: linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, live-patching@vger.kernel.org, x86@kernel.org, Josh Poimboeuf , Miroslav Benes , Petr Mladek Subject: Re: [PATCH v11 2/2] livepatch,x86: Clear relocation targets on a module removal Message-ID: <20230125190336.utdb3tvyuy74vnap@treble> References: <20230125185401.279042-1-song@kernel.org> <20230125185401.279042-2-song@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230125185401.279042-2-song@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 25, 2023 at 10:54:01AM -0800, Song Liu wrote: > 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. > > 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 > Originally-by: Miroslav Benes > Signed-off-by: Song Liu > Acked-by: Miroslav Benes > Reviewed-by: Petr Mladek Acked-by: Josh Poimboeuf -- Josh