Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp8534051rwb; Tue, 13 Dec 2022 07:30:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf5ymvikRP6+YM9NF17+278nBlF6rM5D4S4IKrpiYHnx9OQ1I9SyusRoqtg9Uk+raFyjJq64 X-Received: by 2002:a05:6a00:13a4:b0:56b:ada5:db92 with SMTP id t36-20020a056a0013a400b0056bada5db92mr27808539pfg.9.1670945446332; Tue, 13 Dec 2022 07:30:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670945446; cv=none; d=google.com; s=arc-20160816; b=uYC1jbr/3twie0KDJF1Q52hNkr8mlX21nn87HjoyAeTiae8byuwtm4FCeUTEYKwKyE mADjK1BhJzscXl1fYBFflHcz/4BlkKgg9rgxDBkG8OQR5ADjpUnOwHTsr2DNUkEaGNtR OVTLx2uGs0s+9q2iP3UGtxahlTa4d3VIn8O5N4RaE9ivxC9HnY1r9RsnZ+syeeclTsty 9y+qiq1GC297MECIvcqtlxR4hFEqi8Ws4QfaB9i8Qu2m1RR2kJRPSLW680F8UJHXRZL2 iLKluGxxMqWUUTrEKMoQDBIm1iORo2k4ii09n9sNAZVQIhVKy0opa6khFxCgSV0D20vk nKNg== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=yCoPhJw+GKmzrg8p4DH4Ya6d+PQIKemaInJPhpeXlHU=; b=kVT8FiqcuiHXH+7U28cMcm84fDl5BQTEiVB7rg0RW8d2O660lIu/vs7wCtqTRl0cAS Qs4FT/WNbLBQPIhD6i51vZd9ZwU5B6kdOrg5lKpMwt8iBn6krlR2k0axMWhxzjoeqXMY PezEWEqhSQCY6fc0/XKMDLuretK49y1xopUPhMbTEPKGh5v4Daku/W9KPsv/A0VAQGbU AwYnOb0Ux6QnLN5OgRPxtmaVWEvvH5rsSceTcYN64qI3AqYZhgiQp0heg4p7poAGLD1U F+20NW48tvih9/ZfK59S/e6i0PKomZtuB1Hj6eGzF1I/73P/8w0CdrA2JifVmg1ov3bi rndg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=eMnP3Idp; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y2-20020aa78f22000000b00574f6921ba2si12220204pfr.207.2022.12.13.07.30.35; Tue, 13 Dec 2022 07:30:46 -0800 (PST) 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=@suse.com header.s=susede1 header.b=eMnP3Idp; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235960AbiLMOhj (ORCPT + 72 others); Tue, 13 Dec 2022 09:37:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235954AbiLMOhg (ORCPT ); Tue, 13 Dec 2022 09:37:36 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE75B13CE5; Tue, 13 Dec 2022 06:37:33 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 8ADEE1FDB8; Tue, 13 Dec 2022 14:37:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1670942252; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=yCoPhJw+GKmzrg8p4DH4Ya6d+PQIKemaInJPhpeXlHU=; b=eMnP3IdpmRft/ER7oin2HnZdMR5P7VHO5Sw/nEemsxB2Ij/yJwJfX7Qw5GQMBH5u6Fzp9j B/k+nQ8blMON5hd8beazuYDg55xA4qnleqSX2yPUaX1FJkK9+lFf9Ix1dIM9V3mpRRdKVk 2q5tMlDY577z7rViBRwn73TM11qdHPY= Received: from suse.cz (unknown [10.100.208.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 6DB002C142; Tue, 13 Dec 2022 14:37:32 +0000 (UTC) Date: Tue, 13 Dec 2022 15:37:32 +0100 From: Petr Mladek To: Song Liu Cc: Miroslav Benes , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, jpoimboe@kernel.org, jikos@kernel.org, x86@kernel.org, joe.lawrence@redhat.com, linuxppc-dev@lists.ozlabs.org, Josh Poimboeuf Subject: Re: [PATCH v6] livepatch: Clear relocation targets on a module removal Message-ID: References: <20220901171252.2148348-1-song@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 On Tue 2022-12-13 00:28:34, Song Liu wrote: > On Fri, Dec 9, 2022 at 4:55 AM Miroslav Benes wrote: > > > > Hi, > > > > first thank you for taking over and I also appologize for not replying > > much sooner. > > > > On Thu, 1 Sep 2022, 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 > > > > Petr has commented on the code aspects. I will just add that s390x was not > > dealt with at the time because there was no live patching support for > > s390x back then if I remember correctly and my notes do not lie. The same > > applies to powerpc32. I think that both should be fixed as well with this > > patch. It might also help to clean up the ifdeffery in the patch a bit. > > After reading the code (no testing), I think we don't need any logic for > ppc32 and s390. > > We need clear_relocate_add() to handle module reload failure. > > I don't think we have similar checks for ppc32 and s390, so > clear_relocate_add() is not needed for the two. > > OTOH, we can argue that clear_relocate_add() should undo > everything apply_relocate_add() did. But I do think that > will be an overkill. It is true that we do not need to clear the relocations if the values are not checked in apply_relocated_add(). I do not have strong opinion whether we should do it or not. One one hand, the clearing code might introduce a bug if it modifies some wrong location. So, it might do more harm then good. One the other hand, it feels bad when a code is jumping to a non-existing address. I know, nobody should call this code. But it is still a kind of a security hole. Well, I think that we could keep the clearing functions empty on ppc32 and s390 in this patch(set). It won't be worse than it is now. And perfection is the enemy of good. Best Regards, Petr