Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793215358; b=1e9V/DQuNqA07v2MDWiagXAg677mb6ik47MNfXd3lr7cOekdLv+tJUycYaZ1hkRSCGoM ltAQ4T3Z1mWuoVMwCKfWs46rphWxLEMNXMrsKvaZwfTyQo2JhDkevE6Po7OtU8aJnzMr9 BYY963y3U3HqLesCV8GVur6s9YXEhpSwgh0MOqmnf/Mpa9RjbMZp9taVxLMWKk1j/NQkL LtB3gE8ieJsZpUlxO/iOyE3i952tLKVR9tjsmiMI18FKQRPbmlbkaj7oyJXow2b18sBlF fQrmlSWiDH5/mrzrsttIM1Xu4ELkV7KuRWPakD3p8vr2xw1ObqAYj/PhG6uzk7xuPpA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793215358; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=STGZcNV3gP93CjfzKn39HdI9HKMRPA6OkMl0K181qaQ=; b=usQLWoAIISlWJNs0TQx6ARD1RY+q5ZNj28okDd8QTganYxisvjxH5GwkP2RtfL3mK1w/ 5HwcwTHFY4gjYyByEv8cnb18oJHKbn+KfXwzs4DUB/43QceNn0bhvgbm0Q+wBZqW2Nfg0 yndMGjqC5JYUQGINTxJMnUUOHbYyqogFtBF5mXhPWLAsUW8pkZ3nivVJo0IoJfoW8igil kKQGoEmiKULWJXZ4jPXMDaCCqia0/MfR+WmQNvnJnAbiMqMlDiQ0XoSY9QvBNdWk3csGC yCIbB5fHw3A25KBWq2ukN12NQnL//E6ATsaXHa7ptifc8fE5AiR3c6N1sAK1dG7J8RA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=nZezei87; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07DE5606A320; Wed, 28 Oct 2026 19:22:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=nZezei87 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 591C71F031E1; Wed, 28 Oct 2026 19:22:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793215357; bh=STGZcNV3gP93CjfzKn39HdI9HKMRPA6OkMl0K181qaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nZezei87My6MpbOMDEiRYzY7H/bWthfsQCfJpwHh4n66Cr0nnAOMPr5MzQin7D1b8 n7Cl6DNwTwU5RwoQDfo9DwNXBe4Jmzl3TH47Jtdn1jHRL41xMfg5xtwk2D/bskJOpW x+xgr2ypnn6MekjS7ZsADXv3XeF5Sc80ebl9wb/8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jia Zhu , Gao Xiang , Sasha Levin Subject: [PATCH 6.1 1140/1887] erofs: fix metabuf leak in inode xattr initialization Date: Wed, 28 Oct 2026 17:53:56 +0100 Message-ID: <20261028170525.349100526@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170459.200466217@linuxfoundation.org> References: <20261028170459.200466217@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jia Zhu [ Upstream commit 79b09c54c6563df9846ca3094bcfd72082c3e1d7 ] commit bb88e8da0025 ("erofs: use meta buffers for xattr operations") converted xattr operations to use on-stack erofs_buf instances. erofs_init_inode_xattrs() uses such a metabuf while reading the inline xattr header and shared xattr id array. Some error paths after erofs_read_metabuf() leave through out_unlock without dropping the metabuf, so the folio reference can leak. Consolidate the cleanup at out_unlock. erofs_put_metabuf() is a no-op if no folio has been acquired, and this keeps all paths after taking EROFS_I_BL_XATTR_BIT covered by a single cleanup site. Fixes: bb88e8da0025 ("erofs: use meta buffers for xattr operations") Signed-off-by: Jia Zhu Reviewed-by: Gao Xiang Fixes: bb88e8da0025 ("erofs: use meta buffers for xattr operations") Signed-off-by: Gao Xiang Signed-off-by: Sasha Levin --- fs/erofs/xattr.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 7c09ad1beb839..05e5733d78597 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -35,6 +35,7 @@ static int init_inode_xattrs(struct inode *inode) return 0; } + it.buf = __EROFS_BUF_INITIALIZER; if (wait_on_bit_lock(&vi->flags, EROFS_I_BL_XATTR_BIT, TASK_KILLABLE)) return -ERESTARTSYS; @@ -67,7 +68,6 @@ static int init_inode_xattrs(struct inode *inode) goto out_unlock; } - it.buf = __EROFS_BUF_INITIALIZER; it.blkaddr = erofs_blknr(sb, erofs_iloc(inode) + vi->inode_isize); it.ofs = erofs_blkoff(sb, erofs_iloc(inode) + vi->inode_isize); @@ -83,7 +83,6 @@ static int init_inode_xattrs(struct inode *inode) vi->xattr_shared_xattrs = kmalloc_array(vi->xattr_shared_count, sizeof(uint), GFP_KERNEL); if (!vi->xattr_shared_xattrs) { - erofs_put_metabuf(&it.buf); ret = -ENOMEM; goto out_unlock; } @@ -110,13 +109,13 @@ static int init_inode_xattrs(struct inode *inode) le32_to_cpu(*(__le32 *)(it.kaddr + it.ofs)); it.ofs += sizeof(__le32); } - erofs_put_metabuf(&it.buf); /* paired with smp_mb() at the beginning of the function. */ smp_mb(); set_bit(EROFS_I_EA_INITED_BIT, &vi->flags); out_unlock: + erofs_put_metabuf(&it.buf); clear_and_wake_up_bit(EROFS_I_BL_XATTR_BIT, &vi->flags); return ret; } -- 2.53.0