From mboxrd@z Thu Jan 1 00:00:00 1970 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 8571A19AD93; Tue, 16 Jul 2024 15:52:21 +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=1721145141; cv=none; b=S6aTHQQ7/RPXBgVttVIrmvGffSsny2/9FkwOz9ERRI//s7XnMTrVZ2nn6esdbUKIb722YG6buTNC2D3Muo9n6WxeerDXCiB3GLhhCc+95v4j4QnSN1eKCTMwrj3XhGKp1agat6LqnnGSIrh1pR2pjK7WQZ3uo4Vewr2q5MqVvIg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721145141; c=relaxed/simple; bh=gY+5ojZwOPZ/OEPKbiv+/8cmkeZEVaOFgUjrXo2mGGA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u2dskD8cehR0BQfZM+aFXTcToUEXqq3nVQIS3P3BBG4UhjSQ1efV41GXo4mLGNdHeAMSyhOnMlyLuhfAzoKwEN4JYZCW2JhieSl0UYoF4RvDXVB0lLmO1AzAFW3pRdff6yOZfUEYcPP+FGs+YKd4u7qBmybg6Vy4Zgok8dDRCq0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=dBTFPyMr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="dBTFPyMr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5B61C116B1; Tue, 16 Jul 2024 15:52:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1721145141; bh=gY+5ojZwOPZ/OEPKbiv+/8cmkeZEVaOFgUjrXo2mGGA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dBTFPyMrJxlgT39HIU/dJXIfNR+mmeotCh5g+F02TSyAg6kggOsJUcuDZvfIXmr18 VnnCPengpyKSz/voI+A7BHulHntN6mvlOZ+Rc0dMKzZRvwf/1i/gQyd6Y9X3fhfPBT KGV+n9dC0ZnVqhUkDQ3z9IC50IeiYuCKSe4pDK+4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Audra Mitchell , Al Viro , Andrea Arcangeli , Christian Brauner , Jan Kara , Mike Rapoport , Peter Xu , Rafael Aquini , Shaohua Li , Shuah Khan , Andrew Morton Subject: [PATCH 6.9 112/143] Fix userfaultfd_api to return EINVAL as expected Date: Tue, 16 Jul 2024 17:31:48 +0200 Message-ID: <20240716152800.287559908@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240716152755.980289992@linuxfoundation.org> References: <20240716152755.980289992@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Audra Mitchell commit 1723f04caacb32cadc4e063725d836a0c4450694 upstream. 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 Link: https://lkml.kernel.org/r/20240626130513.120193-1-audra@redhat.com Fixes: e06f1e1dd499 ("userfaultfd: wp: enabled write protection in userfaultfd API") Signed-off-by: Audra Mitchell Cc: Al Viro Cc: Andrea Arcangeli Cc: Christian Brauner Cc: Jan Kara Cc: Mike Rapoport Cc: Peter Xu Cc: Rafael Aquini Cc: Shaohua Li Cc: Shuah Khan Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- fs/userfaultfd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -2053,7 +2053,7 @@ static int userfaultfd_api(struct userfa 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)) @@ -2077,6 +2077,11 @@ static int userfaultfd_api(struct userfa 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)))