From patchwork Sat Dec 28 17:55:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13922473 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 412EA194ACC; Sat, 28 Dec 2024 17:55:29 +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=1735408529; cv=none; b=CqdVBIhM5SX0Fnw/dgO2DLnlIdu7V3ALS+HJ6SKRXV9Y+vMx63wB4gMOOy6CWcdSTiNXK1IObKmr0tv3SldOh/CA8S1aHV3cctBXx4iC9SK0k2vesOwC3OQ5jJMoik+IPa5F7Rei6sQre3EENiz8rfNPQYw2TeZub/WbAlgKvqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735408529; c=relaxed/simple; bh=EECtu5EOQPP9WpkyAeyEzP3b+8wuy+Niq71T6d9EZWc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VH8/bKV/WGZELIKfOSElj16aHhC6Arsb7QALTFrynF8PhxolvCyQ22YNyYeFu1HH3CILHq3huwe+KI/5zFzE6Dhc4FldTySwpdzggDr4hz05vh1Zv8UWv1E+fIVR/GbMSLASQVnZzgXCDAI5DjxrQV5+x6j6owZZtiKPHk0mZ4c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Uma4kQ2k; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Uma4kQ2k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B35BC4CED3; Sat, 28 Dec 2024 17:55:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1735408529; bh=EECtu5EOQPP9WpkyAeyEzP3b+8wuy+Niq71T6d9EZWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Uma4kQ2kNj/TOCp8GofUQATKtCXg9pKPiiaPxerbHBR1J1MtjzVlVou7vExRGYGtA 65BSwylOREkYANw6gZKPDWebHMXN4k54oQ/kIWEaY/Tgi6t6zOjpKC/K5hq/JaKl8G WJ3Fq5btLxjxUIm9QXgeg6JEOg3z1AHfae9l+B9RTK2SGB3zJQUQNpb0OZQsq/iQ3r BjoMXzIKW60jDKbAY5trHgHFPHh6VVByIH3v5JCNoZrhwJDCuOnSTjBmT3hCC1c16T AhH8e3ewz2IJ54b5YjFJ1RfSnphPqXvPxHQkWYWOq9A4kLiOB/+TecXx07wZl7E7Fb FasZ5Fxn2KSyg== From: cel@kernel.org To: Hugh Dickins , Christian Brauner , Al Viro Cc: , , yukuai3@huawei.com, yangerkun@huaweicloud.com, Liam.Howlett@oracle.com, Chuck Lever , stable@vger.kernel.org, Jeff Layton , Yang Erkun Subject: [PATCH v7 1/5] libfs: Return ENOSPC when the directory offset range is exhausted Date: Sat, 28 Dec 2024 12:55:17 -0500 Message-ID: <20241228175522.1854234-2-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241228175522.1854234-1-cel@kernel.org> References: <20241228175522.1854234-1-cel@kernel.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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, 2 insertions(+), 2 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 748ac5923154..3da58a92f48f 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -292,8 +292,8 @@ 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) - return ret; + if (unlikely(ret < 0)) + return ret == -EBUSY ? -ENOSPC : ret; offset_set(dentry, offset); return 0;