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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EF47C433FE for ; Thu, 6 Oct 2022 17:43:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E09326B0072; Thu, 6 Oct 2022 13:43:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D92048E0001; Thu, 6 Oct 2022 13:43:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE3576B0074; Thu, 6 Oct 2022 13:43:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9B6226B0072 for ; Thu, 6 Oct 2022 13:43:02 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3F76CC114A for ; Thu, 6 Oct 2022 17:43:02 +0000 (UTC) X-FDA: 79991245404.17.86D2859 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by imf04.hostedemail.com (Postfix) with ESMTP id 7C2264001C for ; Thu, 6 Oct 2022 17:43:01 +0000 (UTC) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4MjzLC11Gzz9syB; Thu, 6 Oct 2022 19:42:59 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LsXJRIhoNC1h; Thu, 6 Oct 2022 19:42:59 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4MjzLB5Dvqz9syS; Thu, 6 Oct 2022 19:42:58 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8738A8B78C; Thu, 6 Oct 2022 19:42:58 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id z2OiiiTjoE_O; Thu, 6 Oct 2022 19:42:58 +0200 (CEST) Received: from [192.168.233.27] (po19210.idsi0.si.c-s.fr [192.168.233.27]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 4E53E8B77D; Thu, 6 Oct 2022 19:42:56 +0200 (CEST) Message-ID: <6396875c-146a-acf5-dd9e-7f93ba1b4bc3@csgroup.eu> Date: Thu, 6 Oct 2022 19:42:55 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: [PATCH v3 3/5] treewide: use get_random_u32() when possible Content-Language: fr-FR From: Christophe Leroy To: "Jason A. Donenfeld" Cc: "linux-kernel@vger.kernel.org" , "patches@lists.linux.dev" , Andreas Noever , Andrew Morton , Andy Shevchenko , Borislav Petkov , Catalin Marinas , =?UTF-8?Q?Christoph_B=c3=b6hmwalder?= , Christoph Hellwig , Daniel Borkmann , Dave Airlie , Dave Hansen , "David S . Miller" , Eric Dumazet , Florian Westphal , Greg Kroah-Hartman , "H . Peter Anvin" , Heiko Carstens , Helge Deller , Herbert Xu , Huacai Chen , Hugh Dickins , Jakub Kicinski , "James E . J . Bottomley" , Jan Kara , Jason Gunthorpe , Jens Axboe , Johannes Berg , Jonathan Corbet , Jozsef Kadlecsik , KP Singh , Kees Cook , Marco Elver , Mauro Carvalho Chehab , Michael Ellerman , Pablo Neira Ayuso , Paolo Abeni , Peter Zijlstra , Richard Weinberger , Russell King , Theodore Ts'o , Thomas Bogendoerfer , Thomas Gleixner , Thomas Graf , Ulf Hansson , Vignesh Raghavendra , WANG Xuerui , Will Deacon , Yury Norov , "dri-devel@lists.freedesktop.org" , "kasan-dev@googlegroups.com" , "kernel-janitors@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-block@vger.kernel.org" , "linux-crypto@vger.kernel.org" , "linux-doc@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-media@vger.kernel.org" , "linux-mips@vger.kernel.org" , "linux-mm@kvack.org" , "linux-mmc@vger.kernel.org" , "linux-mtd@lists.infradead.org" , "linux-nvme@lists.infradead.org" , "linux-parisc@vger.kernel.org" , "linux-rdma@vger.kernel.org" , "linux-s390@vger.kernel.org" , "linux-um@lists.infradead.org" , "linux-usb@vger.kernel.org" , "linux-wireless@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "loongarch@lists.linux.dev" , "netdev@vger.kernel.org" , "sparclinux@vger.kernel.org" , "x86@kernel.org" , =?UTF-8?Q?Toke_H=c3=b8iland-J=c3=b8rgens?= =?UTF-8?Q?en?= , Chuck Lever , Jan Kara References: <20221006165346.73159-1-Jason@zx2c4.com> <20221006165346.73159-4-Jason@zx2c4.com> <848ed24c-13ef-6c38-fd13-639b33809194@csgroup.eu> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665078181; h=from:from:sender: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=xV/g8UUaOZTAfElJMdzKRr4WPzEp2UTWXSAym3LtymY=; b=ghbs4CI4LzV03z1l5TxVoyjhhFRqIOwoFwn0soyrjgRMTZ5MhlztF8HLHvhTNQB52jwvAz 2uFCeFzBrBPsk5s+FpBNhCN+Ml9bHSdShVXEBcBcDpPNvN6W3CDwZ005olWoNuOgpliYLL PLDhwPW4VLShpYRJGBIhzZAeKkyD8RY= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665078181; a=rsa-sha256; cv=none; b=8lkWp/55HKBLG8HhuKvqbXw+z+DAlVkl9Kzjs11hxuebiNJNedD+4YTPLFlP4Qzamn1NLQ ZjMIbboHLQj8wMd2V9h5vHZUXtjSvSz79dqkq+ehJPnv0ECizPTlMWvJM1GMCFmdU0QqaJ hRvGxM1BOttLvIwmpQPeIOaEJmGpmO4= X-Rspamd-Queue-Id: 7C2264001C Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu; dmarc=none X-Rspamd-Server: rspam06 X-Rspam-User: X-Stat-Signature: 5b5bythnjusxtmnf9npkmkbtpio1wytd X-HE-Tag: 1665078181-64854 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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;