From patchwork Sun Dec 15 18:58:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13908872 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 AEDC9E77183 for ; Sun, 15 Dec 2024 18:58:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7BDB96B0083; Sun, 15 Dec 2024 13:58:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 71EBC6B0085; Sun, 15 Dec 2024 13:58:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 570836B0088; Sun, 15 Dec 2024 13:58:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3A8FE6B0083 for ; Sun, 15 Dec 2024 13:58:24 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D0BA5B2CBF for ; Sun, 15 Dec 2024 18:58:23 +0000 (UTC) X-FDA: 82898103792.28.2D44D69 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf21.hostedemail.com (Postfix) with ESMTP id 1A0521C0002 for ; Sun, 15 Dec 2024 18:57:27 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=dABbN62e; spf=pass (imf21.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734289083; 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=NfGfjIQWmViBy4pOGS11NqIGxn2Me3U9TpY7ruVA6Zw=; b=20KRvX5c2i+MhAqK+kZAj2X/hh/d19C0zecmRCf1gnT+RAj7ahXk7/X1j+FlvrAibM4hRW Is6cJO9Sl/nspgDWn7NKNqErDIhXeAAWhFGkG8DfQced1GwrkYsYUWhEk97tjrO+5mpGk+ Veua3vzo6x5W1EZqq79jwtvvSjrNBl0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734289083; a=rsa-sha256; cv=none; b=T7oR797PqB5pnx77N87W51OCC3NA9rBp9SUvHkD0d+3wtmPD+iiBPf9VEAbsAr987rnwjB t5z5MCv2xt71xrBHfajmaZDCCShOr2Jmp5uE6D2OnGF0C7xam0IzukVxnlN2INOvq3p8Zv W6I/sMgfPM2hjUbXM7LhIoXlE+QDL10= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=dABbN62e; spf=pass (imf21.hostedemail.com: domain of cel@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cel@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 48AF05C5B59; Sun, 15 Dec 2024 18:57:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35DFFC4CEDE; Sun, 15 Dec 2024 18:58:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734289101; bh=JO3wJ67L+bBQYON3juM3zuVAaoxUR6DOyzoX+5ATl2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dABbN62e5zHRGjy3VKyLbWhYQ0+3u7z3KN/O3aLiFX/HRzHwAI/exDTn9N9DOEm3f yaVrrvx5KhPcK038AiKFW3gHmMgMLEEVE56tFRDrNYrAGcbTeP3ZY+kNFXPncSPnOj ntnD1GrCD+LebkyB8GGRpCcP/9ZnMjTqV85JjnVO9O2WVAAhK2b/U8lBb5sYwpEqbb wUlJtremoJDGKJE9lZCC+UnPZlrlbxEAsd2pGrkXXYom27BJGYMDRheoWXMQqL6vEM EOlNdo/K4AcdkhTCxGTC5tW6uhGWJ7VdAOjpMfgL6DqGG29C1+y/kDRtPsVfPrvqsK YVBIWqSL4tyjw== From: cel@kernel.org To: Hugh Dickins , Christian Brauner , Al Viro Cc: , , yukuai3@huawei.com, yangerkun@huaweicloud.com, Chuck Lever , stable@vger.kernel.org, Jeff Layton , Yang Erkun Subject: [PATCH v5 1/5] libfs: Return ENOSPC when the directory offset range is exhausted Date: Sun, 15 Dec 2024 13:58:12 -0500 Message-ID: <20241215185816.1826975-2-cel@kernel.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241215185816.1826975-1-cel@kernel.org> References: <20241215185816.1826975-1-cel@kernel.org> MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 1A0521C0002 X-Stat-Signature: f5wqu5u1afd3qtjgjxbat3pngrfnq9i6 X-Rspam-User: X-HE-Tag: 1734289047-957005 X-HE-Meta: U2FsdGVkX1/wHVEuS2VWlZC/aSs2xX0Cq6eYy/rDqj4PuouNcki2C9y9mOv1TG+N1ioif+PHXWN0xS8jViHTHIUpi7ZTMbLF5k62EDzCT+iSLnaRMvqtxJUExfLNhg7FFDRBUDE9teHOaV3rzZKW8pOSgDqRb9jHpnUPYNKqcCpmfmq9vRVwUBiw1sOg3t2oOzvDSERdtDPPTQntR1TzOOt+XXMR8+od3qnWNyFo9yYwHFZHiIHQNovKqQhbF0N4R7SzT9hrbIsnNiJ4kiogfGIatqyQQZDS+6PRglJWLHUoW02acQirZ4D9h3TC/wBqrbPU/mhRyoDxSBHKDT4LdTNXZLhnI1oXAbT0sGDDAlCa0c2LBAbHThaLBDjZFSsrM9yQmlKb5nMo97eGL9dEes0GOLD7kNCFy8XfktgqnlmLBRwZc43JqMiW9BieB9R1hJV8CO5+10GLB9EalHmFeU8HrRChJZfPE+1bLlRC1k5i5lIEegIOORmeIkTdkC9xEy2PE9phcKpYgF5D5PyvCjvglei5pQUFXYApfJS/tE4Mdl0cl0D+adVzC2uJ5pMfsFEkZpvpvY7jQv7ZRsUoNF/Sm6ngylD2SvTbsdf8gD9PHsvM7dW6hN0wQQEhKOiE472z+LDBZi5cTnG+usWw3VemRWn2AZgKMi4jHpK2xinA3IdlWaHRhiC6cb0F5lO1WaAnzgiRpBdIltPby+AwsHhUAJyul+iOKQZi7c7XzEx0hBIYTAzN+IBgDiC06TVICJ5D3g/qjrW0YT1PKsxI/QVdKUryG42uK39Hm2xQ7YxTOs06K0vn49EWwYXopEkE+UKHMadf0DwiaarXjcuWdbloI2sza2SZ1TMHDy5DDWuYM5dTLCfUMIo6OklPHIMsyNHB8Gxrz+YobqRwEBsP3nb5/3y29nsH4+ALNzG0KxCejxw/FO0WWTFhKApOeaWGEIC2A328NwAU26627qt SnkKiDIY E7CW95mfq796bQtOjZP3gd1aaencQuMIxBNNGffyLDk2E/Jw5oeTlRq+YTTRdaqjKaElbR2fvx/uZzRU+xjHE1Su0NgnhP9f73DSO0wCNSrxkl5xs5U3A4jVMetmqNuZ+1+RA8tPUwRGxttGNfKvAg44Lu+n7H4/0lEtdQwPYfYsvz4oJZkwPMCiCUpyZExiowmyX5pWFKera3A62JIUDYptxBC5W01CrMwBpqsqqgcRl4+1nA+fv+PCQs+17ymFdLmCAEBbtNZCV6hM2hcB9B+nyUA== 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 748ac5923154..f6d04c69f195 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -292,7 +292,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);