Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2522709rwb; Wed, 30 Nov 2022 07:37:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf6w/6oozqxFNpLxT5pUdl9cSmVyPd4g2k7PFWnwZhojNTRnMiq73mXOJ91TMO7utxoZrro9 X-Received: by 2002:aa7:cd91:0:b0:469:2f36:fd with SMTP id x17-20020aa7cd91000000b004692f3600fdmr42819020edv.385.1669822671529; Wed, 30 Nov 2022 07:37:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669822671; cv=none; d=google.com; s=arc-20160816; b=l2dJ2TqCVzIL7xb7RoyP6L6rrDaiJ+6G0nodbOO6N6h5jSunSOEA9kTyXJ5XRNEE3q 2xxZOmODsAaBcphRlNn0Yp1Rbp8rtR/+lwyJ66eL90tLWqfzyy8guLCZ9oPgoZY1JNAV oKKikpIyvXS1jPFQJ3FCCusJwuzPumaDKmnCmbnD0rfqSB0FC2sdisO0vaYFUwtWD2Ey v22Lo5osSLo0+asOCEbWAG3jxum1tCTRDdHpINgil5pkBOX1R0Bf/G3dhjrbGWARlvCA BR5KYMn/XJIWpjyOwXaIfXKTZzQNXekPGqv1L+j36yaO4c2TzqxnieW5v1+vvZ718ELc LZrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:feedback-id:dkim-signature :dkim-signature; bh=cQmMnP4VZDsFwEhmSshAvzwxcmvmKRmn3yle98I76AQ=; b=XDE/ynpxbaySAmZyHmZ9LaNa7lCPc3jsq/lH1jDd7d6o6Mhdwan6+4eB94M49WqWvP LiqNIaBg/7vN5bWmrLu8GSGbiyHpZL0F1UPiE1n04Q2lFYmKODP9pACzkc0KqdDzJga/ s1vPp+9VWQmYe7cEbgaij36RFvvmH0i04q96UAKQwjbPOf8dksn/UmyLQwRaI53uM5vx ab5xyozSouubuDMJPnwqU50ryOv+yBmpE/kdZM9TIKMED07I8QvMK0BnqYhzh+Gt9kW3 +oSuKc3B2CPo0s+6ohg8j9+94dhGovdWdF0qXTZp5sc5DfHeTRrHQywN7PTVclJvlT5o Y42w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arndb.de header.s=fm1 header.b=aOTWwzuT; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=kAMZsgcE; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b17-20020a056402351100b0046400f454a3si1706479edd.125.2022.11.30.07.37.17; Wed, 30 Nov 2022 07:37:51 -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=@arndb.de header.s=fm1 header.b=aOTWwzuT; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=kAMZsgcE; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229681AbiK3P3u (ORCPT + 99 others); Wed, 30 Nov 2022 10:29:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbiK3P3t (ORCPT ); Wed, 30 Nov 2022 10:29:49 -0500 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BA5E4F1B5; Wed, 30 Nov 2022 07:29:48 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 2A59C320046E; Wed, 30 Nov 2022 10:29:47 -0500 (EST) Received: from imap51 ([10.202.2.101]) by compute6.internal (MEProxy); Wed, 30 Nov 2022 10:29:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; t=1669822186; x=1669908586; bh=cQmMnP4VZD sFwEhmSshAvzwxcmvmKRmn3yle98I76AQ=; b=aOTWwzuTKU7DDg+Kx8uwybGpGc 5n77QCfJn6GjKMCVv7Bd5pIHGfTLtVLmZhA0T84ylBk1kuieitVOIhWFViBVzdu/ X1VVcSMnkfYuTXO9Zh0GaL4rh5jzxG27TPzLnjaDPpc1mhjnY8Y/jh7PhKX0pFce ypfPUehmZ6c8kAh7a6fn19F/w9STz36JXYgLhH4Hm7QcyU4PGDJ83pJUhg8BsEo8 WJlxwwTLYGGZOiD7BTmoR0h/Q8u4WoAXk+Jw/CVsSwRwHMuCXbVXCTSTmdSRiFFj wZ7gJNHu+as1T2vvufFVGEHPsT9z/NXCBRlBIBt81S2tX6mpmE/7ybN6nyaQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1669822186; x=1669908586; bh=cQmMnP4VZDsFwEhmSshAvzwxcmvm KRmn3yle98I76AQ=; b=kAMZsgcEo9hB5JgkVN6AY4zuD4A/rfXozApzsDnjYYmL EZLBpH5eUs+WbPVWOwat6Q7v1fkHLlgqE10e50re6BLQ3+S8U+OqTvgK0RTCH5xn vDXP5b1uH1W6kTbJB195vy5J+8vINzwdbYurGBgVBzfjJaAbCCD1m5HJArRQNuM9 ni3rlso8bCngrcCmoX8PjLrUg2c+Md+ieL5T48V8MMRUBEJEGCNFraAj6G0ta1jg RRwi63hVCyUmHpUWNdX6MFgfEusGWGFob1KdFP+SZsmLFKJGnHJvxzmN94F7UXpA bH8UbeGM3jDG3y3L72oR//YyRsHwMPVGaSq0iZYiIQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrtdefgdejiecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdetrhhn ugcuuegvrhhgmhgrnhhnfdcuoegrrhhnugesrghrnhgusgdruggvqeenucggtffrrghtth gvrhhnpeffheeugeetiefhgeethfejgfdtuefggeejleehjeeutefhfeeggefhkedtkeet ffenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrrh hnugesrghrnhgusgdruggv X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 65099B60086; Wed, 30 Nov 2022 10:29:46 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-1115-g8b801eadce-fm-20221102.001-g8b801ead Mime-Version: 1.0 Message-Id: <574ad32d-566e-4c18-a645-1470fc081ede@app.fastmail.com> In-Reply-To: References: <20221129210639.42233-1-Jason@zx2c4.com> <20221129210639.42233-4-Jason@zx2c4.com> <878rjs7mcx.fsf@oldenburg.str.redhat.com> <16ec2a7a-c469-4732-aeca-e74a9fb88d3e@app.fastmail.com> Date: Wed, 30 Nov 2022 16:29:26 +0100 From: "Arnd Bergmann" To: "Jason A . Donenfeld" Cc: "Florian Weimer" , linux-kernel@vger.kernel.org, patches@lists.linux.dev, "Thomas Gleixner" , linux-crypto@vger.kernel.org, linux-api@vger.kernel.org, x86@kernel.org, "Greg Kroah-Hartman" , "Adhemerval Zanella Netto" , "Carlos O'Donell" , "Christian Brauner" Subject: Re: [PATCH v10 3/4] random: introduce generic vDSO getrandom() implementation Content-Type: text/plain X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, 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 Wed, Nov 30, 2022, at 16:12, Jason A. Donenfeld wrote: > Hi Arnd, > > On Wed, Nov 30, 2022 at 4:07 PM Arnd Bergmann wrote: >> > +#ifdef CONFIG_64BIT >> > +typedef u64 vdso_kernel_ulong; >> > +#else >> > +typedef u32 vdso_kernel_ulong; >> > +#endif >> >> This does not address the ABI concern: to allow 32-bit and 64-bit >> tasks to share the same data page, it has to be the same width on >> both, either u32 or 64, but not depending on a configuration >> option. > > I think it does address the issue. CONFIG_64BIT is a .config setting, > not a compiler-derived setting. So a 64-bit kernel will get a u64 in > kernel mode, and then it will get a u64 for the 64-bit vdso usermode > compile, and finally it will get a u64 for the 32-bit vdso usermode > compile. So in all three cases, the size is the same. I see what you mean now. However this means your vdso32 copies are different between 32-bit and 64-bit kernels. If you need to access one of the fields from assembler, it even ends up different at source level, which adds a bit of complexity. Making the interface configuration-independent makes it obvious to the reader that none of these problems can happen. >> > struct vdso_rng_data { >> > vdso_kernel_ulong generation; >> > bool is_ready; >> > }; >> >> There is another problem with this: you have implicit padding >> in the structure because the two members have different size >> and alignment requirements. The easiest fix is to make them >> both u64, or you could have a u32 is_ready and an explit u32 >> for the padding. > > There's padding at the end of the structure, yes. But both > `generation` and `is_ready` will be at the same offset. If the > structure grows, then sure, that'll have to be taken into account. But > that's not a problem because this is a private implementation detail > between the vdso code and the kernel. I was not concerned about incompatibility here, but rather about possibly leaking kernel data to the vdso page. Again, this probably doesn't happen if your code is written correctly, but the rule for kernel-user ABIs is to avoid implicit padding to ensure that the padding bytes can never leak any information. Using structures without padding at the minimum helps avoid having to think about whether this can become a problem when inspecting the code for possible issues, both from humans and from automated tools. Arnd