From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4BD39C43331 for ; Thu, 2 Apr 2020 07:55:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 02948206F6 for ; Thu, 2 Apr 2020 07:55:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="NEr/HOuF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 02948206F6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 93BA18E0009; Thu, 2 Apr 2020 03:55:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C4788E0007; Thu, 2 Apr 2020 03:55:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7645A8E0009; Thu, 2 Apr 2020 03:55:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0004.hostedemail.com [216.40.44.4]) by kanga.kvack.org (Postfix) with ESMTP id 5B76A8E0007 for ; Thu, 2 Apr 2020 03:55:36 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1DF81181AC9CC for ; Thu, 2 Apr 2020 07:55:36 +0000 (UTC) X-FDA: 76662155472.29.hook35_13c4c82b31c21 X-HE-Tag: hook35_13c4c82b31c21 X-Filterd-Recvd-Size: 6377 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Thu, 2 Apr 2020 07:55:35 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id l14so1497158pgb.1 for ; Thu, 02 Apr 2020 00:55:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=cNKPt9zws6tETOtG4clSFgvYQggRaWY4PbOPgRy3R/Q=; b=NEr/HOuFOs50bDB/L0pQZVsoQ+Nyg7UDyLD4S8+MDPajx7NSq21pauFLuu8fuuS5HT dA7TbZA2aW9xfHzx8uCcccW9e7W+yaqO5sU6kFMZUqI2AY+iLus6FD4e+eesLB4+PTnk oebi07I1vQWsVfSymxAqSpu68Tvq2bSlWm8+E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=cNKPt9zws6tETOtG4clSFgvYQggRaWY4PbOPgRy3R/Q=; b=g1IpYTKyghXlEAsV0x9rWno6riQidY8n9dMc5LrEG8eLfE5UhJ6dVWkVMX2Xa7rY8V kI4PCBFv2b/tZnUEMES6YMsrIIfhLG+4bPZAVlDfdJQz9NVXoMYoxg122B3oJTTCVLuH sdKeABj9/U33WAinLM1J6hDPh+c+5LwOyt9iOHEMdt8S7JwpCPrDUUBt1gSGqsTKjumo 0BsbahBpoJ2dIdGI1py7li13KQ6VcpjP2z1xtCL3SlzK2r7daMtS3AXKB3K4e74ZJTrd 5cRdKRCEylFH7e1utgOgMisTJhsfPHaf4krtXNDGusekzlUydYza7RIlZJS5KXJNq6hv ByGQ== X-Gm-Message-State: AGi0PubZ56jmX5flBkPE+MW3Q09OyJ3/ftqwQz7bQ7n//xoApVzAjYnw zV8jE55Mr0DSXwTgyi5DK9NKXw== X-Google-Smtp-Source: APiQypLB2ZurOAtjAAZY1rw1Oc9/IReJTqNfIyojiVL6ct3p3zeLZXi1W1njrDdywOR0TVbU9jwgMA== X-Received: by 2002:a62:1c4c:: with SMTP id c73mr1880326pfc.64.1585814134808; Thu, 02 Apr 2020 00:55:34 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id u21sm3185973pjy.8.2020.04.02.00.55.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2020 00:55:34 -0700 (PDT) Date: Thu, 2 Apr 2020 00:46:56 -0700 From: Kees Cook To: Christophe Leroy Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , airlied@linux.ie, daniel@ffwll.ch, torvalds@linux-foundation.org, viro@zeniv.linux.org.uk, akpm@linux-foundation.org, hpa@zytor.com, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, linux-arch@vger.kernel.org Subject: Re: [PATCH RESEND 1/4] uaccess: Add user_read_access_begin/end and user_write_access_begin/end Message-ID: <202004020046.96A2D21F@keescook> References: <27106d62fdbd4ffb47796236050e418131cb837f.1585811416.git.christophe.leroy@c-s.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <27106d62fdbd4ffb47796236050e418131cb837f.1585811416.git.christophe.leroy@c-s.fr> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Apr 02, 2020 at 07:34:16AM +0000, Christophe Leroy wrote: > Some architectures like powerpc64 have the capability to separate > read access and write access protection. > For get_user() and copy_from_user(), powerpc64 only open read access. > For put_user() and copy_to_user(), powerpc64 only open write access. > But when using unsafe_get_user() or unsafe_put_user(), > user_access_begin open both read and write. > > Other architectures like powerpc book3s 32 bits only allow write > access protection. And on this architecture protection is an heavy > operation as it requires locking/unlocking per segment of 256Mbytes. > On those architecture it is therefore desirable to do the unlocking > only for write access. (Note that book3s/32 ranges from very old > powermac from the 90's with powerpc 601 processor, till modern > ADSL boxes with PowerQuicc II modern processors for instance so it > is still worth considering) > > In order to avoid any risk based of hacking some variable parameters > passed to user_access_begin/end that would allow hacking and > leaving user access open or opening too much, it is preferable to > use dedicated static functions that can't be overridden. > > Add a user_read_access_begin and user_read_access_end to only open > read access. > > Add a user_write_access_begin and user_write_access_end to only open > write access. > > By default, when undefined, those new access helpers default on the > existing user_access_begin and user_access_end. > > Signed-off-by: Christophe Leroy Reviewed-by: Kees Cook -Kees > Link: https://patchwork.ozlabs.org/patch/1227926/ > --- > Resending this series as I mistakenly only sent it to powerpc list > begining of February (https://patchwork.ozlabs.org/patch/1233172/) > > This series is based on the discussion we had in January, see > https://patchwork.ozlabs.org/patch/1227926/ . I tried to > take into account all remarks, especially @hpa 's remark to use > a fixed API on not base the relocking on a magic id returned at > unlocking. > > This series is awaited for implementing selective lkdtm test to > test powerpc64 independant read and write protection, see > https://patchwork.ozlabs.org/patch/1231765/ > > include/linux/uaccess.h | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h > index 67f016010aad..9861c89f93be 100644 > --- a/include/linux/uaccess.h > +++ b/include/linux/uaccess.h > @@ -378,6 +378,14 @@ extern long strnlen_unsafe_user(const void __user *unsafe_addr, long count); > static inline unsigned long user_access_save(void) { return 0UL; } > static inline void user_access_restore(unsigned long flags) { } > #endif > +#ifndef user_write_access_begin > +#define user_write_access_begin user_access_begin > +#define user_write_access_end user_access_end > +#endif > +#ifndef user_read_access_begin > +#define user_read_access_begin user_access_begin > +#define user_read_access_end user_access_end > +#endif > > #ifdef CONFIG_HARDENED_USERCOPY > void usercopy_warn(const char *name, const char *detail, bool to_user, > -- > 2.25.0 > -- Kees Cook