Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1437420rwb; Wed, 16 Nov 2022 18:08:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf70+yAgl1HYFuOEHL4E1gXcaF1vXJQBcaziVtEROcfQcjIB6Jmv//cOwVCHtt0NlO35GppF X-Received: by 2002:a05:6402:149:b0:458:cc1b:a273 with SMTP id s9-20020a056402014900b00458cc1ba273mr395792edu.92.1668650935351; Wed, 16 Nov 2022 18:08:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668650935; cv=none; d=google.com; s=arc-20160816; b=gvyglF0VA6H7Z2zEBl1k+1XufYHNSPYjKmnm14NjG8/v/Rm6NwRAuE9uIeKsYZVSjy o786cGIfYh+FQBfHTJuC4Nx0VFbxXy4+cH/jJRLmwGwqXZzbiCFMdxDTvUMdAeQmYyG/ VjnEzpPJvFS0oOSq8k8UdMMGju9VLZFCoKh/kikBBMjS0xQU+z4+/ojKu8npoXX6nZb3 wLyOXPNDoU/ZKcJDx9lQzMb3tPPtMJW0pCc1ygTWzoQDPxOd2rvpRuRZ0Kox3FVx84tY 29Wa7r/Yc/XlFbQlDjuB0kn+qDR/Agey8CFxj3+TDF/eMcXt3bk/NZVK7Pofpb8PUBff p8aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=dEJat997gDB284IQJDfbqi4/5IXvytYbwgZCPi3gI8M=; b=v61i7l9z5ReLvqyH1tlwyIg0o7fxMlNeJmj70uhHv2BlOAGRgpWHOHe80QoaKvHt3s 66JunJtYGZOdge5T1wmkChpkxfc1OhGXZ0gW+yPn9ZqhxCidQSRoqOU92H5HfW9hWq1i lOc5IPfaT5KQxiZmBCsLU0edMLSR0wYEIWqHq18BfA2yykduRYRlL2OM0gNYGip6n87L LToD/3buFzqJ7ikKIsj0R+KXe+lbzxxQXCac45TO1m7GAmz01RiV5/2iu6vHK8txSLpE O71lKiyjszeZOE/NICqRLgZcieKeU28KnYOZhTsU6D/5jJL3DcZJ3FicwJ2lDEXZyY5i +yLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=oBVYY4GH; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne39-20020a1709077ba700b007adf9d2fa0fsi16284766ejc.947.2022.11.16.18.08.24; Wed, 16 Nov 2022 18:08:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=oBVYY4GH; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234600AbiKQCFc (ORCPT + 99 others); Wed, 16 Nov 2022 21:05:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232097AbiKQCF3 (ORCPT ); Wed, 16 Nov 2022 21:05:29 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D40E60686; Wed, 16 Nov 2022 18:05:28 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D2AD2B81F87; Thu, 17 Nov 2022 02:05:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B916CC433D6; Thu, 17 Nov 2022 02:05:21 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="oBVYY4GH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1668650720; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dEJat997gDB284IQJDfbqi4/5IXvytYbwgZCPi3gI8M=; b=oBVYY4GH+szvpy7v+MDpWl7rIbq1Ag0+XjaiW9ivB+W/ypTPzWGRKmZ5grHtl0NRu+tdAw OceXtZlFIdzaNyPTBIDx5ZFzB/5YparpWLHfLRzfitegfl7G9s7sam3TuLTYL+fICnJhuN DFCVAmQjhuCf5Jl3bBUK1aEXDFPWY+A= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id ca8ad650 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 17 Nov 2022 02:05:19 +0000 (UTC) Date: Thu, 17 Nov 2022 03:05:14 +0100 From: "Jason A. Donenfeld" To: Kees Cook Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, Greg Kroah-Hartman , Jakub Kicinski , Russell King , Catalin Marinas , Thomas Bogendoerfer , Heiko Carstens , Herbert Xu , Christoph =?utf-8?Q?B=C3=B6hmwalder?= , Jani Nikula , Jason Gunthorpe , Sakari Ailus , "Martin K . Petersen" , Theodore Ts'o , Andreas Dilger , Jaegeuk Kim , Richard Weinberger , "Darrick J . Wong" , SeongJae Park , Thomas Gleixner , Andrew Morton , Michael Ellerman , Helge Deller , netdev@vger.kernel.org, linux-crypto@vger.kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-mmc@vger.kernel.org, linux-parisc@vger.kernel.org, ydroneaud@opteya.com Subject: Re: [PATCH v2 3/3] treewide: use get_random_u32_between() when possible Message-ID: References: <20221114164558.1180362-1-Jason@zx2c4.com> <20221114164558.1180362-4-Jason@zx2c4.com> <202211161436.A45AD719A@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Thu, Nov 17, 2022 at 12:55:47AM +0100, Jason A. Donenfeld wrote: > 1) How/whether to make f(0, UR2_MAX) safe, > - without additional 64-bit arithmetic, > - minimizing the number of branches. > I have a few ideas I'll code golf for a bit. > I think I can make progress with (1) alone by fiddling around with > godbolt enough, like usual. The code gen is definitely worse. Original half-open interval: return floor + get_random_u32_below(ceil - floor); Suggested fully closed interval: ceil = ceil - floor + 1; return likely(ceil) ? floor + get_random_u32_below(ceil) : get_random_u32(); Is the worse code gen actually worth it? Options: a) Decide worse codegen is worth it. b) Declare f(0, U32_MAX) undefined and just not handle it. c) Stick with original half-open interval that doesn't have this problem. Jason