Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp76848imm; Thu, 30 Aug 2018 08:41:27 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb/LpB04RalntXODFjljQKBolZajhcls528ri1tbBi2cl5LXHY2R6X3NhNgcrELF3Y9yMI9 X-Received: by 2002:a62:438f:: with SMTP id l15-v6mr11185327pfi.196.1535643687900; Thu, 30 Aug 2018 08:41:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535643687; cv=none; d=google.com; s=arc-20160816; b=WjdXJiAtzHy4JljmvH1biEetsqE711PN/1h9lXzdgDi+GlhO77PjkZ5SxT6qFSK1YX IlaJtMs8KZcsHh5cY1xwfamiSUFgkzU8jRWGjL0WwXI0IK3Qr+wSX4VKDTm71U+4B12d Ek2iYfLZ/h2Jlpgh+fr+61suMQNVqWaJfeA5JBmMJBn58Om84DzTexwa12Lkx2u45wTd zjXkVz/2qJLHQyVk0+N5Usq0YStRA7zNk3d8XrI55ZdrQPwhPxi0/v4A+QFtbnX5fymT gDlZBA+KXTAw8yPRAFCwRqlaKZ1kcGWNrz1MG7AlkXuBmtkCy4sOeSveHZ0BkUIIbxc9 gdQw== 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 :arc-authentication-results; bh=Kz8MQNPDzN7DpxJUSNa0x2jNVynzAGDge5M0MJqhY20=; b=YRla3b8io2MvcN23LbgVbVTCiZJrwNlH+uPPFMka2VoaMVNPJtdCLE3E0KBhZ178u2 9S3GeWfDsLwQ/pt97GRSr4MqLFFu7/w2XLy3VoWbRPoSNWWucOUm2SR77uJMqY9wPt+2 GksQgbLfEKPXQF5gPIydpRx7rCsvdD+Ow5Ke8pnoYQObMcUA1GgWis+2I2VpXANXT7hB WDu3SXM6f2nUJmO1XcYtsv9hZnwkHAV/SMWhMTorqtIYWx9naVL9ns6aENYbuQcuygFM z8ZuD9IulSb0G0W7Yk/c6vFSrmhROL1PlsXrcUc6VfN4xFPkJAPi4u2QOwUPMK75rcpJ l+3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=GahXkin8; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o12-v6si7038055pfd.142.2018.08.30.08.41.13; Thu, 30 Aug 2018 08:41:27 -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=@google.com header.s=20161025 header.b=GahXkin8; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727429AbeH3Tmr (ORCPT + 99 others); Thu, 30 Aug 2018 15:42:47 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:41833 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726878AbeH3Tmq (ORCPT ); Thu, 30 Aug 2018 15:42:46 -0400 Received: by mail-oi0-f65.google.com with SMTP id k12-v6so16192356oiw.8 for ; Thu, 30 Aug 2018 08:40:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Kz8MQNPDzN7DpxJUSNa0x2jNVynzAGDge5M0MJqhY20=; b=GahXkin85mYJmrx3gkxXQUSOqfxLsi/S3VnWOXUHAnhj2laosZYLnElcPMFU9jBlcM MpeaAdrPAiq0cIZUu06yCjopY/3JAhnPiFzVo7CzX9/Sa5TBQMYgH5E48wCryCZXWoQY K2OiwrfN+NapCxb6HlqTTc1S1mjkkyi7a5Y1+YRH2UkUpcNfqiAEUzj/oxCZ0TONKgJC gUUYYiUnAmJl2qm99Uz/1rdppwThCn97f79155Vo2tuFLecwQk5drDbdd/fIItHv7RmF xOQe14fJb+0XH2Vuu+UGJKsbhqgBI8qi3NuJ49joiSzqZFxBUQS3GHkn3Dkjps+yxMEf 3vlQ== 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=Kz8MQNPDzN7DpxJUSNa0x2jNVynzAGDge5M0MJqhY20=; b=JMhi3jf8br3rQ52Q3EWTfqwhyLNuuLMZzzpQo5BAw0SPdCcch3EZWZgsRcqlBCx2UT jUXFenisJNTIG0vx3jZR4MDM1PyuNiTX/rLV2g9UmOJmlthQwGpY9GS8IsHhCHLU87fZ 0gvxHq+PnsQ6D8Uvw4o/hZvY4+7zuz8TUJ+jAj5/j5G2A9aoUsB6Mz5X+tny6/5EhN92 Aiw7VdBSpk7aTg7RRA2uyyTe6MV15iVyzFdpNHMD67h+322GkIO3/3WLvUl75654g0Qn VjxkjG7mG+Jl/DMqMnoB9f/qagz/ySYXhE606o219922AxvF0p7A6/dOmnBkf9O7fgp7 JPHg== X-Gm-Message-State: APzg51B+7EG+kkIURCeQQYz+rD2zl/qJWiBKaFo7JLSjpOwo2/89chGk +Awjww8Bd5CEUDKFf/9dILdE6GyElwp1s6eR2UI1fw== X-Received: by 2002:aca:4204:: with SMTP id p4-v6mr2836500oia.242.1535643601937; Thu, 30 Aug 2018 08:40:01 -0700 (PDT) MIME-Version: 1.0 References: <20180830143904.3168-1-yu-cheng.yu@intel.com> <20180830143904.3168-20-yu-cheng.yu@intel.com> In-Reply-To: <20180830143904.3168-20-yu-cheng.yu@intel.com> From: Jann Horn Date: Thu, 30 Aug 2018 17:39:35 +0200 Message-ID: Subject: Re: [RFC PATCH v3 19/24] x86/cet/shstk: Introduce WRUSS instruction To: yu-cheng.yu@intel.com Cc: "the arch/x86 maintainers" , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , kernel list , linux-doc@vger.kernel.org, Linux-MM , linux-arch , Linux API , Arnd Bergmann , Andy Lutomirski , Balbir Singh , Cyrill Gorcunov , Dave Hansen , Florian Weimer , hjl.tools@gmail.com, Jonathan Corbet , keescook@chromiun.org, Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , ravi.v.shankar@intel.com, vedvyas.shanbhogue@intel.com 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 Thu, Aug 30, 2018 at 4:44 PM Yu-cheng Yu wrote: > > WRUSS is a new kernel-mode instruction but writes directly > to user shadow stack memory. This is used to construct > a return address on the shadow stack for the signal > handler. > > This instruction can fault if the user shadow stack is > invalid shadow stack memory. In that case, the kernel does > fixup. > > Signed-off-by: Yu-cheng Yu [...] > +static inline int write_user_shstk_64(unsigned long addr, unsigned long val) > +{ > + int err = 0; > + > + asm volatile("1: wrussq %1, (%0)\n" > + "2:\n" > + _ASM_EXTABLE_HANDLE(1b, 2b, ex_handler_wruss) > + : > + : "r" (addr), "r" (val)); > + > + return err; > +} What's up with "err"? You set it to zero, and then you return it, but nothing can ever set it to non-zero, right? > +__visible bool ex_handler_wruss(const struct exception_table_entry *fixup, > + struct pt_regs *regs, int trapnr) > +{ > + regs->ip = ex_fixup_addr(fixup); > + regs->ax = -1; > + return true; > +} And here you just write into regs->ax, but your "asm volatile" doesn't reserve that register. This looks wrong to me. I think you probably want to add something like an explicit `"+&a"(err)` output to the asm statements. > @@ -1305,6 +1305,15 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code, > error_code |= X86_PF_USER; > flags |= FAULT_FLAG_USER; > } else { > + /* > + * WRUSS is a kernel instrcution and but writes Nits: typo ("instrcution"), weird grammar ("and but writes")