Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1309922ybz; Wed, 22 Apr 2020 18:13:42 -0700 (PDT) X-Google-Smtp-Source: APiQypKumfWMScf5kcyRIVXGbksixX+Q1xXWSjH4KN1tIqGoVzrY6kORhKHZ77zkXyEWapFS9FyO X-Received: by 2002:a17:906:770b:: with SMTP id q11mr750359ejm.224.1587604422685; Wed, 22 Apr 2020 18:13:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587604422; cv=none; d=google.com; s=arc-20160816; b=0xnbWPc7rOD+fqtu+WvRoULXm0lT/eO2dwfAx2s3PMPY/5t6UmEWaOlT2KLjxP89Y7 sxTqgPPwIL/D3CkLb8v2yHk+kH92K9lr9ZYJBqjxCfSUzbTCHGXh/LK7QPpYt0vBoDX7 yRGeE9EYvpCmSPpFL3LtqVZAYiVNox0uEUcbIEgr3rfOawOEXZCigy43lIVuj0xlK30y K+QkPKKUKH6Bax/2wpykdmun0gTgx8jlK2Nhgs0+vIOIIXERmF/lYC6cZHEhSBDFjLmE ammjU3LQMaZptJB3ILLYwbVW+5IzNDCAlKnnvb4dPtuZmabQUreswr2xfhkhVP3ImYPx +vBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=gpmF7iLJaKAhFgik0YYBKvZq2mUVWcZ8e1b5KXEpW50=; b=gZkaBvjosuq7IODSulxjDhnYatGkBKP5H8LOr0juMFBgt4WLXA/Edx5HMf9MAZlxZm Qww+xxJf+eF4i1PNlRlGoTwWzjktimWax+mWv3ieqCX252vlz000gU1sS2Cxa44LYn6k b6zzUZKMukDnYoRFp4e64LKle8NcvxUYWG0HSuHTfd35sE1r4UF63SQMxEeslJUNONCi +l0rbQrKmlQTVtwcU2o2lm5GI34EG5UDJ5g5l/xn5up5n/FnZCeY5PjOlD2yu1dRNQ4x 04X+iVq1Z3ryP9zEr1DejBhlqDk3xtXpVBAm5FjyvOP0bRfsVefR216VkteDKEOMR+fA HzEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SOmfqeMh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t5si444143edi.241.2020.04.22.18.13.00; Wed, 22 Apr 2020 18:13:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SOmfqeMh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726398AbgDWBKO (ORCPT + 99 others); Wed, 22 Apr 2020 21:10:14 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:28303 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725846AbgDWBKO (ORCPT ); Wed, 22 Apr 2020 21:10:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587604212; 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: in-reply-to:in-reply-to:references:references; bh=gpmF7iLJaKAhFgik0YYBKvZq2mUVWcZ8e1b5KXEpW50=; b=SOmfqeMhf/1fZXurLWVsDyzoExXmG4YFvPXyx2xASAbxafAAuKm3c0rUjLjmyd0ypqBiB1 aLeb6NIH7YMTgliE1xTgY1fPmCLPnCR8kUgEtoJSmBPqQtNY5xd+rzZz3ddpV1dWlAllJR Fmly3BWj8oQNWD4GZYu1gHdJC1HDQTs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-453-B2P9V75uPF6XHblE7rVSvA-1; Wed, 22 Apr 2020 21:10:09 -0400 X-MC-Unique: B2P9V75uPF6XHblE7rVSvA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5DB4F1005510; Thu, 23 Apr 2020 01:10:08 +0000 (UTC) Received: from redhat.com (ovpn-112-171.phx2.redhat.com [10.3.112.171]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CFA465D9E2; Thu, 23 Apr 2020 01:10:05 +0000 (UTC) Date: Wed, 22 Apr 2020 21:10:03 -0400 From: Joe Lawrence To: Josh Poimboeuf Cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Peter Zijlstra , Jessica Yu Subject: Re: [PATCH v2 2/9] livepatch: Apply vmlinux-specific KLP relocations early Message-ID: <20200423011003.GA20432@redhat.com> References: <83eb0be61671eab05e2d7bcd0aa848f6e20087b0.1587131959.git.jpoimboe@redhat.com> <20200420175751.GA13807@redhat.com> <20200420182516.6awwwbvoen62gwbr@treble> <20200420190141.GB13807@redhat.com> <20200420191117.wrjauayeutkpvkwd@treble> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200420191117.wrjauayeutkpvkwd@treble> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 20, 2020 at 02:11:17PM -0500, Josh Poimboeuf wrote: > On Mon, Apr 20, 2020 at 03:01:41PM -0400, Joe Lawrence wrote: > > > > ... apply_relocations() is also iterating over the section headers (the > > > > diff context doesn't show it here, but i is an incrementing index over > > > > sechdrs[]). > > > > > > > > So if there is more than one KLP relocation section, we'll process them > > > > multiple times. At least the x86 relocation code will detect this and > > > > fail the module load with an invalid relocation (existing value not > > > > zero). > > > > > > Ah, yes, good catch! > > > > > > > The same test case passed with a small modification to push the foreach > > KLP section part to a kernel/livepatch/core.c local function and > > exposing the klp_resolve_symbols() + apply_relocate_add() for a given > > section to kernel/module.c. Something like following... > > I came up with something very similar, though I named them > klp_apply_object_relocs() and klp_apply_section_relocs() and changed the > argument order a bit (module first). Since it sounds like you have a > test, could you try this one? > > diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h > index 533359e48c39..fb1a3de39726 100644 > --- a/include/linux/livepatch.h > +++ b/include/linux/livepatch.h > > [ ... snip ... ] > > @@ -245,10 +245,10 @@ static inline void klp_update_patch_state(struct task_struct *task) {} > static inline void klp_copy_process(struct task_struct *child) {} > > static inline > -int klp_write_relocations(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, > - const char *shstrtab, const char *strtab, > - unsigned int symindex, struct module *pmod, > - const char *objname) > +int klp_apply_section_relocs(struct module *pmod, Elf_Shdr *sechdrs, > + const char *shstrtab, const char *strtab, > + unsigned int symindex, unsigned int secindex, > + const char *objname); ^^ Whoops, stray semicolon in !CONFIG_LIVEPATCH case. I found it by botching my cross-compiling .config, but the build-bot might find it when you push your branch. > { > return 0; > } -- Joe