Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1553875pxy; Thu, 29 Apr 2021 09:20:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyy9jc46WbglUXoN416shn0tfAJ2IWvBGnCtpBKPIzsylzMtwYcS2BhjiE1jp9B/EZKIRk+ X-Received: by 2002:a17:90a:5313:: with SMTP id x19mr7192911pjh.109.1619713228217; Thu, 29 Apr 2021 09:20:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619713228; cv=none; d=google.com; s=arc-20160816; b=hcPYn3umFFKAEAGiH0IUyCNHpoFhsEv2piaZBY3R1RYrenLhEFsOKHuouLhIsRSyWt tZfHgAWU+SsFl6JFFqvKcmEsmyM70hKASTsFc1NRCyk27R7gD78kM28g2u1ClTUgAUGq /PdBYnritmjpIhCztEiv4sLwkCYwiSC+AhV8k3BCLoNTc3afM2Zm6mCiHrbhxx3W4ans 9xP4M78EsE0zLzrSeSkFhzr71xp8QytdzKmEB1AIeb5vWBz9zlKJ98tAMAmlJLAEskuv wENyMIp5ceuTIDCxAYi7UckPDqFfr+ET1l/j0bXdydWE9ldsNv6+o+sbsZACblGZs2dh WmKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:ironport-sdr:ironport-sdr; bh=OuC7GvulaleY7BO86oDzs1soG5ipXXXYwD+ul1fK7Eo=; b=JJi2w1svlQA3Q+MT3wzui58vZfxTXpkIrDNHXNFCbqXcrywomHpZO+JcIGM3UIUikY nnFJKmfJYajm9Ni0Euo2h4hRhI3ofjxrEDW0BAc9Zrf1gAblFHKaJkwPO7HfPqEsqV5B k1Yiaq2qJHLLRaKUc688b3HnW5el8JOPE1DwrBugo7Syg3Q+WGELRLGyC+IF83M+aWbC IzNlZ1tX0rvgKXPLSDBz70/NxaXTcmL31N6jLUIDExw8qvKiOAqZUMKPuHaHxWfi9o7K 1Nhd0fIkgtTJmYQq9msY+6Gll3XWRMFZe432UN5VlO9o8G91q86Z9CQ5DHb31qrbxYGC JI0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s2si374621pgo.250.2021.04.29.09.20.13; Thu, 29 Apr 2021 09:20:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240796AbhD2QR5 (ORCPT + 99 others); Thu, 29 Apr 2021 12:17:57 -0400 Received: from mga07.intel.com ([134.134.136.100]:12153 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233480AbhD2QR5 (ORCPT ); Thu, 29 Apr 2021 12:17:57 -0400 IronPort-SDR: u6RT5mR3NcX5bHVZOUpa+4AKjiaNPjx0dQF7RQ3RCA5o78NA04SE/8GxkXX2aKlplglR4vx5Wz zFOWWKdPUXgQ== X-IronPort-AV: E=McAfee;i="6200,9189,9969"; a="260990856" X-IronPort-AV: E=Sophos;i="5.82,259,1613462400"; d="scan'208";a="260990856" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2021 09:17:08 -0700 IronPort-SDR: qpscS/NTPaNExpS/xy+h77DjUAj0MfSqWUBQ9aWY26+7MNzDWCTgXqKlTL6m4WaoZlZ1zH9tjB 1WJjeFNQOWHQ== X-IronPort-AV: E=Sophos;i="5.82,259,1613462400"; d="scan'208";a="458834640" Received: from yyu32-mobl1.amr.corp.intel.com (HELO [10.212.75.159]) ([10.212.75.159]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2021 09:17:07 -0700 Subject: Re: [PATCH v26 22/30] x86/cet/shstk: Add user-mode shadow stack support To: Borislav Petkov Cc: 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 , Andy Lutomirski , Balbir Singh , 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 , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang , Pengfei Xu , Haitao Huang References: <20210427204315.24153-1-yu-cheng.yu@intel.com> <20210427204315.24153-23-yu-cheng.yu@intel.com> <3a0ed2e3-b13d-0db6-87af-fecd394ddd2e@intel.com> From: "Yu, Yu-cheng" Message-ID: Date: Thu, 29 Apr 2021 09:17:06 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/29/2021 2:12 AM, Borislav Petkov wrote: > On Wed, Apr 28, 2021 at 11:39:00AM -0700, Yu, Yu-cheng wrote: >> Sorry about that. After that email thread, we went ahead to separate shadow >> stack and ibt into different files. I thought about the struct, the file >> names cet.h, etc. The struct still needs to include ibt status, and if it >> is shstk_desc, the name is not entirely true. One possible approach is, we >> don't make it a struct here, and put every item directly in thread_struct. >> However, the benefit of putting all in a struct is understandable (you might >> argue the opposite :-)). Please make the call, and I will do the change. > > /me looks forward into the patchset... > > So this looks like the final version of it: > > @@ -15,6 +15,7 @@ struct cet_status { > unsigned long shstk_base; > unsigned long shstk_size; > unsigned int locked:1; > + unsigned int ibt_enabled:1; > }; > > If so, that thing should be simply: > > struct cet { > unsigned long shstk_base; > unsigned long shstk_size; > unsigned int shstk_lock : 1, > ibt : 1; > } > > Is that ibt flag per thread or why is it here? I guess I'll find out. > > /me greps... > > ah yes, it is. > The lock applies to both shadow stack and ibt. So maybe just "locked"? >> Yes, the comments are in patch #23: Handle thread shadow stack. I wanted to >> add that in the patch that takes the path. > > That comes next, I'll look there. > >>> vm_munmap() can return other negative error values, where are you >>> handling those? >>> >> >> For other error values, the loop stops. > > And then what happens? > >>>> + cet->shstk_base = 0; >>>> + cet->shstk_size = 0; > > You clear those here without even checking whether unmap failed somehow. > And then stuff leaks but we don't care, right? > > Someone else's problem, I'm sure. > vm_munmap() returns error as the following: (1) -EINVAL: address/size/alignment is wrong. For shadow stack, the kernel keeps track of it, this cannot/should not happen. Should it happen, it is a bug. The kernel can probably do WARN(). (2) -ENOMEM: when doing __split_vma()/__vma_adjust(), kmem_cache_alloc() fails. Not much we can do. Perhaps WARN()? (3) -EINTR: mmap_write_lock_killable(mm) fails. This should only happen to a pthread. When a thread is existing, its siblings are holding mm->mmap_lock. This is handled here. Right now, in the kernel, only the munmap() syscall returns __vm_munmap() error code, otherwise the error is not checked. Within the kernel and if -EINTR is not expected, this makes sense as explained above. Thanks for questioning. This piece needs to be correct. Yu-cheng