Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2646304rwb; Thu, 17 Nov 2022 14:00:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf4MXRHwBvIV/8N7NrjiToDo+5eAROOmvPyl/OE1PJujdKRpCrUaj5MMqt6Aa/JvnQvCQVk+ X-Received: by 2002:a17:90b:1958:b0:213:880:e931 with SMTP id nk24-20020a17090b195800b002130880e931mr4566342pjb.217.1668722423790; Thu, 17 Nov 2022 14:00:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668722423; cv=none; d=google.com; s=arc-20160816; b=EWDJglvX7HZj2iEYAkiKpXhFTGg2JkHlOyLj/YCsBuvgoYfCHBEUdlbJokuPpfy5La I9xXLUonHxvLDe8dnryFx1+RfacH7pZ9z94CD/eFiGDaLoZdlZ93aMPk0TUdl93pMH6h OdoIP9GxFzhIpaWUMTz7Ea4ax2KhOycR+p4Z+fKo845ixwQ7jvgMWgwefTZd983fULVl AmjTKsjkg9zbHrlEUcWdUPU/qaRqc8rN9zui0MN8Qyrr3bfmjtJnkfRbeHcT9AuSFVH1 mAN+zePtYuxLA3Fbb4VZhNbrQQ+aXzwBwfNls8ufabb+OskBXqHfpQANWoOuhNmcD5qu vHqA== 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=r2vqsefxvlQpm7YoDJQXEXeeHIkQ6S5JMCMQ5S8aLio=; b=JAnFdowlnOOBygBayFoJ3EcBGnnPmki5PMf52xlh/3CtHHieuQc2q17mdPfdxbsmIm f0m2/oC2BA3sSfuuOC+wJfV9n0JSIpwAG9r75HamR//MKHn6JZiUmPSocuwN0SYp9PhR 21zpogayuPe5umdN5lKE7BRHVJjJrOJ6i8+WTig/gEQBty7x+hKgObi6lkseejK4pnoZ ymrpR5XuuQvM04l7nAkN7nvT2+gXBOk7zQjVAv9FEzttu7HYeicwiHlY45Y2QAVwdD1N HrM1dj4gxSR99m84kFP87VR88RLDz0kaAra9/w7rwUcrzpdcSZXlynYkhSiqkKX4r11t 0LHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=k2i7Pob2; 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 e5-20020a170902784500b0017857e4e6easi1835201pln.343.2022.11.17.14.00.09; Thu, 17 Nov 2022 14:00:23 -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=k2i7Pob2; 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 S241147AbiKQWAF (ORCPT + 99 others); Thu, 17 Nov 2022 17:00:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241074AbiKQV7u (ORCPT ); Thu, 17 Nov 2022 16:59:50 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE5671156 for ; Thu, 17 Nov 2022 13:58:27 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id g62so3064955pfb.10 for ; Thu, 17 Nov 2022 13:58:26 -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=r2vqsefxvlQpm7YoDJQXEXeeHIkQ6S5JMCMQ5S8aLio=; b=k2i7Pob22XCdE3eYvjx4pPufwTb8mTPjukR1UCSAv0kmL6U29qZrcajtJc3GiwR25C GxngyGxuAOe8R1u2fG07FDvUurbqbhzNNAvQ0bvvdjotWAgaJxTe1J6rbJlEzDLOD/Zm f5ROj4ZQvL1a3wZkcDpdW1XiI4mqzUly58q/U= 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=r2vqsefxvlQpm7YoDJQXEXeeHIkQ6S5JMCMQ5S8aLio=; b=r3RcSZ3ULI8jh6MgNn+2FAZ40Vf5xAzmD7YmgpdYtae8wGSkAKcWmKgLGJgoVRSqFP dvVbNiX2LDgiU0OfSwEx2+mZBbeaGQqrVvkYzfVZJvsFfjMdJlI38KFu+7UEXZ3QPvFr 8JxIi+sjAAzySA7OZGfD+rYteY/ISV6V6/y4GNGqvJINx//s8GWUX8CA1AF12t3mwO8Q Hf4wuNycaOsohbd03LBnJBLAwKliR9x8aSBYVTrCflDSu+vytesmRkh5nUj04x+Ekx83 hP4nnQMGwP5Q6mZPcKGxmjlhm4r0C0NreMIegNkL7SnXHguPHmsVjZBlIOf2T7ZcWMB2 QJ1A== X-Gm-Message-State: ANoB5pk55WQLv5rfP0e6TDSEK4Cck3SACVSJkC697uUb6xOv/SJuBzML j17+mfLzw0eKAjeZ+fW5hnKhSw== X-Received: by 2002:a63:5c0f:0:b0:470:8e8a:8e11 with SMTP id q15-20020a635c0f000000b004708e8a8e11mr3843188pgb.490.1668722306503; Thu, 17 Nov 2022 13:58:26 -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 k3-20020a17090a3cc300b00200461cfa99sm3966446pjd.11.2022.11.17.13.58.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 13:58:25 -0800 (PST) Date: Thu, 17 Nov 2022 13:58:25 -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 v3 2/3] treewide: use get_random_u32_{above,below}() instead of manual loop Message-ID: <202211171358.4B4E0E2F17@keescook> References: <20221114164558.1180362-1-Jason@zx2c4.com> <20221117202906.2312482-1-Jason@zx2c4.com> <20221117202906.2312482-3-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221117202906.2312482-3-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 Thu, Nov 17, 2022 at 09:29:05PM +0100, Jason A. Donenfeld wrote: > These cases were done with this Coccinelle: > > @@ > expression E; > identifier I; > @@ > - do { > ... when != I > - I = get_random_u32(); > ... when != I > - } while (I > E); > + I = get_random_u32_below(E + 1); > > @@ > expression E; > identifier I; > @@ > - do { > ... when != I > - I = get_random_u32(); > ... when != I > - } while (I >= E); > + I = get_random_u32_below(E); > > @@ > expression E; > identifier I; > @@ > - do { > ... when != I > - I = get_random_u32(); > ... when != I > - } while (I < E); > + I = get_random_u32_above(E - 1); > > @@ > expression E; > identifier I; > @@ > - do { > ... when != I > - I = get_random_u32(); > ... when != I > - } while (I <= E); > + I = get_random_u32_above(E); > > @@ > identifier I; > @@ > - do { > ... when != I > - I = get_random_u32(); > ... when != I > - } while (!I); > + I = get_random_u32_above(0); > > @@ > identifier I; > @@ > - do { > ... when != I > - I = get_random_u32(); > ... when != I > - } while (I == 0); > + I = get_random_u32_above(0); > > @@ > expression E; > @@ > - E + 1 + get_random_u32_below(U32_MAX - E) > + get_random_u32_above(E) > > Reviewed-by: Greg Kroah-Hartman > Signed-off-by: Jason A. Donenfeld Reviewed-by: Kees Cook -- Kees Cook