From patchwork Tue Nov 26 15:54:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13886133 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 962A2D3B9AC for ; Tue, 26 Nov 2024 15:54:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4642E6B0083; Tue, 26 Nov 2024 10:54:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4131C6B0085; Tue, 26 Nov 2024 10:54:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DAAC6B0088; Tue, 26 Nov 2024 10:54:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 11B076B0083 for ; Tue, 26 Nov 2024 10:54:57 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B60F21A1362 for ; Tue, 26 Nov 2024 15:54:56 +0000 (UTC) X-FDA: 82828694466.22.1BBA970 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf03.hostedemail.com (Postfix) with ESMTP id DA8BA20011 for ; Tue, 26 Nov 2024 15:54:52 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=fIAh4dxF; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf03.hostedemail.com: domain of cel@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732636492; a=rsa-sha256; cv=none; b=17UPU6sVvAXS731Sgc66ejiPdY62thas89wzvtxnnJrmQOl2aiNrdR9Vx4Js+/1o0K7qC7 6G0PTeLgnRN1uFadPZ9YBd0gjz1w8NQPsWgvH41Mlqay3XIin2UnH4kiLVCw9Bn53BrZv6 ZMiu8Zyv1j9hxczp4Rk7uFNo5I/Qk9s= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=fIAh4dxF; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf03.hostedemail.com: domain of cel@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732636492; 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:dkim-signature; bh=9bhJfmmX8eWLULpBVOq7lXLXxEaVv114s3PiBizSr28=; b=h1ZUxfhV6ohA5teLL4W2hqohgUqkYnq539dNmX8sWKLowJQ1MbMFCI3KOZljXv6yheZpow 2DxjgRAcvZB+DRY0OtCUo2YXLrmdRfW8f10kqGhZ/61XTJ1wjThvL9caQEkvOE5QATJd8+ A2LcVSTdlnGJVLziiiqhXpqXjEPselM= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 4556EA407F8; Tue, 26 Nov 2024 15:53:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 345EFC4CED0; Tue, 26 Nov 2024 15:54:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732636494; bh=uhgh93plhiFV1pHFjFAu6nt5SYYT8N+YCq9mpcqsLXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fIAh4dxF+U4xexzovtB/7kPFGF35L5IKVEm3YrWxmpi09Xhg+s3Q6xBHA+BEOKxM6 01c8Ahzm2uaKRidP1kBlNetkAHbGcVjfgSZQcMQsSVcnkzT0DMkz1+VBNapdeMsbVW ggHJdbDQPhH5XARuL9TLITKoR450QibdFfJ4W/Xn+OhcLvlvPGY8eNqgc66lmwXcem RlTQItF+ZF8mUqqa7lJxN0dnHSjampVwpgtBVUukrEZkV10plMr9XHU9RyWafi/DGu Mmqs1R8Ie5cshvo6L+ztqqUnOPCJWlkOhaXYEp1Aaci3D1uCUKchh4g1N9J1OOlxuO KmFZcPfEyEVEg== From: cel@kernel.org To: Hugh Dickens , Christian Brauner , Al Viro Cc: , , yukuai3@huawei.com, yangerkun@huaweicloud.com, Chuck Lever , stable@vger.kernel.org Subject: [RFC PATCH v2 1/5] libfs: Return ENOSPC when the directory offset range is exhausted Date: Tue, 26 Nov 2024 10:54:40 -0500 Message-ID: <20241126155444.2556-2-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241126155444.2556-1-cel@kernel.org> References: <20241126155444.2556-1-cel@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: DA8BA20011 X-Rspamd-Server: rspam01 X-Stat-Signature: 31f8o3scqa7wdj5pq67m1if7o9w939a5 X-HE-Tag: 1732636492-818874 X-HE-Meta: U2FsdGVkX1+PP1hfCvJrGz799MuRu52zGq/k9wFZ6AzLbOoOMuD8Q2hTSn5Lf8hiOeC523GkeHMIN0XsiP+VIpnoV9N2JXZXyUm9mCHdffb+Ud23aWZYhKA+MxV8lVhbA98lah+oVHey6ToxdVhYYpLfNrbtYvrEwVYCUooA05mrKvYWbwEFZMCXojLC0xuLQba5nrVX3PrsIE77rxkHVWq+GPHyX5nL6zvQxTVtuP2M23TAG1v13Z7AC4WU1xs3ShNiXKpk/erdH+Ce307QIeQUBX8Nn4Rb4jFFDE6apyxstpedmmAcP/IcDO1AV1Tm+Woxw4/FXX7NU+2YyCm2UdBuhjd6sbzmfONwZC0XN5/E10jGiMmUp5/WGibp7qXkOf1d1A6aBnAdFHcdqI0S/AnVwLTvR8MHEWeOtRWvN/yvFbaBkH5sjx8uebk5Hb5+sHeM2qPeXoRvyw29dyNt954jKJTcICkxCd3D+qewR/rUR3Q0BU4kvkmZC/oxruB1TCdt7MtsnOcr5kSZxQEy35UDBXgdd6EYwA4MiljcH3m9auHkT4ddSAVKOldb7/dpe+TA8r5kQjZznHEaVD7JhY3T/ACl75IoZlmWFnSzdB7cR8vdEAiYRSQFCzMyZ3HHuRw/pu7jwu6Gq8qEJE4in6uBh4AJFQBlDC047e/HXsVuDXl9alUY7iL70wvtkD+TwkhA46hfycGiqX0kpmxkirAN5VWewI1hwv0+k3f/1/XZlYqyX8Qs98PQJL/qZ8Ll6OmYGn4nREBLhhzTSVrsZfb8Mv8PPOqsY1m9RKVkieRB8gqoI5vb0e2EiJwqh4HcIy+znQXSCQyprnjgeJsQYJ3uAJ9yfbbODJtah22GYh+KDqHlGhdtxhd9FdumauD5a5iNmA75B1ws7f+OD2RVSgHtiXh4QMwAQsHj1zV9LH42qvNRnWToCYu5iJCVreR+lg41ptCCx4u5IUVs9XJ Hwr9PFhA KLxa6Z/r2X3MCn3kGaM1mVQzWscjMRD881ISsIsoSA7wf3+c2GkSXgVU0p0XeJRhzOAGax+dSOVAgl6Lz7puVnxNirJjr3eHDpFezicq/De5YT7wSoc3zsbi+Fbu9Bo6RaFi5srz2h/Ds1okIEZhHgbTwkBoe3Xu9LLs75h9aJmHfOttrB2vmhE7HEW1pD+UnaBAzGEdsPLGtbGlIqaeCv61bb0YVpVv0BcE/OpC9PmFhRNutPe5dyRizDHotAJxKgIAR 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: From: Chuck Lever Testing shows that the EBUSY error return from mtree_alloc_cyclic() leaks into user space. The ERRORS section of "man creat(2)" says: > EBUSY O_EXCL was specified in flags and pathname refers > to a block device that is in use by the system > (e.g., it is mounted). ENOSPC is closer to what applications expect in this situation. Note that the normal range of simple directory offset values is 2..2^63, so hitting this error is going to be rare to impossible. Fixes: 6faddda69f62 ("libfs: Add directory operations for stable offsets") Cc: # v6.9+ Signed-off-by: Chuck Lever Reviewed-by: Yang Erkun --- fs/libfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/libfs.c b/fs/libfs.c index 46966fd8bcf9..bf67954b525b 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -288,7 +288,9 @@ int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry) ret = mtree_alloc_cyclic(&octx->mt, &offset, dentry, DIR_OFFSET_MIN, LONG_MAX, &octx->next_offset, GFP_KERNEL); - if (ret < 0) + if (unlikely(ret == -EBUSY)) + return -ENOSPC; + if (unlikely(ret < 0)) return ret; offset_set(dentry, offset);