Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp614528ybi; Fri, 7 Jun 2019 13:43:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwA1qdH6PzSRCFoJBTst9yPxkASoTQyLehiJau5y7elUgwmKS2X9LVQYYBR+AaZIbjosIXy X-Received: by 2002:aa7:9a95:: with SMTP id w21mr60741175pfi.248.1559940183402; Fri, 07 Jun 2019 13:43:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559940183; cv=none; d=google.com; s=arc-20160816; b=dIwrm5X3SWdRJwP8uym54cFxU0DnM2OG/q0KrusciHD7HNMXkBgvOlT++ihDXY1TYf jeZBI5g01B9ujcZsHvXacyjpSLtbZO7f9tMHTlLWhQKL2cjLPRLcVV2vEztDT0cRPzc4 ErC3YZkTxseq/3c133cSr3oL2hG7DS5DIKe+0yvnucgfP3VyJ6TZ2fZ9lIJdJMXgEOVH MXEKi1F6Mph0/TkyjYVyvbco4OYKMkblllAk71UoGmfVeVAK94ZOhFe+CmnnlRIao8nY gawPn2ZJYO37JfNYiEtG2MlzEkDf5aas87hP5GSwEUCkfpYoHbQG3u3lGmzjqcMdGyEf MiGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=/zXZ0PAO7hrTuftMmJADCccAFJNVvLuJoT5zW483dm4=; b=EbOgVkEAE68/GCtCV2ZyNGwC6m87VHBwrblPfQUxxssFIGhrEJqUG660YvbsymzhaB 29ecjLdg8pUf0oXXkPYQG8KqjMJ9DqKM9ei0XX5hIjvZmIN/Zeqh0H7PJoWBz1rzqm87 Ww3+bnc003WXNjovvThD1kQyViOv/uHvx/E0+fhwOi7dF/XUE0WPoMSNPyJ61ATChq1d c1mwB/DbVnW2PXvWlq0CAeDsaDOSlqrHVWZUhifWGyeayMdjwidzVU03AROtKyju/nhf OwkZJxJdPa9JpF1z+Sd+qdqHAXMHatYTkvpTObI1XENTlh5tA1FZf+VAW+wyMQEMTC3L p0UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=xrvdgiwg; 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 132si2907439pfu.263.2019.06.07.13.42.46; Fri, 07 Jun 2019 13:43:03 -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=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=xrvdgiwg; 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 S1730254AbfFGUkK (ORCPT + 99 others); Fri, 7 Jun 2019 16:40:10 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:34688 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729677AbfFGUkJ (ORCPT ); Fri, 7 Jun 2019 16:40:09 -0400 Received: by mail-pg1-f195.google.com with SMTP id h2so1753289pgg.1 for ; Fri, 07 Jun 2019 13:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=/zXZ0PAO7hrTuftMmJADCccAFJNVvLuJoT5zW483dm4=; b=xrvdgiwgMy+n6sUxDDjF6GbcFmqZ9IbL4LqbaOlUjeE8uqFUu4xLwLCn5TySJGkcHl fXPiABlcfNSCw9bl0NwfmBnfApC4fAM1xXXJDZ27D9KyYVvW3Pd4X+nasECUMC2LBZEJ fKA5BQIw1BcsTounoXppfOwxaeXfpEVX0HyHm3x1KFjINzS4PCb6c6IaljqNaSCBm7Od drrmRGWCxY710x1mQlxy/KRBEo0C1hie/MUbVm5jM/+AlavFNb6N+fUr8V+MNbUOPbuC xC4rbQBCWUzb43kM79GQ/pk24o4zNJi31I1dPZeQMzNZkLkM+wXFQ8x1bMx3nK65vvQb mnNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=/zXZ0PAO7hrTuftMmJADCccAFJNVvLuJoT5zW483dm4=; b=ZVqfFEdlWyJdLHg/zgBcbnBWrWdM4taZhCddPhDT5GiwaphYbTvi/0gP+NZe0nGo7i YKD+JZLimlZqqELZJ3NmuLwdYbMjdYYfo3JyTEWfzUVFgk7nQzj2kGTlelCpsz+uZg1N nVw+I6fjPnl8+rlaYWt4UhOsauWxawqCosSlU6xM+2dZjty0Mj6u6oBiQeqgYybsEFnw 7FgR4egV5X1W9AzOErG94E1wZA6Sng6QKtk24LCAwxvWU6htKmk7MWGjoaJ0C8XoFCui //MOP/qQM1okpHD7mqxFXbmd7GPxzHT9e5kCKBfnHp8c/iZ/ax8Uw1gBwursDAZzBw+9 ueow== X-Gm-Message-State: APjAAAX7mq7SPwNHHjy+/cq/0VzotjFcEAIA7bqvB39F0VXMM5PgJ2KM rzQ23bvwx0LUmcLrSY+be0aVyw== X-Received: by 2002:a63:490a:: with SMTP id w10mr4721938pga.6.1559940008694; Fri, 07 Jun 2019 13:40:08 -0700 (PDT) Received: from ?IPv6:2600:1012:b044:6f30:60ea:7662:8055:2cca? ([2600:1012:b044:6f30:60ea:7662:8055:2cca]) by smtp.gmail.com with ESMTPSA id 128sm3433146pff.16.2019.06.07.13.40.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 07 Jun 2019 13:40:07 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) Subject: Re: [PATCH v7 03/14] x86/cet/ibt: Add IBT legacy code bitmap setup function From: Andy Lutomirski X-Mailer: iPhone Mail (16F203) In-Reply-To: <352e6172-938d-f8e4-c195-9fd1b881bdee@intel.com> Date: Fri, 7 Jun 2019 13:40:06 -0700 Cc: Peter Zijlstra , Yu-cheng Yu , x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin Content-Transfer-Encoding: quoted-printable Message-Id: References: <20190606200926.4029-1-yu-cheng.yu@intel.com> <20190606200926.4029-4-yu-cheng.yu@intel.com> <20190607080832.GT3419@hirez.programming.kicks-ass.net> <20190607174336.GM3436@hirez.programming.kicks-ass.net> <34E0D316-552A-401C-ABAA-5584B5BC98C5@amacapital.net> <352e6172-938d-f8e4-c195-9fd1b881bdee@intel.com> To: Dave Hansen Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Jun 7, 2019, at 11:58 AM, Dave Hansen wrote: >=20 > On 6/7/19 11:29 AM, Andy Lutomirski wrote: > ... >>> I think this new MSR probably needs to get included in oops output when >>> CET is enabled. >>=20 >> This shouldn=E2=80=99t be able to OOPS because it only happens at CPL 3, >> right? We should put it into core dumps, though. >=20 > Good point. >=20 > Yu-cheng, can you just confirm that the bitmap can't be referenced in > ring-0, no matter what? We should also make sure that no funny business > happens if we put an address in the bitmap that faults, or is > non-canonical. Do we have any self-tests for that? >=20 > Let's say userspace gets a fault on this. Do they have the > introspection capability to figure out why they faulted, say in their > signal handler? We need to stick the tracker state in the sigcontext somewhere. Did we end up defining a signal frame shadow stack token? >=20 >>> Why don't we require that a VMA be in place for the entire bitmap? >>> Don't we need a "get" prctl function too in case something like a JIT is= >>> running and needs to find the location of this bitmap to set bits itself= ? >>>=20 >>> Or, do we just go whole-hog and have the kernel manage the bitmap >>> itself. Our interface here could be: >>>=20 >>> prctl(PR_MARK_CODE_AS_LEGACY, start, size); >>>=20 >>> and then have the kernel allocate and set the bitmap for those code >>> locations. >>=20 >> Given that the format depends on the VA size, this might be a good >> idea. >=20 > Yeah, making userspace know how large the address space is or could be > is rather nasty, especially if we ever get any fancy CPU features that > eat up address bits (a la ARM top-byte-ignore or SPARC ADI). That gets extra bad if we ever grow user code that uses it but is unaware. I= t could poke the wrong part of the bitmap. >=20 >> Hmm. Can we be creative and skip populating it with zeros? The CPU > should only ever touch a page if we miss an ENDBR on it, so, in normal > operation, we don=E2=80=99t need anything to be there. We could try to pr= event > anyone from *reading* it outside of ENDBR tracking if we want to avoid > people accidentally wasting lots of memory by forcing it to be fully > populated when the read it. >=20 > Won't reads on a big, contiguous private mapping get the huge zero page > anyway? The zero pages may be free, but the page tables could be decently large. Do= es the core mm code use huge, immense, etc huge zero pages? Or can it synth= esize them by reusing page table pages that map zeros? >=20 >> The one downside is this forces it to be per-mm, but that seems like >> a generally reasonable model anyway. >=20 > Yeah, practically, you could only make it shared if you shared the > layout of all code in the address space. I'm sure the big database(s) > do that cross-process, but I bet nobody else does. User ASLR > practically guarantees that nobody can do this. I meant per-mm instead of per-task.