From patchwork Tue Sep 3 15:14:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincenzo Frascino X-Patchwork-Id: 13788878 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 BB8E5CD342A for ; Tue, 3 Sep 2024 15:15:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DF008D0198; Tue, 3 Sep 2024 11:15:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 46A228D016E; Tue, 3 Sep 2024 11:15:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26F648D0198; Tue, 3 Sep 2024 11:15:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 065768D016E for ; Tue, 3 Sep 2024 11:15:26 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A4115C04F0 for ; Tue, 3 Sep 2024 15:15:25 +0000 (UTC) X-FDA: 82523775810.28.9B93265 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf15.hostedemail.com (Postfix) with ESMTP id EC2A5A0013 for ; Tue, 3 Sep 2024 15:15:23 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of vincenzo.frascino@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=vincenzo.frascino@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725376449; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=y9tGsIPSXlxjajOzhEsQ4JyuSJv7MJdnh9u07mDndu8=; b=oBJKW0jEZFo6XJJaymDHhYL+YDbH2oHzuX//MVccfFzMW/6vFL7/bhAr6zOYA7zEmTOkSW xc0/8fcf8fBf6pY9LQdl9jtKIndr17fQba+xy8HIUUllNKqARBQImvlZ9n4rP2HobL0rMu OYrf7/+Q0xq48UgVw9wAagvPgRYI53M= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of vincenzo.frascino@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=vincenzo.frascino@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725376449; a=rsa-sha256; cv=none; b=lNo8VC+3EYNzYHBmnf8esdvsdbcH2gNSqAGuUpSc0AnYvMHkhEkPFEER5R0bAc8OVikQlT 4ZE8i/uHAp95APNjLelqaF+G31XVND0qk90MCutXMxLks7lwC3znT5OeRi2shw0B+QO3Rz uvobwTrp2tQ13LPwcmQ7tm6EUJctjqk= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 99AED1424; Tue, 3 Sep 2024 08:15:49 -0700 (PDT) Received: from e119884-lin.cambridge.arm.com (e119884-lin.cambridge.arm.com [10.1.196.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 439333F66E; Tue, 3 Sep 2024 08:15:20 -0700 (PDT) From: Vincenzo Frascino To: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org Cc: Vincenzo Frascino , Andy Lutomirski , Thomas Gleixner , "Jason A . Donenfeld" , Christophe Leroy , Michael Ellerman , Nicholas Piggin , Naveen N Rao , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Theodore Ts'o , Arnd Bergmann , Andrew Morton , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers Subject: [PATCH 9/9] vdso: Modify getrandom to include the correct namespace Date: Tue, 3 Sep 2024 16:14:37 +0100 Message-Id: <20240903151437.1002990-10-vincenzo.frascino@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240903151437.1002990-1-vincenzo.frascino@arm.com> References: <20240903151437.1002990-1-vincenzo.frascino@arm.com> MIME-Version: 1.0 X-Stat-Signature: qmib9698b5uofont46udg4zq1x9af4ry X-Rspam-User: X-Rspamd-Queue-Id: EC2A5A0013 X-Rspamd-Server: rspam02 X-HE-Tag: 1725376523-494009 X-HE-Meta: U2FsdGVkX1+7VD7ncR+bVbpL9RAELowkJ2qYTeINMwS069md6nULMfR31bCuEMFtN1unL4SobMYnyxL5OzhPeGHuZYFq5eZdOZUf5URKv0AujMlMizIw8HZIRnibwmjXNMEnLGMsD2cAvfce9pExupm5RrcQtfYoxIPYluhZ8vR72i2pa6bi0ghy4GEXC+xGgWSycaRRfN1swL10it2tXYeQX6pRmwlvyXNQE3cjtWWk7dQC6bCfi7bEhGkIOclpeGzULTEqbo6gSSNLqWl+9+bWCTvje4KlFbCY+YCqTsmuedjIeqLbfdsiiaP1L8C7l+R88aJt63UefTULVhTRzx3Q1e0uVnEL5dFC/Y1UDhCDwR6SBx7YywYJTwtUsy6z6F00WimSdBrolJfueN98eKx2KwT0gWC/wPlOOb5n6ffdd7FQAmebROg0vDYnwQN81G5Qnjs546/XBvhBwRLnN8fT/pnDvghThVawMVmo6FlTqWUvrMI6EM0d/FtYWeonUwZnkppJtZXR7+QmAPBwvjEY72ebqwiwRly5uAcLAECUE7oDsZRWYFTdD42811gsx/86uEJ/tUQbvBcDVZuf+Cdt+W/QRJspN8moiJa2bO6tedqABrtXvrBE1m5WdUEWQhuE02k0p9tr321IRRuA3+Oy7GdO/3q1oYUI/0FTeGNa4x26BiArD9ejwx7dI1nuvSFIlKiIpavu++Dgq4ax+CYyx6vKj99edRphTzEBkL/rlHYLUFFb7ZrsHLSgcHKsRx1dAvNnAZJypIQf5vncmRjZtRqyUoOWBl8SUXV4fG4A7Se1PQGlETJUq0E4SpfYpC2REuSrEZdg9eevx3HPx/3UDaqL8trF983i3innZAV9xznBXYt4pAaAKezzwEwdjomkvJ1Y2kVyJqkgapwquXzYtZAZWQvzM0m6YtMvZF+oFAHnd8so2iJkM+6SX5umqC3wDchp2tBR798QY5I CRt8Pvg2 wTQOxvEhVsZluzIpejMnaNLBAlVVnhhP7RN7wi/8Qf75gFrNg3OgHWboH/VQsDYmmdtZ3WeGBWjvuiNtvlahOWUEyCiuo8RrMmvZ/7jWQ/MSswLqaSQ8qbQtZCHkL0g/kOu8IWHS45x9LaVj5YQumk93soZpFYMsn2Wxo8646NxnWBqKX/teKxXDceikrPmACZnNd2eN8uyhTCOPeOssbRs84CWBKa5OtSHX/UehkqL7w37mBj3CjogBxJ1BccW2zTwP9Wfpj3YskUEp5Amo3qDKOV5csc1MCvxLKURGk/lBiw5g= 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: List-Subscribe: List-Unsubscribe: The VDSO implementation includes headers from outside of the vdso/ namespace. Modify getrandom to take advantage of the refactoring done in the previous patches and to include only the vdso/ namespace. Cc: Andy Lutomirski Cc: Thomas Gleixner Cc: Jason A. Donenfeld Signed-off-by: Vincenzo Frascino --- lib/vdso/getrandom.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/vdso/getrandom.c b/lib/vdso/getrandom.c index 938ca539aaa6..9c26b738e4a1 100644 --- a/lib/vdso/getrandom.c +++ b/lib/vdso/getrandom.c @@ -3,19 +3,13 @@ * Copyright (C) 2022-2024 Jason A. Donenfeld . All Rights Reserved. */ -#include -#include #include #include #include -#include -#include -#include - -#undef PAGE_SIZE -#undef PAGE_MASK -#define PAGE_SIZE (1UL << CONFIG_PAGE_SHIFT) -#define PAGE_MASK (~(PAGE_SIZE - 1)) +#include +#include +#include +#include #define MEMCPY_AND_ZERO_SRC(type, dst, src, len) do { \ while (len >= sizeof(type)) { \ @@ -68,7 +62,7 @@ static __always_inline ssize_t __cvdso_getrandom_data(const struct vdso_rng_data *rng_info, void *buffer, size_t len, unsigned int flags, void *opaque_state, size_t opaque_len) { - ssize_t ret = min_t(size_t, INT_MAX & PAGE_MASK /* = MAX_RW_COUNT */, len); + ssize_t ret = min_t(size_t, INT_MAX & VDSO_PAGE_MASK /* = MAX_RW_COUNT */, len); struct vgetrandom_state *state = opaque_state; size_t batch_len, nblocks, orig_len = len; bool in_use, have_retried = false; @@ -79,15 +73,15 @@ __cvdso_getrandom_data(const struct vdso_rng_data *rng_info, void *buffer, size_ if (unlikely(opaque_len == ~0UL && !buffer && !len && !flags)) { struct vgetrandom_opaque_params *params = opaque_state; params->size_of_opaque_state = sizeof(*state); - params->mmap_prot = PROT_READ | PROT_WRITE; - params->mmap_flags = MAP_DROPPABLE | MAP_ANONYMOUS; + params->mmap_prot = VDSO_MMAP_PROT; + params->mmap_flags = VDSO_MMAP_FLAGS; for (size_t i = 0; i < ARRAY_SIZE(params->reserved); ++i) params->reserved[i] = 0; return 0; } /* The state must not straddle a page, since pages can be zeroed at any time. */ - if (unlikely(((unsigned long)opaque_state & ~PAGE_MASK) + sizeof(*state) > PAGE_SIZE)) + if (unlikely(((unsigned long)opaque_state & ~VDSO_PAGE_MASK) + sizeof(*state) > VDSO_PAGE_SIZE)) return -EFAULT; /* Handle unexpected flags by falling back to the kernel. */