From: Peter Zijlstra Subject: Re: [PATCH v7 03/14] x86/cet/ibt: Add IBT legacy code bitmap setup function Date: Fri, 7 Jun 2019 19:43:36 +0200 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 Return-path: Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org 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 List-Id: linux-api@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?