Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753418AbbLNUF1 (ORCPT ); Mon, 14 Dec 2015 15:05:27 -0500 Received: from mail-io0-f174.google.com ([209.85.223.174]:36221 "EHLO mail-io0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752900AbbLNUF0 (ORCPT ); Mon, 14 Dec 2015 15:05:26 -0500 MIME-Version: 1.0 In-Reply-To: <20151214190632.6A741188@viggo.jf.intel.com> References: <20151214190542.39C4886D@viggo.jf.intel.com> <20151214190632.6A741188@viggo.jf.intel.com> Date: Mon, 14 Dec 2015 12:05:25 -0800 Message-ID: Subject: Re: [PATCH 31/32] x86, pkeys: execute-only support From: Kees Cook To: Dave Hansen Cc: LKML , Linux-MM , "x86@kernel.org" , Linus Torvalds , Andrew Morton , Andy Lutomirski , Dave Hansen Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1454 Lines: 41 On Mon, Dec 14, 2015 at 11:06 AM, Dave Hansen wrote: > > From: Dave Hansen > > Protection keys provide new page-based protection in hardware. > But, they have an interesting attribute: they only affect data > accesses and never affect instruction fetches. That means that > if we set up some memory which is set as "access-disabled" via > protection keys, we can still execute from it. > > This patch uses protection keys to set up mappings to do just that. > If a user calls: > > mmap(..., PROT_EXEC); > or > mprotect(ptr, sz, PROT_EXEC); > > (note PROT_EXEC-only without PROT_READ/WRITE), the kernel will > notice this, and set a special protection key on the memory. It > also sets the appropriate bits in the Protection Keys User Rights > (PKRU) register so that the memory becomes unreadable and > unwritable. > > I haven't found any userspace that does this today. To realistically take advantage of this, it sounds like the linker would need to know to keep bss and data page-aligned away from text, and then set text to PROT_EXEC only? Do you have any example linker scripts for this? -Kees -- Kees Cook Chrome OS & Brillo Security -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/