Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1827056ybn; Thu, 26 Sep 2019 02:50:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXH04zot3c3X55bdAijdIBlFbTAbvAiXXysCjLrKKR4GQfzvWm/Wk5fu19d8PbjUTHWbIs X-Received: by 2002:a50:ccd3:: with SMTP id b19mr2448059edj.257.1569491437856; Thu, 26 Sep 2019 02:50:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569491437; cv=none; d=google.com; s=arc-20160816; b=voIfNJhX3Dei96ETugRfZYMyLzsuDvuAnBm9WY5B/q5BZ9AIh+MMs+pA2yOnw6fbyh Jk9fdrpAja1aLyVYi6Wp4oaqRIhpds2FalZ/29pbwtC1eZCLCxCnQlD1vypEqGxKeuBs R158vWQVe/o25AXD/VrvD0FhPp3muje6ZHghGmqV7up0oP1kN+J1U+p/yygvergeBrSv OyYnSxuv7cW5YNl2koG48wTvkkYDDUb5gnqP+UkQnARIA0a5+Kg6T1vWkfrz+E+Dy13o TELgIZpncdJaLS2/PZF/CSd+aELkyBziztlaj7HW4YQZm2l8hLkNiFzv6C0A4Te1iNmI tY2A== 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; bh=bkbX2fx17xagwqplidp4C6JG0V3E045Hz3wke4mUBDU=; b=yo6ApMsINtPa1gvpEndOV6s13AiL0WCkJj9a53GIQVYYhwJFW2K+5u17Psh4eJHY/C Ue/doZYIOmoHlBy6WFsS3XxUDV+ncPWfl18whSGlK18WqI6M4NG0m4BYTEuOhB3uvRYN fgdX8KigpT+1tPwtx82sNVrMAVLMhyXk7gvSRoZCqERLL2eOmoPMVFpJM3wPjIaANBSe E+CZlr8QrbLSFWBDOA6luafgdJXxPzhiSBG7gGEqk/LoZSEfCkJ25HQYrUL1spLZhqNy grtWJ8R8HraPXRJUEJpz5n8KLUFCei+BgUkiAkCS2ohFoe1NtUwQ9TNeoIH5VDdxAXs7 r1oA== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d15si980318edb.7.2019.09.26.02.50.15; Thu, 26 Sep 2019 02:50:37 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2442965AbfIYRVB (ORCPT + 99 others); Wed, 25 Sep 2019 13:21:01 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:58148 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732997AbfIYRVA (ORCPT ); Wed, 25 Sep 2019 13:21:00 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 07A44A20C4; Wed, 25 Sep 2019 19:20:59 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id XpjdrVYPuLr1; Wed, 25 Sep 2019 19:20:52 +0200 (CEST) Date: Wed, 25 Sep 2019 19:20:49 +0200 From: Aleksa Sarai To: Linus Torvalds Cc: Ingo Molnar , Peter Zijlstra , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Christian Brauner , Rasmus Villemoes , Al Viro , GNU C Library , Linux API , Linux Kernel Mailing List Subject: Re: [PATCH v1 1/4] lib: introduce copy_struct_from_user() helper Message-ID: <20190925172049.skm6ohnnxpofdkzv@yavin> References: <20190925165915.8135-1-cyphar@cyphar.com> <20190925165915.8135-2-cyphar@cyphar.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="d7zsgn6gfbe7cd4l" Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --d7zsgn6gfbe7cd4l Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2019-09-25, Linus Torvalds wrote: > On Wed, Sep 25, 2019 at 10:00 AM Aleksa Sarai wrote: > > > > +int is_zeroed_user(const void __user *from, size_t size) >=20 > I like how you've done this, but it's buggy and only works on 64-bit. >=20 > All the "u64" and "8" cases need to be "unsigned long" and > "sizeof(unsigned long)". >=20 > Part of that requirement is: >=20 > > + unsafe_get_user(val, (u64 __user *) from, err_fault); >=20 > This part works fine - although 64-bit accesses migth be much more > expensive and the win of unrolling might not be sufficient - but: >=20 > > + if (align) { > > + /* @from is unaligned. */ > > + val &=3D ~aligned_byte_mask(align); > > + align =3D 0; > > + } >=20 > This part fundamentally only works on 'unsigned long'. Just to make sure I understand, the following diff would this solve the problem? If so, I'll apply it, and re-send in a few hours. --8<-----------------------------------------------------------------------= --- int is_zeroed_user(const void __user *from, size_t size) { - u64 val; - uintptr_t align =3D (uintptr_t) from % 8; + unsigned long val; + uintptr_t align =3D (uintptr_t) from % sizeof(unsigned long); =20 if (unlikely(!size)) return true; @@ -150,8 +150,8 @@ int is_zeroed_user(const void __user *from, size_t size) if (!user_access_begin(from, size)) return -EFAULT; =20 - while (size >=3D 8) { - unsafe_get_user(val, (u64 __user *) from, err_fault); + while (size >=3D sizeof(unsigned long)) { + unsafe_get_user(val, (unsigned long __user *) from, err_fau= lt); if (align) { /* @from is unaligned. */ val &=3D ~aligned_byte_mask(align); @@ -159,12 +159,12 @@ int is_zeroed_user(const void __user *from, size_t si= ze) } if (val) goto done; - from +=3D 8; - size -=3D 8; + from +=3D sizeof(unsigned long); + size -=3D sizeof(unsigned long); } if (size) { /* (@from + @size) is unaligned. */ - unsafe_get_user(val, (u64 __user *) from, err_fault); + unsafe_get_user(val, (unsigned long __user *) from, err_fau= lt); val &=3D aligned_byte_mask(size); } --=20 Aleksa Sarai Senior Software Engineer (Containers) SUSE Linux GmbH --d7zsgn6gfbe7cd4l Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQSxZm6dtfE8gxLLfYqdlLljIbnQEgUCXYuhzgAKCRCdlLljIbnQ EoTkAP4y5leltK1ihQabd2Qeo0xNwWS4A1sSxNc6gZyek3TIbgD/ZTWvBM6ezLu7 TNEGtnXD7IhbdLW9QNtPAVYBWJhK6AI= =DQmi -----END PGP SIGNATURE----- --d7zsgn6gfbe7cd4l--