Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp3223877rwb; Fri, 20 Jan 2023 13:01:04 -0800 (PST) X-Google-Smtp-Source: AMrXdXuRbfI4P70A/659b19elwX0/Y2XsNl+QUib8rZIiQPb1tNQcBB3EhOZjezoqId67RTapSMh X-Received: by 2002:a17:902:cec7:b0:191:3993:801e with SMTP id d7-20020a170902cec700b001913993801emr21691611plg.56.1674248464471; Fri, 20 Jan 2023 13:01:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674248464; cv=none; d=google.com; s=arc-20160816; b=dbA+UQNGHvMwSDED7Z9wInLwbGBnNdtJE4FLtdhQvHW7p5jOwHKhKM7JvhfTPZK8xO pPZn9oZTSxV8u+IoEoUlFs1klQeuz5YboNeC4D4ij4JL8G2mZ+eQRQRmOOmnK4k54Oo3 LXtxtOaUuzdkI3au5KY4ghOERi67HAmOxfSBoPQZafwIcmbyyaOGIdY7jBIPdvW0F2MD YdlH4PTw0uPuZ+9yAORR45yAXYea0dxpA9h9iXZ+4CD3BRx9mCBX8WXnyRSwUjr3rfiv 3b0kDLy3BD32JIzG/p4tgESidWAsY49krRMeKI32o+3+tWHjBnmI5kD2Ob73AsyejOut u//w== 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=QZ7XQpdNnhYlYlztnjthD+lG1qqtNibgkYn9WkfGsZI=; b=kTN+2uZazs4BLx6XeF0Rjcs9a3PCsgscV3J+boQ21kpp+ykOl36pQ3rPDjAi7iJDvZ 0KibFHSaN26CLH7AV3jFVG2Oc0wZS+T8tGse/watQqCEldJZ7yQs7Gpu2ISv+wW+xk/2 si/LpSNE+lK2p/SPrLscdtA574QfW7cDgrYQtxdlukVA/q6EFrF5cOLynZjRrBcNaKaC giejAvMncQ8D6/CYvp60BsZ9QbKl49SWB3mbEeVapXVLN2rZIYcv+cUYCbxIkBguaAMw ahkbNLaEGmalI3koNsGYSoiL6Uoht07ibUum14WgodNOJ4KQqrlT//S2f8VJ+brBRQbY NTVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="f/2YTsso"; 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 z4-20020a170902ccc400b00172cb948c68si42148186ple.227.2023.01.20.13.00.57; Fri, 20 Jan 2023 13:01:04 -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=@kernel.org header.s=k20201202 header.b="f/2YTsso"; 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 S229604AbjATUdC (ORCPT + 50 others); Fri, 20 Jan 2023 15:33:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbjATUdB (ORCPT ); Fri, 20 Jan 2023 15:33:01 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 967EB8A0F8; Fri, 20 Jan 2023 12:32:58 -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 ams.source.kernel.org (Postfix) with ESMTPS id 3BF08B82A59; Fri, 20 Jan 2023 20:32:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DEABC433D2; Fri, 20 Jan 2023 20:32:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674246775; bh=Mpd3ggMAesKvNDM2J5TjcadboGsqRMW6xSnwxTQzs9M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=f/2YTssoLBjjzLSBf54MtKOiJn2xOGzgzBiDMuZYAA+cYBNvfT2kZfrIwQk+makKA DBiADCIkkzpVrrbTdTON2aMMIHNjVvji6xB4w4j0vcNqrscNqhRC+a7rV1323TLN3O jY7YwMuK25eZrsJv2k9kmZeC9o/pfJRNa0X4c3D0OfOL0MHzWfIS6OV6/7m9D/6iCS E8PlUu/ztkOjzpjBAD9d7y8EbKMQtvjxwuxDiaSi8Cit+6y9XAfMAe2mbI9eox5dgv QR4zjGRMd0RZ3roPzIXG3k99ph4S45ZAUwMqHYvO9QV8GQ65ObE9rI0LC5jPTiF1mh jZPrE6AzyXK0w== Date: Fri, 20 Jan 2023 12:32:53 -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, jikos@kernel.org, pmladek@suse.com, joe.lawrence@redhat.com, Miroslav Benes , Josh Poimboeuf Subject: Re: [PATCH v9] livepatch: Clear relocation targets on a module removal Message-ID: <20230120203253.5r7dkge6x4vsx5ov@treble> References: <20230118204728.1876249-1-song@kernel.org> <20230120191642.7bmqt6t4qngisqep@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.1 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 On Fri, Jan 20, 2023 at 11:41:02AM -0800, Song Liu wrote: > > > 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. > > > > Should we add a selftest to make sure this problem doesn't come back? > > IIRC, a selftest for this issue is not easy without Joe's klp-convert work. > At the moment I use kpatch-build for testing. Ah right, I remember that now. > How about: > > Signed-off-by: Song Liu > Originally-by: Miroslav Benes > Acked-by: Miroslav Benes > Reported-by: Josh Poimboeuf Yes, but the ordering looks off, I think it should be more like: Reported-by: Josh Poimboeuf Originally-by: Miroslav Benes Signed-off-by: Song Liu Acked-by: Miroslav Benes And then make sure 'From:' is you. BTW, this patch affects both livepatch and x86, so the subject prefix should have "x86" added, something like: livepatch,x86: Clear relocations on module removal > > This code really needs to be removed anyway, it's been dead for at least > > 15 years. > > Shall we remove it now? Within the same patch? Or with a preparation > patch? > A preparatory patch sounds good. > > > + (int)ELF64_R_TYPE(rel[i].r_info), loc, val); > > > + return -ENOEXEC; > > > + } > > > + write(loc, &val, write_size); > > > + } else { > > > + if (memcmp(loc, &val, write_size)) { > > > + pr_warn("x86/modules: Clearing invalid relocation target, existing value does not match expected value for type %d, loc %p, val %Lx\n", > > > + (int)ELF64_R_TYPE(rel[i].r_info), loc, val); > > > + } > > > + write(loc, &zero, write_size); > > > > If the value doesn't match then something has gone badly wrong. Why go > > ahead with the clearing in that case? > > We can pr_err() then return -ENOEXEC (?). But I guess we need to > handle the error case in: > klp_cleanup_module_patches_limited() > klp_module_coming() > klp_module_going() > and all the functions that call klp_module_going(). > > This seems a big overkill to me... > > Or do you mean we just skip the write()? At the very least, skip the write. But I really think it should just break out of the loop and return an error, there's no point in trying to continue clearing the rest of the relocations if one of them failed. It's probably fine for the callers to ignore the error, the module's going to get unloaded regardless. -- Josh