Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1259171rwb; Wed, 16 Nov 2022 14:46:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf7NNSprz0Bkcj3RI2MOtPzE4GKyrtrBUhYRhw7jxR1T/NGn4mE/qZku7zAcvkukV3uhCyGL X-Received: by 2002:a17:907:d504:b0:7ad:b6d6:9188 with SMTP id wb4-20020a170907d50400b007adb6d69188mr18463389ejc.418.1668638768646; Wed, 16 Nov 2022 14:46:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668638768; cv=none; d=google.com; s=arc-20160816; b=cfz8lF+Wa0VoGdXOT3ghLM8YQVz2cfrmuBYbEjDIUwngnkKux9QwXnDbixYSnhUXfF aDQ3cBDiht9G0qK4G0+aix6/E1BWzfEWNIoo/Tfa1FmSK7SvQMja2pOoUl6K1Zer5wCB MU3/YN5uzWtdSJMLmH+ArotouKcC4TD5v1QylzU9g4uE9ll2iUZVLX4nJWHy+KwsDqj5 D42p8VvBTLd0himCgJjFLLOK4dMMwRjHPYxtBg1vXE6X0RHlTV5fyKlw6tmkRznAkFOS xd+A01pJejcVUoXhnTynLQHuvzb1l9zLNUeus4moFFUTP5Hiv8PQdyX+mZIrDIbJaHL/ FqpQ== 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=Wf2gFJO0eZI55pjXm8OYjMYkGLte7QuRao7+IuvSaqE=; b=c5yRxL33RbVtcJ7m8TJcKhLNQZUtITW9kBw5VKtOWBWhbFLyqCazyk8WqjaoIDz3Mi pxNcgARZQ33cwLUFMN7wtuCfKicGA1ZUAYoGtp1MEAN1jA9f7xNgk/SR+ToI+HqOYH6x /BTTgIbrjW8cfE4SbGiv+yPHlKcy3jp7KZpy2J3w4qZk6Ne2KcpshLycnMy1FG8qKJ7A LSoxjhFk3Q6IpzsR24+LgkSXbpuJwUcz+d9p0eFkD1suGxcwW8Pk7QxzdNrrtuARMCUz 3mAKhaPK5XYbo8PhucAiMm4Gj6OVZ2e0zWo3IiMn6Ge5HmiuiDqxkxkUlmx4pWFqhsFT fBhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=D2amVl9V; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg9-20020a170907970900b0078dcf11ccf7si13948315ejc.802.2022.11.16.14.45.37; Wed, 16 Nov 2022 14:46:08 -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=@chromium.org header.s=google header.b=D2amVl9V; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234393AbiKPWnj (ORCPT + 99 others); Wed, 16 Nov 2022 17:43:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234460AbiKPWn2 (ORCPT ); Wed, 16 Nov 2022 17:43:28 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 198556BDD6 for ; Wed, 16 Nov 2022 14:43:15 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id b11so14374pjp.2 for ; Wed, 16 Nov 2022 14:43:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Wf2gFJO0eZI55pjXm8OYjMYkGLte7QuRao7+IuvSaqE=; b=D2amVl9V9KQfzLW2zaIS23IBouuPji7hB+OAx+ZhW9BBCDB5OKBikMdNxb0VPTDxJj csClJ0YRCWBC/mBx5CM8cmRfxBeg4UGIi36VQSyP9C8PzSygpHTtXYMcx806fNdiiKsi DAssScFkYAwJ1pFNUcIn3ZWqN1hBHz6LpWnys= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Wf2gFJO0eZI55pjXm8OYjMYkGLte7QuRao7+IuvSaqE=; b=7vGzCZS7c2EMPWx8NprOLgvlfg9hAfpx2GlOlAcJ3op+TFrKYmOxFfTs2DQQ9Go7S5 Yv2VARKHEw5heRti3s3VKyXpY094/eL33/xjpcg9YU57d11lYqhhSqw9UaxawbLe9pq6 oq1NSCL2MlYLvXiIIA2cWxXSdJ9Pb17+q3n+xNHxLzZq04yryWN/6rcf4l+s/OGoYGFC L3qGKM591TxRsmpgAGcoJhmYRDMKwPlwM8vwQL3OnU8BlWGx5iiM3/wJKFRrDI1xhce4 9ZSCK5ZscxdS/ZnSt5AIFNxbclPLIHPP6r9qHG0fktZTboaXs6wrl29QDJl5Bts5FyMX oPEw== X-Gm-Message-State: ANoB5pl65hSx8g/4P2vi8LMWYU750QUodPXcurbxFaj28QYHWBsrQF3/ hrVw9KFG38ubP5bv1tuf9fKPIg== X-Received: by 2002:a17:90b:3c42:b0:213:1ce7:d962 with SMTP id pm2-20020a17090b3c4200b002131ce7d962mr6007688pjb.63.1668638594628; Wed, 16 Nov 2022 14:43:14 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id a9-20020a170902710900b00183c6784704sm12680746pll.291.2022.11.16.14.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Nov 2022 14:43:14 -0800 (PST) Date: Wed, 16 Nov 2022 14:43:13 -0800 From: Kees Cook To: "Jason A. Donenfeld" 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 =?iso-8859-1?Q?B=F6hmwalder?= , 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 Subject: Re: [PATCH v2 3/3] treewide: use get_random_u32_between() when possible Message-ID: <202211161436.A45AD719A@keescook> References: <20221114164558.1180362-1-Jason@zx2c4.com> <20221114164558.1180362-4-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221114164558.1180362-4-Jason@zx2c4.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 Mon, Nov 14, 2022 at 05:45:58PM +0100, Jason A. Donenfeld wrote: > - (get_random_u32_below(1024) + 1) * PAGE_SIZE; > + get_random_u32_between(1, 1024 + 1) * PAGE_SIZE; I really don't like "between". Can't this be named "inclusive" (and avoid adding 1 everywhere, which seems ugly), or at least named something less ambiguous? > - n = get_random_u32_below(100) + 1; > + n = get_random_u32_between(1, 101); Because I find this much less readable. "Below 100" is clear: 0-99 inclusive, plus 1, so 1-100 inclusive. "Between 1 and 101" is not obvious to me to mean: 1-100 inclusive. These seem so much nicer: get_random_u32_inclusive(1, 1024) get_random_u32_inclusive(1, 100) -- Kees Cook