From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B5CDC43219 for ; Sat, 8 Oct 2022 01:29:28 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4Mkndy1p1Cz3ds1 for ; Sat, 8 Oct 2022 12:29:26 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=zx2c4.com header.i=@zx2c4.com header.a=rsa-sha256 header.s=20210105 header.b=nfYgePI9; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=139.178.84.217; helo=dfw.source.kernel.org; envelope-from=srs0=jvfi=2i=zx2c4.com=jason@kernel.org; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=zx2c4.com header.i=@zx2c4.com header.a=rsa-sha256 header.s=20210105 header.b=nfYgePI9; dkim-atps=neutral Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4MkVX713rGz2xb4 for ; Sat, 8 Oct 2022 01:08:22 +1100 (AEDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id D63CA61D26; Fri, 7 Oct 2022 14:08:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 070E7C433C1; Fri, 7 Oct 2022 14:08:11 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="nfYgePI9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1665151688; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GwMExxyHWRhjupCjy80ATuiTjwid+3186g/nbW9UcWo=; b=nfYgePI9KM8BlGnmbR3ouUoTgbqX0bmg+MHxz9qox2mDg1Ao4QNQA34F1ojE6QWVH7lnMZ JCnOmfX2/22xviCjt9MflZdzSKJ6jqjmdSwH6RCVEhuoe4krJ9q8+B6hn4YxZ0DzwoUloS EW51bMUr/eMjeREL5G2BmpFXN0LLrR0= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 7db71c1d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 7 Oct 2022 14:08:08 +0000 (UTC) Date: Fri, 7 Oct 2022 08:07:58 -0600 From: "Jason A. Donenfeld" To: Christophe Leroy Subject: Re: [PATCH v3 3/5] treewide: use get_random_u32() when possible Message-ID: References: <20221006165346.73159-1-Jason@zx2c4.com> <20221006165346.73159-4-Jason@zx2c4.com> <848ed24c-13ef-6c38-fd13-639b33809194@csgroup.eu> <6396875c-146a-acf5-dd9e-7f93ba1b4bc3@csgroup.eu> <501b0fc3-6c67-657f-781e-25ee0283bc2e@csgroup.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <501b0fc3-6c67-657f-781e-25ee0283bc2e@csgroup.eu> X-Mailman-Approved-At: Sat, 08 Oct 2022 12:28:34 +1100 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "linux-wireless@vger.kernel.org" , Ulf Hansson , "x86@kernel.org" , Jan Kara , Vignesh Raghavendra , "linux-doc@vger.kernel.org" , Peter Zijlstra , Catalin Marinas , Dave Hansen , "kernel-janitors@vger.kernel.org" , KP Singh , "dri-devel@lists.freedesktop.org" , "patches@lists.linux.dev" , "linux-mm@kvack.org" , Eric Dumazet , "netdev@vger.kernel.org" , "linux-mtd@lists.infradead.org" , "H . Peter Anvin" , Andreas Noever , WANG Xuerui , Will Deacon , Christoph Hellwig , "linux-s390@vger. kernel.org" , "sparclinux@vger.kernel.org" , Mauro Carvalho Chehab , Herbert Xu , Daniel Borkmann , Jonathan Corbet , "linux-rdma@vger.kernel.org" , Helge Deller , Huacai Chen , Hugh Dickins , Russell King , "kasan-dev@googlegroups.com" , Jozsef Kadlecsik , Jason Gunthorpe , Dave Airlie , Paolo Abeni , "James E . J . Bottomley" , Pablo Neira Ayuso , "linux-media@vger.kernel.org" , Marco Elver , Kees Cook , Yury Norov , Heiko Carstens , Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= , "linux-um@lists.infradead.org" , "linux-mips@vger.kernel.org" , "linux-block@vger.kernel.org" , Richard Weinberger , Borislav Petkov , "linux-nvme@lists.infradead.org" , "loongarch@lists.linux.dev" , Jakub Kicinski , Thomas Gleixner , Andy Shevchenko , Johannes Berg , "linux-arm-kernel@lists.infradead.org" , Jens Axboe , "linux-mmc@vger.kernel.org" , Thomas Bogendoerfer , Theodore Ts'o , "linux-parisc@vger.kernel.org" , Greg Kroah-Hartman , "linux-usb@vger.kernel.org" , Florian Westphal , "linux-kernel@vger.kernel.org" , Christoph =?utf-8?Q?B=C3=B6hmwalder?= , Chuck Lever , "linux-crypto@vger.kernel.org" , Jan Kara , Thomas Graf , "linux-fsdevel@vger.kernel.org" , Andrew Morton , "linuxppc-dev@lists.ozlabs.org" , "David S . Miller" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Fri, Oct 07, 2022 at 04:57:24AM +0000, Christophe Leroy wrote: > > > Le 07/10/2022 à 01:36, Jason A. Donenfeld a écrit : > > On 10/6/22, Christophe Leroy wrote: > >> > >> > >> Le 06/10/2022 à 19:31, Christophe Leroy a écrit : > >>> > >>> > >>> Le 06/10/2022 à 19:24, Jason A. Donenfeld a écrit : > >>>> Hi Christophe, > >>>> > >>>> On Thu, Oct 6, 2022 at 11:21 AM Christophe Leroy > >>>> wrote: > >>>>> Le 06/10/2022 à 18:53, Jason A. Donenfeld a écrit : > >>>>>> The prandom_u32() function has been a deprecated inline wrapper around > >>>>>> get_random_u32() for several releases now, and compiles down to the > >>>>>> exact same code. Replace the deprecated wrapper with a direct call to > >>>>>> the real function. The same also applies to get_random_int(), which is > >>>>>> just a wrapper around get_random_u32(). > >>>>>> > >>>>>> Reviewed-by: Kees Cook > >>>>>> Acked-by: Toke Høiland-Jørgensen # for sch_cake > >>>>>> Acked-by: Chuck Lever # for nfsd > >>>>>> Reviewed-by: Jan Kara # for ext4 > >>>>>> Signed-off-by: Jason A. Donenfeld > >>>>>> --- > >>>>> > >>>>>> diff --git a/arch/powerpc/kernel/process.c > >>>>>> b/arch/powerpc/kernel/process.c > >>>>>> index 0fbda89cd1bb..9c4c15afbbe8 100644 > >>>>>> --- a/arch/powerpc/kernel/process.c > >>>>>> +++ b/arch/powerpc/kernel/process.c > >>>>>> @@ -2308,6 +2308,6 @@ void notrace __ppc64_runlatch_off(void) > >>>>>> unsigned long arch_align_stack(unsigned long sp) > >>>>>> { > >>>>>> if (!(current->personality & ADDR_NO_RANDOMIZE) && > >>>>>> randomize_va_space) > >>>>>> - sp -= get_random_int() & ~PAGE_MASK; > >>>>>> + sp -= get_random_u32() & ~PAGE_MASK; > >>>>>> return sp & ~0xf; > >>>>> > >>>>> Isn't that a candidate for prandom_u32_max() ? > >>>>> > >>>>> Note that sp is deemed to be 16 bytes aligned at all time. > >>>> > >>>> Yes, probably. It seemed non-trivial to think about, so I didn't. But > >>>> let's see here... maybe it's not too bad: > >>>> > >>>> If PAGE_MASK is always ~(PAGE_SIZE-1), then ~PAGE_MASK is > >>>> (PAGE_SIZE-1), so prandom_u32_max(PAGE_SIZE) should yield the same > >>>> thing? Is that accurate? And holds across platforms (this comes up a > >>>> few places)? If so, I'll do that for a v4. > >>>> > >>> > >>> On powerpc it is always (from arch/powerpc/include/asm/page.h) : > >>> > >>> /* > >>> * Subtle: (1 << PAGE_SHIFT) is an int, not an unsigned long. So if we > >>> * assign PAGE_MASK to a larger type it gets extended the way we want > >>> * (i.e. with 1s in the high bits) > >>> */ > >>> #define PAGE_MASK (~((1 << PAGE_SHIFT) - 1)) > >>> > >>> #define PAGE_SIZE (1UL << PAGE_SHIFT) > >>> > >>> > >>> So it would work I guess. > >> > >> But taking into account that sp must remain 16 bytes aligned, would it > >> be better to do something like ? > >> > >> sp -= prandom_u32_max(PAGE_SIZE >> 4) << 4; > >> > >> return sp; > > > > Does this assume that sp is already aligned at the beginning of the > > function? I'd assume from the function's name that this isn't the > > case? > > Ah you are right, I overlooked it. So I think to stay on the safe side, I'm going to go with `prandom_u32_max(PAGE_SIZE)`. Sound good? Jason