Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp2799845ybn; Thu, 26 Sep 2019 18:10:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzHajs4J013Crtn1HDeWnalsFl5IGilTz8TMmC23kXKRTUVScvvR4xyodYb3Q7Iqzu9sBXf X-Received: by 2002:a17:906:1394:: with SMTP id f20mr5972461ejc.274.1569546615108; Thu, 26 Sep 2019 18:10:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569546615; cv=none; d=google.com; s=arc-20160816; b=J5gciknHI7ZtjSjBxNeJex5Tt/rN5r2tPln0webPZb+PzaAMUYCm5aKqiES79Ro6lw U5dc5a/uRLYt/oKfneHKE8LZVLtE7VH0wHqoSnDN1YGJ1gVCiZCvfwGF3NELVHmYoCQ3 nAm0tYYZrXQIlbXVcBN+jFQ1uuvquIXOI2rsF9MRhiR37uqBvg+/N6J9YocRgXAmF1yC r/wwbFWmmCES0pvwhB/SdULntPGIThLemMFybK1txdmFGM9jsRp5QfV5+OBgvWzcSJb4 wOSZVmVS0mzoXJzDa63e5vtJFQ4C4FMI24yI+KatKPoVtvGdXOga2n+SLc8ZBqGo3cC0 fyFA== 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=SOfKuk9HPTSsRvpgfodOLeE1ossXt4acsxL3uqYRaIk=; b=qWwW5iJ0T3hk/RNyFuHe7tIVpJcOboSn/JSlOYWa8MBU7lkr9MH9okxjE1u7Opy/mb 45Xc7uw/insgvAe19/u+SD9ZZc8xn8+GuaRd4oMmOj/kMaaaOhAGy9/x2IJgYzxMubHW 9Vh1o7/uJIzQGFurjUecMuZXpJxDhT3WYiJ16bFMcWCA7H+0KpgQ+STYuKLF7UjpM+GX U7C7rR6fGs6ocR+FlaP2DNjj10UQ0jDX6EU1tOhDt6vn7d3Vb8gBf57VJ0VjNsilVhoj oZFyZGxWOjTKQ6d5Ef/ocEoYR+6E0sRaBEW/P2jpopmuOiiWMN+tsyKlUtfYPkzec7Ir 0JIw== 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 r2si1970026ejj.90.2019.09.26.18.09.50; Thu, 26 Sep 2019 18:10:15 -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 S1726593AbfI0BH5 (ORCPT + 99 others); Thu, 26 Sep 2019 21:07:57 -0400 Received: from mx2.mailbox.org ([80.241.60.215]:62680 "EHLO mx2.mailbox.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725808AbfI0BH5 (ORCPT ); Thu, 26 Sep 2019 21:07:57 -0400 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id 392C0A16F2; Fri, 27 Sep 2019 03:07:54 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter05.heinlein-hosting.de (spamfilter05.heinlein-hosting.de [80.241.56.123]) (amavisd-new, port 10030) with ESMTP id IOcJDIfveQSW; Fri, 27 Sep 2019 03:07:49 +0200 (CEST) Date: Fri, 27 Sep 2019 11:07:36 +1000 From: Aleksa Sarai To: Christian Brauner Cc: Ingo Molnar , Peter Zijlstra , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Christian Brauner , Rasmus Villemoes , Al Viro , Linus Torvalds , libc-alpha@sourceware.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/4] lib: introduce copy_struct_from_user() helper Message-ID: <20190927010736.gy3vvvkjhwlybosj@yavin.dot.cyphar.com> References: <20190925230332.18690-1-cyphar@cyphar.com> <20190925230332.18690-2-cyphar@cyphar.com> <20190925232139.45sbhj34fj7yvxer@wittgenstein> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ningxfpyii3awxw6" Content-Disposition: inline In-Reply-To: <20190925232139.45sbhj34fj7yvxer@wittgenstein> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --ningxfpyii3awxw6 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2019-09-26, Christian Brauner wrote: > On Thu, Sep 26, 2019 at 01:03:29AM +0200, Aleksa Sarai wrote: > > +int is_zeroed_user(const void __user *from, size_t size) > > +{ > > + unsigned long val; > > + uintptr_t align =3D (uintptr_t) from % sizeof(unsigned long); > > + > > + if (unlikely(!size)) > > + return true; >=20 > You're returning "true" and another implicit boolean with (val =3D=3D 0) > down below but -EFAULT in other places. But that function is int > is_zeroed_user() Would probably be good if you either switch to bool > is_zeroed_user() as the name suggests or rename the function and have > it return an int everywhere. I just checked, and in C11 (and presumably in older specs) it is guaranteed that "true" and "false" from have the values 1 and 0 (respectively) [=A77.18]. So this is perfectly well-defined. Personally, I think it's more readable to have: if (unlikely(size =3D=3D 0)) return true; /* ... */ return (val =3D=3D 0); compared to: if (unlikely(size =3D=3D 0)) return 1; /* ... */ return val ? 0 : 1; But I will change the function name (to check_zeroed_user) to make it clearer that it isn't returning a boolean and that you need to check for negative returns. --=20 Aleksa Sarai Senior Software Engineer (Containers) SUSE Linux GmbH --ningxfpyii3awxw6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQSxZm6dtfE8gxLLfYqdlLljIbnQEgUCXY1g0wAKCRCdlLljIbnQ EmniAP96l+2UHf1KZUsjmkF+ni1i3z9S8CcAMfeKjnFvKTEOmAD+Kamb7z8aEEP6 x2hEUZydsZf2ME41Ml2G9Z9uGlezWgM= =zhm8 -----END PGP SIGNATURE----- --ningxfpyii3awxw6--