Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp522063ybi; Fri, 7 Jun 2019 11:58:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqzDuHBjZ5bPOZa2j1WzdCaDQKrJO7Rr+vI8Ruihpc9XhO62Y6XMV/WrpZuCGRuOGsoYDuiD X-Received: by 2002:a17:902:b611:: with SMTP id b17mr4120472pls.261.1559933931199; Fri, 07 Jun 2019 11:58:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559933931; cv=none; d=google.com; s=arc-20160816; b=LfIY2C7LrR/gA2d+G0Akds1zyTiplbW9Log9L/zw7P5EE7F02+Ddq6tLGNhXWtnku9 dnzOD83FI+2qdqWx/G2RZqUWuKVD+cHe/U1mtLaMUNGFedeg6ETugA2PiXqwvL1kkf0a xIft08XQ/JJzaGdoXQhY9Q+eHi8kuP+5+iFX1+rAt2UgAcrVmEV/PMUG7nHphxoEpvF3 Ae+ilCtHM02OAYf1BfW6kiySnq97qryug77Tcc4QmOPKMks2KHHZCjKeQBRXPOWNjjJj yiPKYIdcMv8d0c8MaMGWwxezmULX09W4v/d3R+PMY5NXJ9UW6iLbQTKvf9N/qGHa+Mw2 iC9Q== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Ib5xcjylzZJYs4tQEX10bx6Iy6PiZBk7Yfn6HEJa6+k=; b=z7JZF+c9aNDuKyruum3ZsCzoUxwVSOu1v7IUq7fz22cRXHauBvaQ3CtfFsFGDGNXfI JYTSHZHByLwU2DHiKNagV7mwbvWWiQ9cwm0WcYuKTmgYXs6cICFTtQmWN4QZSWTAaWOQ wB8pIuvKIgIXWx9Lz962SdJDLhPK8ZKFndM2moTA3vNneFveS8RV/LXoBCiBzkCi4gwW Gx7LNRrbftoM+l18TSaqd/OZJvRLezuD5OFEv5RqQ0odTcyUb+TEdS2xHsHI32vRGruR p/I0qOzhoDL5A78dn5lpU0nv9pNrxCjAHr5BpXue8qyk2I7l4oY4wCkCynb9sjFnhyDm fYdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=uUV0Qg4R; 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 12si2726033pfh.109.2019.06.07.11.58.35; Fri, 07 Jun 2019 11:58:51 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=uUV0Qg4R; 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 S1731668AbfFGRnz (ORCPT + 99 others); Fri, 7 Jun 2019 13:43:55 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:50774 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728684AbfFGRny (ORCPT ); Fri, 7 Jun 2019 13:43:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Ib5xcjylzZJYs4tQEX10bx6Iy6PiZBk7Yfn6HEJa6+k=; b=uUV0Qg4RLvuFztCksJatP1vun caXXdhBCXJ1/Zff5BaFrpqzvOtmY792iqKlflcEH7L4Ds+nzOZdE00i9/+A2QdpjUZaw8FTm5C0Di 6a0ESgkewptbth56+PriX5BaJhJVXnuImAz3+GhDF6apj0C5KkbXzhVOPvgP9z/JpZvioXldA2ZyH zuy1FnNgL5zmKuiuFAWNNtxXbReWZY/rsPt+VJwglRFELnGzRDXjgtIXTDTsSXd0TqgtRtMjweOwZ c+Gb5zmZMbrHo49WAIM2sc6JhZRZ7FubJesd/SG9HdwisS9G3VLMjnBNop6B3+O0rZ9//FQS4z8+R sYPvGd5CA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1hZItt-0006lL-Ul; Fri, 07 Jun 2019 17:43:38 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 6C02B20216A2F; Fri, 7 Jun 2019 19:43:36 +0200 (CEST) Date: Fri, 7 Jun 2019 19:43:36 +0200 From: Peter Zijlstra To: Yu-cheng Yu 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 , 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 Subject: Re: [PATCH v7 03/14] x86/cet/ibt: Add IBT legacy code bitmap setup function Message-ID: <20190607174336.GM3436@hirez.programming.kicks-ass.net> References: <20190606200926.4029-1-yu-cheng.yu@intel.com> <20190606200926.4029-4-yu-cheng.yu@intel.com> <20190607080832.GT3419@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 07, 2019 at 09:23:43AM -0700, Yu-cheng Yu wrote: > On Fri, 2019-06-07 at 10:08 +0200, Peter Zijlstra wrote: > > On Thu, Jun 06, 2019 at 01:09:15PM -0700, Yu-cheng Yu wrote: > > > Indirect Branch Tracking (IBT) provides an optional legacy code bitmap > > > that allows execution of legacy, non-IBT compatible library by an > > > IBT-enabled application. When set, each bit in the bitmap indicates > > > one page of legacy code. > > > > > > The bitmap is allocated and setup from the application. > > > +int cet_setup_ibt_bitmap(unsigned long bitmap, unsigned long size) > > > +{ > > > + u64 r; > > > + > > > + if (!current->thread.cet.ibt_enabled) > > > + return -EINVAL; > > > + > > > + if (!PAGE_ALIGNED(bitmap) || (size > TASK_SIZE_MAX)) > > > + return -EINVAL; > > > + > > > + current->thread.cet.ibt_bitmap_addr = bitmap; > > > + current->thread.cet.ibt_bitmap_size = size; > > > + > > > + /* > > > + * Turn on IBT legacy bitmap. > > > + */ > > > + modify_fpu_regs_begin(); > > > + rdmsrl(MSR_IA32_U_CET, r); > > > + r |= (MSR_IA32_CET_LEG_IW_EN | bitmap); > > > + wrmsrl(MSR_IA32_U_CET, r); > > > + modify_fpu_regs_end(); > > > + > > > + return 0; > > > +} > > > > So you just program a random user supplied address into the hardware. > > What happens if there's not actually anything at that address or the > > user munmap()s the data after doing this? > > This function checks the bitmap's alignment and size, and anything else is the > app's responsibility. What else do you think the kernel should check? I've no idea what the kernel should do; since you failed to answer the question what happens when you point this to garbage. Does it then fault or what?