Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp72053ybx; Tue, 29 Oct 2019 14:32:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqx2Tzd/RP3rF62BHvMeTNOW1CTSHmbxDHJlPiWuKifkYK0lzBuVlxjEUOlIqpJ38ojv9sKb X-Received: by 2002:a17:906:e2cb:: with SMTP id gr11mr5663509ejb.205.1572384745353; Tue, 29 Oct 2019 14:32:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572384745; cv=none; d=google.com; s=arc-20160816; b=foC31+rRyInbnf3OAkcKRSvCoIeo/H3nbSjV+PdX4WzG/Uh+u1lbYRQkB2aab0I2yB v38FWt+sFq5zVbatoy+qAZ3sT8fUjnpso0YWsg0J9cY1KT/wlZTrcG/ijj16NZyZoxQH F3VJIKUlnE8x6rHiWvb97re6Es2mbadpFS79uDmzGcxy4wLb6ywkBpfg7ATkLhmSfFJB Orz+5IBSdUGKBNOE9tllhsXO1agon2AHcUl1AWeZTvZl4LJZlawg+IndTG+gvtNqjgiL QzrDK/uFqL+hva+vhXlry1M8WHWNyRuLLjMon7Ts2DYPyaEr3L253aaBOAK4P5JEFxDH fxCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=zjXTK8wqc+micfhU3PtaSFSd9eN2mP8dCcEeCTySNXs=; b=h+ZteXMA0janTUYE3Z8+ERJj4lx8rXEAkaxjqi+rXh/8PbDTOkXib7P3ROG5LyjX9X 71SBOiSCWKiaAIYJ/KJEGYS5/ug/NTLBEXp/ZgYr6BszXVqTIFp62vudiujosvYKk8Nc KAF2pxFLfAuak9rwzPA+hT6XW5yySPzwmkSClOWWbg1KKkcpx7SJyRd1AYhZsjVLULn9 yE4KnpWwIYWU6G2ZE7Q1C8Y7EofVU47uDF/tuJou/GMHBRW/pQ9QF9KqULCQ9EtZqwkC KAETpBJLmLQJI7D2+qkbkqW45SvxZnjlq3qhLdUU2+lHvupip1AOVm+TS/j8jIVq+Mk/ 8NXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="bK/S1BlN"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g14si8180776ejx.238.2019.10.29.14.32.01; Tue, 29 Oct 2019 14:32:25 -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=pass header.i=@chromium.org header.s=google header.b="bK/S1BlN"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728679AbfJ2Vad (ORCPT + 99 others); Tue, 29 Oct 2019 17:30:33 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:37276 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726364AbfJ2Vac (ORCPT ); Tue, 29 Oct 2019 17:30:32 -0400 Received: by mail-ed1-f66.google.com with SMTP id e12so61983edr.4 for ; Tue, 29 Oct 2019 14:30:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zjXTK8wqc+micfhU3PtaSFSd9eN2mP8dCcEeCTySNXs=; b=bK/S1BlNrTZX7xIW1sXhw8Fva50fgp2jCLXmx0dNxNdaHjwy5/0nsVOn2M3e4zMndS ylG17btxpUvCOnh3po1QOsl4zYyVzclox07WqLhIhzoEUjWE0jPgbGjIoMpMt+4hzaxz xphwlkYHW3IuOdu+kxcOFdy/GMp5nH05i8uOU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zjXTK8wqc+micfhU3PtaSFSd9eN2mP8dCcEeCTySNXs=; b=Emuc2HAI63/yE6+RNp9FkcaOESbEqOLUvnInvVX/PdVsb4yCnbezuujuzVPsufxww5 fwOqrZe8yJfkrIN7AwSHmHRocVxJmY8x5CnEQxwQfMVJP1xNJ9Y/o5QB7FH7nE9ki0Y7 1738vO5fEfphzMnlIKHUZ8EKbuzLSnWL2I0ZgyHROLRd5KcKhM6c4KdQcWtNk7/ZfBk7 xNeh/T3KIK5SaVRNo57sm8MNXJBW1NQQkSOTAqqk2OCqvqy08vK84YUzVZsF+yFPfE5A 0DQMRw+1bZOASKdNnIn+qe4I0iv1xCpur2doM/KJ86g5k7VxkGLjACZCA3jTJEBdLWcl Yggg== X-Gm-Message-State: APjAAAXm2GmwQZGfYE1aW/cWrR8Ssk5uRKdQ9X78enWG5MWurFFpTZGg i6txQCbCvxwobnasYQ2y0SU5PW70rwg= X-Received: by 2002:aa7:db49:: with SMTP id n9mr28608801edt.105.1572384628966; Tue, 29 Oct 2019 14:30:28 -0700 (PDT) Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com. [209.85.128.44]) by smtp.gmail.com with ESMTPSA id s9sm648ejf.44.2019.10.29.14.30.28 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 29 Oct 2019 14:30:28 -0700 (PDT) Received: by mail-wm1-f44.google.com with SMTP id 22so3972048wms.3 for ; Tue, 29 Oct 2019 14:30:28 -0700 (PDT) X-Received: by 2002:a05:600c:1150:: with SMTP id z16mr6173967wmz.153.1572384627393; Tue, 29 Oct 2019 14:30:27 -0700 (PDT) MIME-Version: 1.0 References: <20190730191303.206365-1-thgarnie@chromium.org> <20190730191303.206365-11-thgarnie@chromium.org> <20190731125306.GU31381@hirez.programming.kicks-ass.net> <20190812125540.GD23772@zn.tnic> In-Reply-To: <20190812125540.GD23772@zn.tnic> From: Thomas Garnier Date: Tue, 29 Oct 2019 14:30:15 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v9 10/11] x86/paravirt: Adapt assembly for PIE support To: Borislav Petkov Cc: Peter Zijlstra , Kernel Hardening , Kristen Carlson Accardi , Kees Cook , Juergen Gross , Thomas Hellstrom , "VMware, Inc." , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , "the arch/x86 maintainers" , virtualization@lists.linux-foundation.org, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 12, 2019 at 5:54 AM Borislav Petkov wrote: > > On Wed, Jul 31, 2019 at 02:53:06PM +0200, Peter Zijlstra wrote: > > 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, > > Well, before it, the relative CALL is a CALL reg/mem64, i.e. the target > is mem64. For example: > > > ffffffff81025c45: ff 14 25 68 37 02 82 callq *0xffffffff82023768 > > That address there is practically pv_ops + offset. > > Now, in the opcode bytes you have 0xff opcode, ModRM byte 0x14 and SIB > byte 0x25, and 4 bytes imm32 offset. And this is 7 bytes. > > What it becomes is: > > ffffffff81025cd0: ff 15 fa d9 ff 00 callq *0xffd9fa(%rip) # ffffffff820236d0 > ffffffff81025cd6: 90 nop > > which is a RIP-relative, i.e., opcode 0xff, ModRM byte 0x15 and imm32. > And this is 6 bytes. > > And since the paravirt patching doesn't do NOP padding like the > alternatives patching does, you need to pad with a byte. > > Thomas, please add the gist of this to the comments because this > incomprehensible machinery better be documented as detailed as possible. Sorry for the late reply, busy couple months. Will add it. > > Thx. > > -- > Regards/Gruss, > Boris. > > Good mailing practices for 400: avoid top-posting and trim the reply.