Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp963617lqh; Sat, 1 Jun 2024 03:56:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXjrnY/0d1EuJe0PkS6X1eOfgguFGZS11pq5alZ83VUYVE38qClT//bWp5pkqllvqdxPWwjA/RzBxDhFloH40m3ujuJhEnkvhNvSnnc3A== X-Google-Smtp-Source: AGHT+IH+auyV64S2h+vM+GysmPi7l96GwLjeEjyTh7YVL71l/y5xrCetEkT8cCCiasFuW6iJ1OyG X-Received: by 2002:a05:6870:3287:b0:24c:ce54:49d5 with SMTP id 586e51a60fabf-2508bc1e99cmr5067246fac.37.1717239417940; Sat, 01 Jun 2024 03:56:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717239417; cv=pass; d=google.com; s=arc-20160816; b=qzXnnufv1DKGC5LDOATuwxv2NKXlCUrQSn/hyYdSlf9FOOPgurWCrRNFFB17g84cjC K+wOZH88TsSi8MutUiQmEar3piAOiyZrv5Au455NSp0y//yw/oibHIqoPAd3kHq8Area X974IWuFjXUdrGV+xooRxpbli3FDRwbHuaBAOGZxEpre5Ot2EpJlhotdNNjT8M4+38QM fn5fjuRrrCFJ9CqyuM9IUFeV7GyxKwILAj1jw5cNTOxNTiRFKLxy3fzxKYA/jdWbK2jz VWhMrVMhwXkVJfndRYv24bcs2bkOh/RPn+h7KCX8cFfhOjol2rMGilTq/3I1thQIBlqu HEzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=F3C8N1q5G5CmnDvpi3COJ8xyMm2eULKtCWXP4Sq6GaE=; fh=2yXPPjoChjep/W0CQCS9BISZvMguxm4gKwwfZC7SWeI=; b=NRvrZ4d9F5/X0njYXzY8t9AdCYGytlORwz50q9IPfQGhftVVG6N0Iyo2WGwedQTIzB IHNdz4ZG3n0YEesCVu1OhkWGDSKbi4YdDlEkc11rVIZ4O4jB7NSglRrhRU5MWopGwGNB t7Se3L8Cm8v4l3bZ/GZBOMjO/OyhDiHHazlHXlY3XLqs6ywWcdhXwttdPt0IqBj3Fah8 Jv4uB+RphIpQx6+/NUtrwbJZrAgh3psyXGJvwph7wpojlMRnG4DWTLOqSVtHVo5YA2A6 o2f/GzgMpvJ9AJy8cPmxapvQKtX5oCgPggdy8cKyHdCsnFTtRd52Jul66qWnFRdz+AqO oRrw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=jxWlgk+Z; arc=pass (i=1 dkim=pass dkdomain=zx2c4.com); spf=pass (google.com: domain of linux-kernel+bounces-197802-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197802-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c37fad0bb5si3022656a12.248.2024.06.01.03.56.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jun 2024 03:56:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197802-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=jxWlgk+Z; arc=pass (i=1 dkim=pass dkdomain=zx2c4.com); spf=pass (google.com: domain of linux-kernel+bounces-197802-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197802-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 85353282EEE for ; Sat, 1 Jun 2024 10:56:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B52F14EC56; Sat, 1 Jun 2024 10:56:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="jxWlgk+Z" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16E5A208A4; Sat, 1 Jun 2024 10:56:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717239409; cv=none; b=LuVD/gsEYlVkpfF5/3r6BmZ12r23hMeNMaZxSQT0JmfV0tWgizr4SEeRx0ABykp7xjgvN5xM0pdm+UJocHjgQHs3qSZvGncACnF1Egv3zeTtvepGsUuHNFv+8loTrQde5/ejdnQixwzF8RCpJ3cZJTCFpPxBY9vzVlhlLkg2oj8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717239409; c=relaxed/simple; bh=41DY8TV8S+YxvFiEAbKmnGhANeol4FJ3Mp4MdCpmIck=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=l71T74QMv8ruHcPdlJ3OYw4jLXLBqTIMODQ5BJTIfjAb7jlOMz7G0AXbczP7CdlBzmukeilcRMZKn7Rwi718Rx5Pm//m2YKTp0NG13JmarfF35Lk7aoLGyTe5Ese/bAjtZou7CZzP0U/vS86GBee1ocUgjE1AgKylqyvQiyGJIY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b=jxWlgk+Z; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CF40C116B1; Sat, 1 Jun 2024 10:56:46 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="jxWlgk+Z" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1717239405; 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: in-reply-to:in-reply-to:references:references; bh=F3C8N1q5G5CmnDvpi3COJ8xyMm2eULKtCWXP4Sq6GaE=; b=jxWlgk+ZWOpZZh5mjiYsYeT/ujL0Csc153a4DS7n5KhpFm2UZaHWVIpItNQEQwnh76T0Vp VN/fbYyhjP/HQWQEvumkcMGyMOUQjoLcxrXSQSoVRzyBcc0pSpukUXkcdDReiYMpvZ9t5N qRJXEQKGpsiYqCh4XdXcwNEkBWpL4zw= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id c390d7bc (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sat, 1 Jun 2024 10:56:43 +0000 (UTC) Date: Sat, 1 Jun 2024 12:56:40 +0200 From: "Jason A. Donenfeld" To: Eric Biggers Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, tglx@linutronix.de, linux-crypto@vger.kernel.org, linux-api@vger.kernel.org, x86@kernel.org, Greg Kroah-Hartman , Adhemerval Zanella Netto , Carlos O'Donell , Florian Weimer , Arnd Bergmann , Jann Horn , Christian Brauner , David Hildenbrand Subject: Re: [PATCH v16 2/5] random: add vgetrandom_alloc() syscall Message-ID: References: <20240528122352.2485958-1-Jason@zx2c4.com> <20240528122352.2485958-3-Jason@zx2c4.com> <20240531035917.GD6505@sol.localdomain> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240531035917.GD6505@sol.localdomain> On Thu, May 30, 2024 at 08:59:17PM -0700, Eric Biggers wrote: > On Tue, May 28, 2024 at 02:19:51PM +0200, Jason A. Donenfeld wrote: > > +/** > > + * sys_vgetrandom_alloc - Allocate opaque states for use with vDSO getrandom(). > > + * > > + * @num: On input, a pointer to a suggested hint of how many states to > > + * allocate, and on return the number of states actually allocated. > > + * > > + * @size_per_each: On input, must be zero. On return, the size of each state allocated, > > + * so that the caller can split up the returned allocation into > > + * individual states. > > + * > > + * @addr: Reserved, must be zero. > > + * > > + * @flags: Reserved, must be zero. > > + * > > + * The getrandom() vDSO function in userspace requires an opaque state, which > > + * this function allocates by mapping a certain number of special pages into > > + * the calling process. It takes a hint as to the number of opaque states > > + * desired, and provides the caller with the number of opaque states actually > > + * allocated, the size of each one in bytes, and the address of the first > > + * state, which may be split up into @num states of @size_per_each bytes each, > > + * by adding @size_per_each to the returned first state @num times, while > > + * ensuring that no single state straddles a page boundary. > > + * > > + * Returns the address of the first state in the allocation on success, or a > > + * negative error value on failure. > > + * > > + * The returned address of the first state may be passed to munmap(2) with a > > + * length of `(size_t)num * (size_t)size_per_each`, in order to deallocate the > > + * memory, after which it is invalid to pass it to vDSO getrandom(). > > Wouldn't a munmap with '(size_t)num * (size_t)size_per_each' be potentially too > short, due to how the allocation is sized such that states don't cross page > boundaries? You're right, I think. The calculation should instead be something like: DIV_ROUND_UP(num, PAGE_SIZE / size_per_each) * PAGE_SIZE Does that seem correct to you? Jason