Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1457910ybb; Thu, 2 Apr 2020 00:52:04 -0700 (PDT) X-Google-Smtp-Source: APiQypKEMMNVs7v+gWJBrEEb+CaCXo3C12izvdy+nCqPzZGNubtKbi1xRPtO7uKSjYPqsoO62PRt X-Received: by 2002:a9d:6a05:: with SMTP id g5mr1434695otn.116.1585813924836; Thu, 02 Apr 2020 00:52:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585813924; cv=none; d=google.com; s=arc-20160816; b=jjLHE8A2HQjkfwSdAdCNWwM6sAY2ZWGl2k2EW52jwJe3cReYu99Xk700OdOIUHK1SK VoVi3Y0DXjmpsFQL1OmBkjlqv6lDeIyYWcozvnlhWJ3dsl/ATPxUCgvLcjf/iiIrpfkq voDuUmMEQFnANn7dFcxo/2iuuEeEYRXUs/ihP5KPaPA5OXsVWta12CMbzyfFP9xaemw8 lRqkbBWvgRGvUzU88V7bebDIs+sEWt7azZZximhMgEtghNeke+8GjTIljMRz1XxQO/Br Mk6w4qOPmnhf9QDKm06xm3enFGIOHp9ILkpnrtzZ1BwZKAK+Re3Hay/SP4cMTEoJDEe+ 77Gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=owhhf3a9xckUQID1JH+AKO8BSZ4NJugRxsKf3U+q8a4=; b=Lu1TsMnuR9WRBATawUDRNpZp62yZ2OGfVBX5JrfnaiLllzkXtKkVbnE5VKhRLAbUvB ntqfLZjykQVQI1BA8bRYxuNMjnlkcZ0hwOBxk+LMhWylJpuU/reHkjODQJ0w5g1/RNLH OMZX3PNPHJL6eoPUcjcrDU/6k81oda7FqK1fjUkE+X2TiPfZjfaOKEDhr+NLwNHHzs+E /USnufOVQXUhXKWSZIbStU+WFQwuNPingBiORt68zmXXHn2UUyb+o1qk8wGUSM+JywZs VNF/kdTw3GOf/i3mIwtOXXm7YS1/AuMGwcVFCrhV4vtsgAarzYA7KhafJvLAV+uyzdEo +kGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="To/PTKyA"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g129si2161746oob.1.2020.04.02.00.51.51; Thu, 02 Apr 2020 00:52:04 -0700 (PDT) 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; dkim=pass header.i=@chromium.org header.s=google header.b="To/PTKyA"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387599AbgDBHv3 (ORCPT + 99 others); Thu, 2 Apr 2020 03:51:29 -0400 Received: from mail-pj1-f67.google.com ([209.85.216.67]:33209 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387431AbgDBHv3 (ORCPT ); Thu, 2 Apr 2020 03:51:29 -0400 Received: by mail-pj1-f67.google.com with SMTP id jz1so3075653pjb.0 for ; Thu, 02 Apr 2020 00:51:28 -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=owhhf3a9xckUQID1JH+AKO8BSZ4NJugRxsKf3U+q8a4=; b=To/PTKyAFWucW5+IMeI2yi98pK//fDkr9nURGXPB17w0/PjgZQutmOJPXBxJS6aOyb JYGBNOdjcAr9HZAqhAdyZOIdT5Tivgr6CUdMbwXIijjZrQWlDNDrUNWj90OmRbf+aa/R kx8ivj8JL7Zxeosa4D/msz2M4hZMX1zrEuhV8= 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=owhhf3a9xckUQID1JH+AKO8BSZ4NJugRxsKf3U+q8a4=; b=eOjrCKlsaWC6XAJsrimqD2FE6lomH3/sYAeJIvdu+TTKJrGiodRHv+6IrEv9tdoOSY 81WP9f2I1Jk9QcYbzgPffaEA2G7XdCkwKXbOwI/a4CXV368HCRp8Jck2lczvlGyP5cPC BydG/EUgpJ8pa4+1AknEPx1hxPvI1yqA/TMV/nqb7bHkm7SO+b1r8dsVvnnZ5HG6bT/u msuNBe7kPjoengdTeJndH0q90ICvliEw0iqtNzKK4cJRUZrZAQwgcPB/fAOzD8xaGZeY hqcJXJTHulJiaZKGjgoI1KYVFn7awG8oyWplEncx7wz9cHVpfYd2ILK7OSdWosp0rIrH YYxQ== X-Gm-Message-State: AGi0PuYU1Z30pgpQ7j41BoHQSbRG8M/dV4ZY6x4ynEWvgxM2E9C0G8f3 fGmfO4QRaG1Zg1S+5MgN3oiJhw== X-Received: by 2002:a17:90a:228c:: with SMTP id s12mr2380534pjc.68.1585813888074; Thu, 02 Apr 2020 00:51:28 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 71sm3162361pfv.8.2020.04.02.00.51.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2020 00:51:27 -0700 (PDT) Date: Thu, 2 Apr 2020 00:51:26 -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 2/4] uaccess: Selectively open read or write user access Message-ID: <202004020047.401CEBED2@keescook> References: <27106d62fdbd4ffb47796236050e418131cb837f.1585811416.git.christophe.leroy@c-s.fr> <25040ad2d2a2cef45a2442b0e934141987e11b71.1585811416.git.christophe.leroy@c-s.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <25040ad2d2a2cef45a2442b0e934141987e11b71.1585811416.git.christophe.leroy@c-s.fr> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 02, 2020 at 07:34:17AM +0000, Christophe Leroy wrote: > [...] > diff --git a/kernel/compat.c b/kernel/compat.c > index 843dd17e6078..705ca7e418c6 100644 > --- a/kernel/compat.c > +++ b/kernel/compat.c > @@ -199,7 +199,7 @@ long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask, > bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG); > nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size); > > - if (!user_access_begin(umask, bitmap_size / 8)) > + if (!user_write_access_begin(umask, bitmap_size / 8)) This looks mismatched: should be user_read_access_begin()? > return -EFAULT; > > while (nr_compat_longs > 1) { > @@ -211,11 +211,11 @@ long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask, > } > if (nr_compat_longs) > unsafe_get_user(*mask, umask++, Efault); > - user_access_end(); > + user_read_access_end(); > return 0; > > Efault: > - user_access_end(); > + user_read_access_end(); > return -EFAULT; > } (These correctly end read access.) > > @@ -228,7 +228,7 @@ long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask, > bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG); > nr_compat_longs = BITS_TO_COMPAT_LONGS(bitmap_size); > > - if (!user_access_begin(umask, bitmap_size / 8)) > + if (!user_read_access_begin(umask, bitmap_size / 8)) And ..._write_... here? > return -EFAULT; > > while (nr_compat_longs > 1) { > @@ -239,10 +239,10 @@ long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask, > } > if (nr_compat_longs) > unsafe_put_user((compat_ulong_t)*mask, umask++, Efault); > - user_access_end(); > + user_write_access_end(); > return 0; > Efault: > - user_access_end(); > + user_write_access_end(); > return -EFAULT; > } (These correctly end write access.) All the others look correct. With the above fixed: Reviewed-by: Kees Cook -- Kees Cook