From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751973AbdJ0PlO (ORCPT ); Fri, 27 Oct 2017 11:41:14 -0400 Received: from foss.arm.com ([217.140.101.70]:33256 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751199AbdJ0PlN (ORCPT ); Fri, 27 Oct 2017 11:41:13 -0400 Date: Fri, 27 Oct 2017 16:41:13 +0100 From: Will Deacon To: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, Catalin Marinas , Kees Cook , Laura Abbott Subject: Re: [RFC PATCH 0/2] arm64: optional paranoid __{get,put}_user checks Message-ID: <20171027154113.GA13737@arm.com> References: <20171026090942.7041-1-mark.rutland@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171026090942.7041-1-mark.rutland@arm.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 26, 2017 at 10:09:40AM +0100, Mark Rutland wrote: > Hi, > > In Prague, Kees mentioned that it would be nice to have a mechanism to > catch bad __{get,put}_user uses, such as the recent CVE-2017-5123 [1,2] > issue with unsafe_put_user() in waitid(). > > These patches allow an optional access_ok() check to be dropped in > arm64's __{get,put}_user() primitives. These will then BUG() if a bad > user pointer is passed (which should only happen in the absence of an > earlier access_ok() check). > > The first patch rewrites the arm64 access_ok() check in C. This gives > the compiler the visibility it needs to elide redundant access_ok() > checks, so in the common case: > > get_user() > access_ok() > __get_user() > BUG_ON(!access_ok()) > > > ... the compiler can determine that the second access_ok() must return > true, and can elide it along with the BUG_ON(), leaving: > > get_user() > access_ok() > __get_user() > > > ... and thus this sanity check can have no cost in the common case. Probably a stupid question, but why not just move the access_ok check into __{get,put}_user and remove it from {get,put}_user? We can also then move the uaccess_{enable,disable}_not_uao calls out from the __ variants so that we can implement user_access_{begin,end}. Will