Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp99347imm; Thu, 30 Aug 2018 09:12:29 -0700 (PDT) X-Google-Smtp-Source: ANB0VdabXcd8Lu8AadpcZh8TUfhfGIf+Fy0NTPI1ghOhQNUpw/cDex9rAuv6JP5Cl4rOpko3MfLc X-Received: by 2002:aa7:860b:: with SMTP id p11-v6mr11100501pfn.247.1535645549579; Thu, 30 Aug 2018 09:12:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535645549; cv=none; d=google.com; s=arc-20160816; b=aQ5Vbm3RwQAbyyn0Bzn2N9cyV/Nf/sNMmLsUPpjrPH/Gd32CpBlpTZDIIzaIKvHrqH SDf+Exaqrnr3FNzqI9VA3ItqldccPO8/iwpEq8ze+snYPk9OhHxYCDVHmjGT4eXxAoF/ EnlufVFvHeaj1CgZCjwdAAH669T/AEqS5rZDc1AI6F13U9lj73Usf0B8YcayooCdflkF KSLC28NW+ZDaWY80KZaNm7RLMhAn3XNWWD9FIdo7lveOBTaFKSbMHLX4wDX5bg8huhYn iMKoztXmMDk/Ly0uEbDYOecAmxKgsdWVkECNH2KmDFlMgaLIsT1LDSh1ESmmbeqqd/y/ QU7w== 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=rEnUc164i2YQATkUF5pJh5O66ueEUTaHFCxCD73D8Jg=; b=bBrcKVDnZEEo7ejGJHtql2wNwVOzSQA6sfIzjDFAgRlVJR3dGhudSrIAS0CQ01XiX4 aRFFNeLEk+tGdazIgAkRwJigeY9hf08GTIva4GQQmqJhINSjxara74rwpoBbfJk2jweM 3xZxhGjxdHkYcdN9iogQXg8FUrDhxi9CvGN22dzfcpjGa8Ok6efXbvEzZgD1gibdQDXA HlZb9JWwIEYy5Ovl7UwU1QAJDjOamQW54jhNLxjDY8vI6GkclwCm9+ffIO3ysXycFIfF SQ1Gdhoa+3xOY45Ehn3eZC5Whxs+7LkjeXeU/8GgMVtTL+taaQuZGfnfjLpvOhJI76I5 1pIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=J8ojznWC; 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 e10-v6si7796209pln.161.2018.08.30.09.12.14; Thu, 30 Aug 2018 09:12:29 -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=J8ojznWC; 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 S1727522AbeH3UNh (ORCPT + 99 others); Thu, 30 Aug 2018 16:13:37 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:33350 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727281AbeH3UNh (ORCPT ); Thu, 30 Aug 2018 16:13:37 -0400 Received: by mail-oi0-f67.google.com with SMTP id 8-v6so16435944oip.0 for ; Thu, 30 Aug 2018 09:10:45 -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=rEnUc164i2YQATkUF5pJh5O66ueEUTaHFCxCD73D8Jg=; b=J8ojznWClrn8oTylP5Txwv9bjszqQ8Knvl0cpXwgslSTwBLS2mPofSc8kgD8f5/OC/ Kl4IyKNNbIp9KXPhFZWt3QWtLRPjZ797GkL82J7IeszItAr68mJYnmush16u6/bdb1kS C9uGBRCHt8FahA/8xs9KC6dL9eEMDOjZ7Q84qqEaIzZLYtZ6tLqzsTISgDLLmQ3aNBoq oN5alxD/0ADmuqyt/1u10JpZI0P//MLOXlhTuXCIuulk7p/tXcNTbUKXVVPPYgRD+D01 X+cIRjyRbntk5DSGPRy6QnBoIWJqOHJRSOYQ7yYlDMokHXdUw7zEjfs34QtClT1xbJAQ 6bWg== 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=rEnUc164i2YQATkUF5pJh5O66ueEUTaHFCxCD73D8Jg=; b=JVyZ0RAWZfBUcsjhWD52MUxcvCgQFA23y3LD7X9uSQz+/gwMu3sYc+b69ViY/L8lzR MuEE/7l+9OO8BpN2TXfqBuQDlsGw9glu9VcXtkDNY0quyrPoueSjjwlz6PazSRXYDX7S MqvYiQE2d9WBunxDOZFHLc9ELN05L1o3oW9Yhn6Z76IrLntfjmEY8mDt6Bp7PSwdupfI Ha2z2Mjhb/RqQ5WT+ut5dqlW3EYFEaS74qKhyn8OCwwVMSChgl/2b2z73tzVJNe6fO7N WC066l7S8M0JqZMJZqXQFmgZfcxyAe6i2lCTFZl1SU7BG48SiGtbq5Fs2mtScOSnFM8m xU8w== X-Gm-Message-State: APzg51Ak0R8nT1lVjoHZWaHSLpmbgBUMUPAZoYYiZiuu46uep3pEY1o7 LpxkdFV098z+XTfX5SxeMh2s8hCSek12+LNKY53nvQ== X-Received: by 2002:aca:c585:: with SMTP id v127-v6mr3280022oif.348.1535645444133; Thu, 30 Aug 2018 09:10:44 -0700 (PDT) MIME-Version: 1.0 References: <20180830143904.3168-1-yu-cheng.yu@intel.com> <20180830143904.3168-19-yu-cheng.yu@intel.com> In-Reply-To: <20180830143904.3168-19-yu-cheng.yu@intel.com> From: Jann Horn Date: Thu, 30 Aug 2018 18:10:17 +0200 Message-ID: Subject: Re: [RFC PATCH v3 18/24] x86/cet/shstk: User-mode shadow stack support 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: > > This patch adds basic shadow stack enabling/disabling routines. > A task's shadow stack is allocated from memory with VM_SHSTK > flag set and read-only protection. The shadow stack is > allocated to a fixed size of RLIMIT_STACK. > > Signed-off-by: Yu-cheng Yu [...] > +static int set_shstk_ptr(unsigned long addr) > +{ > + u64 r; > + > + if (!cpu_feature_enabled(X86_FEATURE_SHSTK)) > + return -1; > + > + if ((addr >= TASK_SIZE_MAX) || (!IS_ALIGNED(addr, 4))) > + return -1; > + > + rdmsrl(MSR_IA32_U_CET, r); > + wrmsrl(MSR_IA32_PL3_SSP, addr); > + wrmsrl(MSR_IA32_U_CET, r | MSR_IA32_CET_SHSTK_EN); > + return 0; > +} Here's a really stupid question: Where is the logic for switching those MSRs on task switch? MSR_IA32_PL3_SSP contains a userspace pointer, so it has to be switched on task switch, right? I'm sure I'm missing something obvious, but grepping for places that set MSR_IA32_PL3_SSP to nonzero values through the entire patchset, I only see set_shstk_ptr(), which is called from: - cet_setup_shstk() (called from arch_setup_features(), which is called from load_elf_binary()) - cet_restore_signal() (called on signal handler return) - cet_setup_signal() (called from signal handling code)