Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp5949399ybi; Wed, 31 Jul 2019 06:00:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqyjhl/utr3S2co+tez3Bpf5z7sdGnpf6XJfXecyKqaFIcap4Kf6vsVRR4OcKNwQyb+NQbNd X-Received: by 2002:a62:5883:: with SMTP id m125mr46982039pfb.248.1564578006500; Wed, 31 Jul 2019 06:00:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564578006; cv=none; d=google.com; s=arc-20160816; b=CF6X0Dw8XiaOmhgMnaaiT4Sdn1TSI83mEOW2Y50U+0tzlhnq94lhHTEPX6Pac1Ln1z 9w4AiHo6nJlGn51tHSfHN4m2ADC2w0UYDuiXVbeTa0oUTNPI+5a8dSEtf0h80K5noHkh dbfFBz/MJBVTuZVbMmM+SLbExnsDAouJs/5h1ScnQp96vR4hK0ARK8w2Iu3+LbgQXMyP l7FsExKGBTVjrWv9iwgqK3gwCExIoGLWZU34e1Evp1zhDX3HAQo+M0ukU5EviDScxCQB Zyr1YnmuBFFSzMcJtxgWjreR/cEDZoGspo97ProLfCF5wvDXREiFGqK7i2rBgpXEeO9e CGyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=aeUs+tisL054K/og1W1ep85O/gPdmrMrcRsVDP6dWHA=; b=ahSq6KGT1YKyly8vzFBf7ItlMic+ODBmxVwyLGdICnd9IHgb6DmRZ59L6MryQvmDm+ 5JWnV11/vP4aTxtJ8ZSJfLAHbzL6g9xSd1xU8M3FqhhT8UdgyQLeD6prHgNheKMUK3PV TyHsRgT3xw900+3WT3Py0HnxsIqcDZazA5ZispMk3XBH8bPT/HEu0lhPkH6EovQwL3AC djcRi8EXEuV+xxzXqcyjGpLrpCnAk7pr3KXr1n/yeSVVZEvPqeo4e+88pI6EKuE+SOcT suMkwJQIXrKxN3tpIAx+c9k/0rS4RZsKuwvdJZjmvF++oOMbzfOuiVKzklzrpzpx43mo uRaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=oaTRIpZM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e92si29773357pld.312.2019.07.31.05.59.51; Wed, 31 Jul 2019 06:00:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=oaTRIpZM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387730AbfGaMxX (ORCPT + 99 others); Wed, 31 Jul 2019 08:53:23 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:50392 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726125AbfGaMxX (ORCPT ); Wed, 31 Jul 2019 08:53:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=aeUs+tisL054K/og1W1ep85O/gPdmrMrcRsVDP6dWHA=; b=oaTRIpZMm2SA2ctz/ryJdx5ia /LKWmt439ZZvb35/VbYw9o8t12tJoXD6aI6hksP1Xc+hICCc3+lbHuj2nrT2bZGD1twR9eAYcBLn/ E4fayvpXE78Jw5t1qTC2DQir3SQ56cuhq76gfVZUwqhIWVMHnJr4SucdiMqH6GzfyHVgrvLzspEr6 JvFKdCyBT4g80kxsamgYcCog1sbUPhjzsmhDI3r3QnLSV/wR0XpPExqeFZbaEJuIgqkq8O0zqND35 Ko51GPcra8ktSo4PMvM4DARlpmoUDUTy+UxkL/JmshGg8qarRhlaIOSNQ+vtaaJyNIRbpM938EXsL 5GTiOT9LQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1hso6O-0004bd-AJ; Wed, 31 Jul 2019 12:53:08 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 10ABA2029FD58; Wed, 31 Jul 2019 14:53:06 +0200 (CEST) Date: Wed, 31 Jul 2019 14:53:06 +0200 From: Peter Zijlstra To: Thomas Garnier Cc: kernel-hardening@lists.openwall.com, kristen@linux.intel.com, keescook@chromium.org, Juergen Gross , Thomas Hellstrom , "VMware, Inc." , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v9 10/11] x86/paravirt: Adapt assembly for PIE support Message-ID: <20190731125306.GU31381@hirez.programming.kicks-ass.net> References: <20190730191303.206365-1-thgarnie@chromium.org> <20190730191303.206365-11-thgarnie@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190730191303.206365-11-thgarnie@chromium.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 30, 2019 at 12:12:54PM -0700, Thomas Garnier wrote: > if PIE is enabled, switch the paravirt assembly constraints to be > compatible. The %c/i constrains generate smaller code so is kept by > default. > > Position Independent Executable (PIE) support will allow to extend the > KASLR randomization range below 0xffffffff80000000. > > Signed-off-by: Thomas Garnier > Acked-by: Juergen Gross > --- > arch/x86/include/asm/paravirt_types.h | 25 +++++++++++++++++++++---- > 1 file changed, 21 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h > index 70b654f3ffe5..fd7dc37d0010 100644 > --- a/arch/x86/include/asm/paravirt_types.h > +++ b/arch/x86/include/asm/paravirt_types.h > @@ -338,9 +338,25 @@ extern struct paravirt_patch_template pv_ops; > #define PARAVIRT_PATCH(x) \ > (offsetof(struct paravirt_patch_template, x) / sizeof(void *)) > > +#ifdef CONFIG_X86_PIE > +#define paravirt_opptr_call "a" > +#define paravirt_opptr_type "p" > + > +/* > + * Alternative patching requires a maximum of 7 bytes but the relative call is > + * only 6 bytes. If PIE is enabled, add an additional nop to the call > + * instruction to ensure patching is possible. > + */ > +#define PARAVIRT_CALL_POST "nop;" I'm confused; where does the 7 come from? The relative call is 6 bytes, a normal call is 5 bytes (which is what we normally replace them with), and the longest 'native' sequence we seem to have is also 6 bytes (.cpu_usergs_sysret64). > +#else > +#define paravirt_opptr_call "c" > +#define paravirt_opptr_type "i" > +#define PARAVIRT_CALL_POST "" > +#endif > + > #define paravirt_type(op) \ > [paravirt_typenum] "i" (PARAVIRT_PATCH(op)), \ > - [paravirt_opptr] "i" (&(pv_ops.op)) > + [paravirt_opptr] paravirt_opptr_type (&(pv_ops.op)) > #define paravirt_clobber(clobber) \ > [paravirt_clobber] "i" (clobber) > > @@ -379,9 +395,10 @@ int paravirt_disable_iospace(void); > * offset into the paravirt_patch_template structure, and can therefore be > * freely converted back into a structure offset. > */ > -#define PARAVIRT_CALL \ > - ANNOTATE_RETPOLINE_SAFE \ > - "call *%c[paravirt_opptr];" > +#define PARAVIRT_CALL \ > + ANNOTATE_RETPOLINE_SAFE \ > + "call *%" paravirt_opptr_call "[paravirt_opptr];" \ > + PARAVIRT_CALL_POST