From patchwork Wed Jun 26 13:05:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Audra Mitchell X-Patchwork-Id: 13712885 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 19514C27C4F for ; Wed, 26 Jun 2024 13:05:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C0166B0083; Wed, 26 Jun 2024 09:05:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 36DB56B0085; Wed, 26 Jun 2024 09:05:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20F4A6B0088; Wed, 26 Jun 2024 09:05:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 021776B0083 for ; Wed, 26 Jun 2024 09:05:31 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 43B0DC10B8 for ; Wed, 26 Jun 2024 13:05:31 +0000 (UTC) X-FDA: 82273061262.20.0ECFA22 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 614D88005E for ; Wed, 26 Jun 2024 13:05:24 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ArkhL1yB; spf=pass (imf30.hostedemail.com: domain of audra@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=audra@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719407112; 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:references:dkim-signature; bh=Mr03uo/qNadzOQlFY//QZdUfSWytOj/GgGVXQ4GRB8Q=; b=FEWp4lyMdz7h0kcLZEquFqjAPBD94H185XrTOzkH9bG7ccauWzWUfK9u+Hyhl03laX74WI 4VXPjvtmKohB0D3DxzEXot5ystmI4QydvjxwDemHGJcGBKtuG+gOmou4YvU3zOwaG/GOUw /yUzAgpp91uMybBUNSgq+coLaF1iUvM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ArkhL1yB; spf=pass (imf30.hostedemail.com: domain of audra@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=audra@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719407112; a=rsa-sha256; cv=none; b=7AJmCPmZHnnw9XLQQA5FLMU/W3/n329Q0uG+Icm9OX2xkCyJMAX4UvSQgvS2b8ZdnxVidJ SH8YADkDXchljabCQbDbtSePPLIUrv+hd5XDzJ5NxYdVFobUlwR5yzqPcv+8pAaK/bgP2r ykyN3hd9deUae+Nuldzf4Wf8gvX+hpU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1719407123; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Mr03uo/qNadzOQlFY//QZdUfSWytOj/GgGVXQ4GRB8Q=; b=ArkhL1yBOQAVYNUJIZeRp0cWjh4kwmKJtdwCCaSmnFGPk3cNNME2m93MOMpe60DskVbogO uKc9ZlKu2QXw6iLeRRt5DBa6jKBAyezTPk4a7BMHDyWzSNX8CW4CmptLD5LDVUQnCOsFFO PUOyk3EGHTjcFIGS94xQquj1ahVbO30= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-eCZDRI6TNFqZg1KfqIWAxA-1; Wed, 26 Jun 2024 09:05:21 -0400 X-MC-Unique: eCZDRI6TNFqZg1KfqIWAxA-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A06B919560AD; Wed, 26 Jun 2024 13:05:19 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.34.168]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DABDE1956050; Wed, 26 Jun 2024 13:05:16 +0000 (UTC) From: Audra Mitchell To: viro@zeniv.linux.org.uk Cc: brauner@kernel.org, jack@suse.cz, aarcange@redhat.com, akpm@linux-foundation.org, rppt@linux.vnet.ibm.com, shli@fb.com, peterx@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, shuah@kernel.org, linux-kselftest@vger.kernel.org, raquini@redhat.com, linux-mm@kvack.org Subject: [PATCH v3 1/3] Fix userfaultfd_api to return EINVAL as expected Date: Wed, 26 Jun 2024 09:05:11 -0400 Message-ID: <20240626130513.120193-1-audra@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Stat-Signature: pnwn1ej73y1f45n9tcyn14khi7cuopeo X-Rspam-User: X-Rspamd-Queue-Id: 614D88005E X-Rspamd-Server: rspam02 X-HE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ROcvGt5A34Fya9xpCckkbVeGiNXeQHK96jiPSMmYoSkxGNTPHO+1opFAKCl5Molxo/RKi0qYp1EPLKTzs5WM+Z1htd9ZuQangm8T1eEBUNN7ZYTvi6sD7JZx4QuI6TrOCyoBsTYtQe3Lof7vJ9ozM9h/1aetsp/YDxTedkSak+nqhxBNgoc1Gwv4QLpLpWQ1N+O+BrT6OjS1wlNB0ADS2IvK5WYwxytD+cZJFlO5O4gjqjyRizmmL7iTlRlhQiHu7hkEm3MN/5A== 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: Currently if we request a feature that is not set in the Kernel config we fail silently and return all the available features. However, the man page indicates we should return an EINVAL. We need to fix this issue since we can end up with a Kernel warning should a program request the feature UFFD_FEATURE_WP_UNPOPULATED on a kernel with the config not set with this feature. [ 200.812896] WARNING: CPU: 91 PID: 13634 at mm/memory.c:1660 zap_pte_range+0x43d/0x660 [ 200.820738] Modules linked in: [ 200.869387] CPU: 91 PID: 13634 Comm: userfaultfd Kdump: loaded Not tainted 6.9.0-rc5+ #8 [ 200.877477] Hardware name: Dell Inc. PowerEdge R6525/0N7YGH, BIOS 2.7.3 03/30/2022 [ 200.885052] RIP: 0010:zap_pte_range+0x43d/0x660 Fixes: e06f1e1dd499 ("userfaultfd: wp: enabled write protection in userfaultfd API") Signed-off-by: Audra Mitchell --- fs/userfaultfd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index eee7320ab0b0..17e409ceaa33 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -2057,7 +2057,7 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx, goto out; features = uffdio_api.features; ret = -EINVAL; - if (uffdio_api.api != UFFD_API || (features & ~UFFD_API_FEATURES)) + if (uffdio_api.api != UFFD_API) goto err_out; ret = -EPERM; if ((features & UFFD_FEATURE_EVENT_FORK) && !capable(CAP_SYS_PTRACE)) @@ -2081,6 +2081,11 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx, uffdio_api.features &= ~UFFD_FEATURE_WP_UNPOPULATED; uffdio_api.features &= ~UFFD_FEATURE_WP_ASYNC; #endif + + ret = -EINVAL; + if (features & ~uffdio_api.features) + goto err_out; + uffdio_api.ioctls = UFFD_API_IOCTLS; ret = -EFAULT; if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api)))