From patchwork Wed Nov 27 15:28:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13887143 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 5B58FD6ACE9 for ; Wed, 27 Nov 2024 15:28:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF6C56B0085; Wed, 27 Nov 2024 10:28:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C58D86B0088; Wed, 27 Nov 2024 10:28:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD2A06B0089; Wed, 27 Nov 2024 10:28:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8FADD6B0085 for ; Wed, 27 Nov 2024 10:28:23 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CF3DD418D6 for ; Wed, 27 Nov 2024 15:28:22 +0000 (UTC) X-FDA: 82832256360.11.1954CD2 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf04.hostedemail.com (Postfix) with ESMTP id 3779140007 for ; Wed, 27 Nov 2024 15:28:14 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GqMjro8o; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf04.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=1732721295; a=rsa-sha256; cv=none; b=EuHuQLFAJuqmc+ODFawAMdoloAj5ZbZcl64txukjEQmu6K6Nuf6urbbHydzdNQI2FEg4Dx Jz5oNZ9HSyKv9KmxA/oKi3NDy465ANfGAJEG9/8WG6SHJzjqUa8ax8hxs4+1kW3DMlGTZv zX4P4KM6YViGAK7AfpEAJ4XY+SQfNkM= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=GqMjro8o; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf04.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=1732721295; 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=vg3hQgOI0fVKCLF8XazcHrwtTTk7j4qHHHqA/NO5wZE=; b=ZQw86GzCmF6t8TGAHfCmpqCE3QN1HPySMBE7JncO+NXMkzmkLaX0HHapIqfHcwNrCehGP2 UBC1nJvdQXbUXOHw4Xi7leUWNvVlXWQb0FOl+JT7oHIja3mNiZbSOJhK3HXzPBhbuqtT7l Wy1p/OsspJvU6xdwC7xnHIjUarRdpoI= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 84C53A4392A; Wed, 27 Nov 2024 15:26:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14A4EC4CED4; Wed, 27 Nov 2024 15:28:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732721300; bh=NPVXYksZkbK7cP6WTdZWPp256P2B4FMiN2imk2oaSkg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GqMjro8ojkY1tLpJcZlcUCbWHypMHq37p4mKe4wKeV9ANga4aylCBQE5UXv9iYKgk H1l1QixsymlDu3V1hiAXlqQ+p7QdbeKFcSDKwZLfBJkqKPEtAZbS/0zJ1A5o+Ud9qh u7JN52eMlk8g6rwlpELRbm82tdppU3TV3hpeD9TlLb3IYDi8RMJ7YE8OmDX2u0aEvf Niovao4OIXLG6o/hSiAPHrpsys5AJQjzRXjcxcosIpPWYpk2lyS7FAz/VE13TvCiwz vIVmGM4GwB0ZQ/IklvvUcFWv2pqPyGzdYlEZ9xUf4Ze0PrIz9bToqLxo+7KqJpD+I4 EWbJYlUQFuyzQ== From: cel@kernel.org To: Hugh Dickens , Christian Brauner , Al Viro Cc: , , yukuai3@huawei.com, yangerkun@huaweicloud.com, Chuck Lever , stable@vger.kernel.org, Jeff Layton , Yang Erkun Subject: [RFC PATCH v3 1/5] libfs: Return ENOSPC when the directory offset range is exhausted Date: Wed, 27 Nov 2024 10:28:11 -0500 Message-ID: <20241127152815.151781-2-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241127152815.151781-1-cel@kernel.org> References: <20241127152815.151781-1-cel@kernel.org> MIME-Version: 1.0 X-Stat-Signature: gzbks3i98br3wacdrcpa4trqg7dybdco X-Rspam-User: X-Rspamd-Queue-Id: 3779140007 X-Rspamd-Server: rspam08 X-HE-Tag: 1732721294-830363 X-HE-Meta: U2FsdGVkX184MJEoNxQ5xHnXT+lQ/vjxbFJYo+2h9U1/qMWRisG7mTSNYCM8otTG6TbsH1MMLFN4mTY9P2svCCgAkrQ8Flie1/12emB5keu0lFFzjJjhDWdYW7bu5FMpD9sd4fozVIOjfBz4IpNFqiRs+OH3C9qmo8cyo0jSuTfI2u8A2P7l08ffFY6VheUppqyJ2DGl2TP9zk5jBDTpSpDzTOJsJ9gg4RAE296Gu/Eep95P1yAhkH7k0EgT6VLb3uaR+9WmNXjCSUXTnwoGooR8cxM2wO01cBfx3ZGicEV5OIdbXCZNDtF9lKZKMVR266mBFzw2SBBRmZc8YNZlNici4WKwHNVEqdfGuNzVLxcusfS05Oj39rg0V5JPYlMCm74O+rLFfPKYagP9cJbZLMxNbPAvzY2oYR87ql9Ce4nGxHjtxEptZg6iaLbxSYiFAhRxKBTMG7ymsN70NrlEAtuvrRI76B+PH2Y8wUbw+dJSHPKRjgkb48iGs0p46UirmLl2KcNwVWjEpT0Z8T8CPt8KRmc9j7uYL1FICU9OZtYzxhKPHdlNsxIysIZBY+eEUZ9IwEekwH2BfoMgwow9vBPTKVOFcuEUauer8HNcq/rn5M6yYG2tUTh3BILE6lScSvUJAe0CZJcBKt+Mx2/X9JUmkse2A8vaPx0Qp9QxyHwCgjednG2tXQG2jOZTEa33wf6QRYRFPXdEFLx2m/4nUL1+sy8D/npcGMsSSZ5acuVWjz/7dvvC14gzrS9zTU16sDwche+OZzfuXleAOmdp92zBjZa/PAmVRXTi9qtxboyRjrTXH6fMWf23KU23eNOg9o86IUi7nAAjBK0kVLj7gRNk15LhbIR9hMlVbp+6MADSoqYlS6QN8SXcWgrDBbvSkKIagBdDaXT/oWsQoonNacXV+7RdYtBOt8GkkvIOk8Eam5VZQNwoW8U1NoZnrfMO27z2M5eLXtR4iaYVG7L mjt/c8vQ yfeH688tFN90eyjSbwN2HsnQGjQwwR8z7wo9ZKcn2I4gzKdDBIyo9QneC7qqHf5EEoIBOJYXoGFs54BD8AkKP538l3GC8mIc3zNx6jcyPfoSAWWOk1sfFs7rpwgxVi1D7vtP3nGoV9iSWv0i06uIkRWHGtzsSKS1jQzy3deanGVkrFfBh89PlhI86W0wNlQsrLf43+E0TLuBaHbCyelXdKvqEP1FjpcX88854lbpYBqqFhrR2bboWffQ/xrO0sNemVCtkd+stvt20d7eKNAvc9eIM8Q== 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+ Reviewed-by: Jeff Layton Reviewed-by: Yang Erkun Signed-off-by: Chuck Lever --- 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);