From patchwork Tue Feb 16 21:36:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Brown X-Patchwork-Id: 62085 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1915439lbl; Tue, 16 Feb 2016 13:37:10 -0800 (PST) X-Received: by 10.98.89.215 with SMTP id k84mr34259067pfj.66.1455658630414; Tue, 16 Feb 2016 13:37:10 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w18si53578075pfi.224.2016.02.16.13.37.10; Tue, 16 Feb 2016 13:37:10 -0800 (PST) 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; 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; dkim=pass header.i=@linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932789AbcBPVhI (ORCPT + 30 others); Tue, 16 Feb 2016 16:37:08 -0500 Received: from mail-io0-f173.google.com ([209.85.223.173]:34021 "EHLO mail-io0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756115AbcBPVhF (ORCPT ); Tue, 16 Feb 2016 16:37:05 -0500 Received: by mail-io0-f173.google.com with SMTP id 9so662733iom.1 for ; Tue, 16 Feb 2016 13:37:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=KoXaNLV/4pLLmg+wC24DC/rwWyQ/JDwp8dXigSCeWg0=; b=OBTRsA+btgFVAdfGMAwo8U6OKz3mXFtiJpiy88ov8Bu4a6d+jk9mpA9kaCYrOmDI4d fVx2HTg72CsUnEuYPZA5UTHah/4n05KNUUKrY/gzFs+Ufr1WrCTUSfeqcp9DwOKj2kYz 3zPf2q/3HSY8anP1a5v8oQuWR+c3rLWxjuNgk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=KoXaNLV/4pLLmg+wC24DC/rwWyQ/JDwp8dXigSCeWg0=; b=eBSeVstV6MCrFWvG969veYpYr1nkgbgXhPLaKfi33J70aqz/FGbaL8wcfXxpLPPhWN R9tWdiTToA3gpCWmfxWQYOQmUeFvrOR8MlcxeHuEJ1JlsJlu/Ch/c00sd3pVA+4dxxgH qWTPR3BvBnNfl1s2aB/osKO1CBuywEx2vNU406ZhsIyg8wTtu/rLRVHfH9Ll7FL/kqH8 cSl7TeHk0HpCnCdmiAJmgAoZzc4Moq7NZBux+YLpeGa2wXYERpBHHuRXWg+PQZaa52+F x7EneNWaKmdtQ2d3VM+XYlVM84KthvEMP5vOyt8mNq3J1KHDdMMM2VI2pUBvXF+d3RC/ ZQoQ== X-Gm-Message-State: AG10YOSPrM3vZ7xDQKMJqAmFE2zbmkbvvss0Hvj7ZBjnFu6pYJjwFkEb4B1CElVh/Gxn7X/9 X-Received: by 10.182.153.10 with SMTP id vc10mr18665515obb.10.1455658622120; Tue, 16 Feb 2016 13:37:02 -0800 (PST) Received: from davidb.org ([2601:282:500:b612:93d7:b302:84b6:3dff]) by smtp.gmail.com with ESMTPSA id tu11sm18671731oec.13.2016.02.16.13.37.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Feb 2016 13:37:01 -0800 (PST) Date: Tue, 16 Feb 2016 14:36:59 -0700 From: David Brown To: Russell King Cc: linux-arm-kernel@lists.infradead.org, kernel-hardening@lists.openwall.com, Ingo Molnar , Kees Cook , Andy Lutomirski , "H. Peter Anvin" , Michael Ellerman , Mathias Krause , Thomas Gleixner , x86@kernel.org, Arnd Bergmann , PaX Team , Emese Revfy , linux-kernel@vger.kernel.org, linux-arch Subject: [PATCH] ARM: vdso: Mark vDSO code as read-only Message-ID: <20160216213659.GA47194@davidb.org> References: <1453226922-16831-1-git-send-email-keescook@chromium.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1453226922-16831-1-git-send-email-keescook@chromium.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Although the arm vDSO is cleanly separated by code/data with the code being read-only in userspace mappings, the code page is still writable from the kernel. There have been exploits (such as http://itszn.com/blog/?p=21) that take advantage of this on x86 to go from a bad kernel write to full root. Prevent this specific exploit on arm by putting the vDSO code page in post-init read-only memory as well. Before: vdso: 1 text pages at base 80927000 root@Vexpress:/ cat /sys/kernel/debug/kernel_page_tables ---[ Modules ]--- ---[ Kernel Mapping ]--- 0x80000000-0x80100000 1M RW NX SHD 0x80100000-0x80600000 5M ro x SHD 0x80600000-0x80800000 2M ro NX SHD 0x80800000-0xbe000000 984M RW NX SHD After: vdso: 1 text pages at base 8072b000 root@Vexpress:/ cat /sys/kernel/debug/kernel_page_tables ---[ Modules ]--- ---[ Kernel Mapping ]--- 0x80000000-0x80100000 1M RW NX SHD 0x80100000-0x80600000 5M ro x SHD 0x80600000-0x80800000 2M ro NX SHD 0x80800000-0xbe000000 984M RW NX SHD Inspired by https://lkml.org/lkml/2016/1/19/494 based on work by the PaX Team, Brad Spengler, and Kees Cook. Signed-off-by: David Brown --- This patch depends on Kees Cook's series https://lkml.org/lkml/2016/1/19/497 which adds the ro_after_init section. arch/arm/vdso/vdso.S | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) -- 2.7.1 diff --git a/arch/arm/vdso/vdso.S b/arch/arm/vdso/vdso.S index b2b97e3..a62a7b6 100644 --- a/arch/arm/vdso/vdso.S +++ b/arch/arm/vdso/vdso.S @@ -23,9 +23,8 @@ #include #include - __PAGE_ALIGNED_DATA - .globl vdso_start, vdso_end + .section .data..ro_after_init .balign PAGE_SIZE vdso_start: .incbin "arch/arm/vdso/vdso.so"