Received: by 10.223.185.116 with SMTP id b49csp1014446wrg; Fri, 16 Feb 2018 10:50:13 -0800 (PST) X-Google-Smtp-Source: AH8x227354LQUWNbhl+Ll7TIfHpJy+OF/88UfwLaMnc+ZOFDfWv2imMwe6wTzf8AnoktgYP60T49 X-Received: by 10.98.139.145 with SMTP id e17mr1060803pfl.53.1518807013812; Fri, 16 Feb 2018 10:50:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518807013; cv=none; d=google.com; s=arc-20160816; b=DVG42doytesy4lZc4EnYeDszwFlBqttNTnf6TP6u7DflKgYKNU9tv/mCKnLPy4TfJN d/l/IX9+pvbeqxC4zLfqFXeaFDIqayCJ9XUNHEBa597HTMEqF8Uzkcus6sPFEiAeBQhx JpR1mRDkKTfCkza9D9IHkoWT0a/ngfFxgciZDFvKdxCzh2x0O1MbYKKoeJxq/mbSdLAf fhtT9z3I91S0/HInvWXvHmGpJpBEDsJn5hgD0AUNGY7aGnfXrnEC3rBHe03cai3jXLZA YTHFWXjIxHjS8nMwFOeOwWTjSfkoI285sIgy7xrzFGOoLgUBUM5S098eXlNLSie88voR dxkg== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=d+mqqHcC/sSaYCu+LerF94LolST7/5ikGAkK+NN7lcM=; b=Twdo0KNOT6ST/Rs2eVHKHdTuXE0pa/9qlau1ODW3l2Q09xpr6RqRPQZWXmBjC0w1s0 Eq7P2PWcAhcspEgGUAhPlAjqSZduQRcqH9Zdkjx5S8Uen5SOxmRCX4FG81XayTz3iRxo oVjEmavSqY9bGYyAHyqKA9OjR8TILhyT+5APcQINneBKew/LZA/dUgzQJzcoXIv1Djv+ uQ6R+yO6Ss8FIWjCY2QNBD+AT68oZMXE6s0uE1JnWDk3Lxp9bOPr/ljko8VX+so7/3ys vo709T7C5i8EO8nwxeqz2r3Jg1MMGbfUyIX+YAmlzdwIcVm41N01J/GAicqlpMfFkFo+ VS6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BjCUutOj; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r7si1689249pgs.227.2018.02.16.10.49.59; Fri, 16 Feb 2018 10:50:13 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=BjCUutOj; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753524AbeBPHLo (ORCPT + 99 others); Fri, 16 Feb 2018 02:11:44 -0500 Received: from mail-lf0-f44.google.com ([209.85.215.44]:41052 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753481AbeBPHLn (ORCPT ); Fri, 16 Feb 2018 02:11:43 -0500 Received: by mail-lf0-f44.google.com with SMTP id f136so2770226lff.8 for ; Thu, 15 Feb 2018 23:11:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=d+mqqHcC/sSaYCu+LerF94LolST7/5ikGAkK+NN7lcM=; b=BjCUutOjdDT+8p+CgZnujRbgURlIixq9ZpirgRqH9Ww1PUfgs72kWpQR1p2Gf0w9zW dtFuCFZtYJ1EnVS4ZFEZnMu1M6F2VHXy21GTPDReEQsZEvwv2ae5JMR3U3v5nAWmVfDW ltSiFAjHJcGK7nw5bBGkD4R4f2QPnCfIE9MkuIc8szO4tv9AWtv6qkAn51Wuz+owEpPm XSmlMHgnSGG/3tMsgoTby2/LtdiGc1CfyqKHXMGJb3eh89anplNscX2zgY+WcYRXhpST LXki1wawX6mlPKo4mnmJIgLTJQRj6aeuQ5fOots8YZeoKUf6Bq1DQXEpiGCAC+3SY2sd ppTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=d+mqqHcC/sSaYCu+LerF94LolST7/5ikGAkK+NN7lcM=; b=M/HAJV4CQ6oHduBpJtv+ZO/3f/Jtu4DEA/qJgsJ+OmH0IqsV9urBzdeiPKlK/hXEX2 UOYdKe4niML8kfcNkwNXNrFnSnLLHsl9ZagDgtmbT0glWXmG0pTMBVYC0p85FEOrfxNp DDq3Q8NXJep8mGsERgyUm8bd5f3/bxOhSJmprN3L40vEc1i2eVDjdZH1r5CVe/NZufTz yYZRM522vUiOiFj0Ev+WRr7y/oQowOzoaLdp02OmnrTtQRJzV70IymLgxiC1tzuV58ta pYVDNUTIWa7+O/bk2+Ggkh5HWYkfMprsm431UKbLcoiG1Nvtfh62KCnYep+Eu43G7I4J 8cTQ== X-Gm-Message-State: APf1xPB1xJS13mcnSx3YNKKchj8K57rFdQKcrA+22MWvwOTkYuWJZMXX ExMLZefPO8yhJqUXonY0Nvw= X-Received: by 10.46.18.137 with SMTP id 9mr3723518ljs.106.1518765101873; Thu, 15 Feb 2018 23:11:41 -0800 (PST) Received: from uranus.localdomain ([5.18.102.224]) by smtp.gmail.com with ESMTPSA id h3sm3552045lfe.70.2018.02.15.23.11.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 15 Feb 2018 23:11:40 -0800 (PST) Received: by uranus.localdomain (Postfix, from userid 1000) id EC100460D01; Fri, 16 Feb 2018 10:11:39 +0300 (MSK) Date: Fri, 16 Feb 2018 10:11:39 +0300 From: Cyrill Gorcunov To: Andy Lutomirski , Andrey Vagin , Dmitry Safonov Cc: Nadav Amit , Pavel Emelyanov , Linus Torvalds , Ingo Molnar , Thomas Gleixner , Peter Zijlstra , Dave Hansen , Willy Tarreau , X86 ML , LKML Subject: Re: [PATCH RFC v2 4/6] x86: Disable PTI on compatibility mode Message-ID: <20180216071139.GC32767@uranus> References: <20180215163602.61162-1-namit@vmware.com> <20180215163602.61162-5-namit@vmware.com> <9EB804CA-0EC9-4CBB-965A-F3C8520201E7@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 15, 2018 at 11:29:42PM +0000, Andy Lutomirski wrote: ... > >>> +bool pti_handle_segment_not_present(long error_code) > >>> +{ > >>> + if (!static_cpu_has(X86_FEATURE_PTI)) > >>> + return false; > >>> + > >>> + if ((unsigned short)error_code != GDT_ENTRY_DEFAULT_USER_CS << 3) > >>> + return false; > >>> + > >>> + pti_reenable(); > >>> + return true; > >>> +} > >> > >> Please don't. You're trying to emulate the old behavior here, but > >> you're emulating it wrong. In particular, you won't trap on LAR. > > > > Yes, I thought I’ll manage to address LAR, but failed. I thought you said > > this is not a “show-stopper”. I’ll adapt your approach of using prctl, although > > it really limits the benefit of this mechanism. > > > > It's possible we could get away with adding the prctl but making the > default be that only the bitness that matches the program being run is > allowed. After all, it's possible that CRIU is literally the only > program that switches bitness using the GDT. (DOSEMU2 definitely does > cross-bitness stuff, but it uses the LDT as far as I know.) And I've > never been entirely sure that CRIU fully counts toward the Linux > "don't break ABI" guarantee. > > Linus, how would you feel about, by default, preventing 64-bit > programs from long-jumping to __USER32_CS and vice versa? I think it > has some value as a hardening measure. I've certainly engaged in some > exploit shenanigans myself that took advantage of the ability to long > jump/ret to change bitness at will. This wouldn't affect users of > modify_ldt() -- 64-bit programs could still create and use their own > private 32-bit segments with modify_ldt(), and seccomp can (and > should!) prevent that in sandboxed programs. > > In general, I prefer an approach where everything is explicit to an > approach where we almost, but not quite, emulate the weird historical > behavior. > > Pavel and Cyrill, how annoying would it be if CRIU had to do an extra > arch_prctl() to enable its cross-bitness shenanigans when > checkpointing and restoring a 32-bit program? I think this should not be a problem for criu (CC'ing Dima, who has been working on compat mode support in criu). As far as I remember we initiate restoring of 32 bit tasks in native 64 bit mode (well, ia32e to be precise :) mode and then, once everything is ready, we changing the mode by doing a return to __USER32_CS descriptor. So this won't be painful to add additional prctl call here.