From nobody Mon Sep 28 21:08:03 2026 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) (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 8163A440A13; Mon, 17 Aug 2026 15:18:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786979909; cv=none; b=E5dd+TVvZjKHzLwESVfEGUVwSaZkV9VbA4zakcT1P+nXKraRM792JKdfk+zg5sExmN0s3pH2IYp7y98kMyEk+TjPJ0hxLKBQO8rOWfaV8XR97FtILTzMT7dIh+gfnLwphBLSUmFscYZ4jMW1RXhRjrzyKL9fXwZdqaZE8E4hNms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786979909; c=relaxed/simple; bh=oPtTfHEcpMTFd9+ls6wSqfDqMGeBmozNcUF0YjVmNxY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SvG/IFWTbUQDKtUeNWUi8zSasQn8srWAZsVWL+xuiJT+9EgnBTAEpcHxAL+RoMkB0GTYcL8vpqE6k0OltEDyEuC9OJxnYbv7wzDJj6SUmORJrAcYnWlStKG5xjVwkY4E96wm6Th0auXebgiC2RyQewLh0PJFsUloBxYB9kfe1rs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=OGTE737w; arc=none smtp.client-ip=115.124.30.98 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="OGTE737w" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1786979901; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; bh=OfsYHPDZd44RieEP0J3vhgYzaNzr+sUgN6eIy9rDHLs=; b=OGTE737wI5gXE6oNM5hz0L13ePUqTyC0jpkGjR5/Lvi8WiRkaihfacl9AQuWMqPsB1YMLOGlsmbHBuMCWgysAo04cNZNaVCjrxCDf5UseNqi2SqNnk1drfpmyP2wjrJLCG6Ufnxn+7qxVP9kjtlYqPB//3lo9ZlPUgVsAd2bhXI= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R241e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045098064;MF=libaokun@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0X9A6o9t_1786979900; Received: from x31h02109.sqa.na131.tbsite.net(mailfrom:libaokun@linux.alibaba.com fp:SMTPD_---0X9A6o9t_1786979900 cluster:ay36) by smtp.aliyun-inc.com; Mon, 17 Aug 2026 23:18:20 +0800 From: Baokun Li To: fuse-devel@lists.linux.dev Cc: miklos@szeredi.hu, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, vgoyal@redhat.com, jefflexu@linux.alibaba.com, stable@vger.kernel.org Subject: [PATCH 1/2] fuse: fix invalidate lock leak on setattr writeback failure Date: Mon, 17 Aug 2026 23:18:00 +0800 Message-ID: <20260817151801.2677899-2-libaokun@linux.alibaba.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260817151801.2677899-1-libaokun@linux.alibaba.com> References: <20260817151801.2677899-1-libaokun@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable fuse_do_setattr() takes filemap_invalidate_lock() for a DAX truncate (fault_blocked =3D true) and releases it at the out:/error: labels. But when a writeback flush is also needed, a write_inode_now() failure returns directly and leaks the lock, so any later fault or truncate on the file stalls on the stale rwsem. For example, truncate(2) on a setuid file reaches fuse_do_setattr() with both ATTR_SIZE and ATTR_MODE set: truncate(2) =E2=94=94=E2=94=80 do_truncate() =E2=94=9C=E2=94=80 dentry_needs_remove_privs() # S_ISUID =E2=94=94=E2=94=80 notify_change() # KILL_SUID -> = ATTR_MODE =E2=94=94=E2=94=80 fuse_setattr() # no killpriv: =E2=94=82 # ia_valid |=3D ATTR_= MODE =E2=94=94=E2=94=80 fuse_do_setattr() =E2=94=9C=E2=94=80 filemap_invalidate_lock() # IS_DAX && is_= truncate =E2=94=94=E2=94=80 write_inode_now() # is_wb && ATTR= _MODE =E2=94=94=E2=94=80 if (err) # e.g. daemon -= > -EIO return err # <- lock leaked Fix this by adding an unlock label that releases the lock before returning the error, and use it for the fuse_dax_break_layouts() failure path as well. Fixes: 6ae330cad6ef ("virtiofs: serialize truncate/punch_hole and dax fault= path") Cc: # v5.10+ Signed-off-by: Baokun Li --- fs/fuse/dir.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 0e2a1039fa43..48763bc192f3 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -2161,10 +2161,8 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct = dentry *dentry, filemap_invalidate_lock(mapping); fault_blocked =3D true; err =3D fuse_dax_break_layouts(inode, 0, -1); - if (err) { - filemap_invalidate_unlock(mapping); - return err; - } + if (err) + goto unlock; } =20 if (attr->ia_valid & ATTR_OPEN) { @@ -2191,7 +2189,7 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct d= entry *dentry, ATTR_TIMES_SET)) { err =3D write_inode_now(inode, true); if (err) - return err; + goto unlock; =20 fuse_set_nowrite(inode); fuse_release_nowrite(inode); @@ -2299,6 +2297,7 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct d= entry *dentry, =20 clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state); =20 +unlock: if (fault_blocked) filemap_invalidate_unlock(mapping); return err; --=20 2.43.7 From nobody Mon Sep 28 21:08:03 2026 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) (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 4A458445AD2; Mon, 17 Aug 2026 15:18:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.112 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786979909; cv=none; b=MojMGWwEEb7t0ivo0/z1dBH+ZyomQDeGArR/OvSLLVBkr+R2n+WEH7gPmuDp2oZ6LuNf3ilwR34JbeapYAQQzjtLytdIoyBnZxsWUX7vM8bA3ZAHRru98ctc7vQlk9ag3qydf/4BX2sI2sdrXrFPfZ1+iYPTEmUs+ZXik3a7aF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786979909; c=relaxed/simple; bh=iTuPbUlen4774ig2yCMvJ99XD5oszOd5LAnS26sa+nk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nq7Os9xMPjR3F2uVfFJnxfRAYbgByZmY8i0c27c25mKJY0adkcVb6/gzZDkOuCBYsjzwCSm+LfIS4BLqj/5wlviWlNNaZGFd/t+DNSM6v8cagDkYdkfg3E9ChW/xyuUvOlD74Er4AjAT36RxS89RQysZpkTrdRp9c2ke/md7RMU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=cIBWcbYa; arc=none smtp.client-ip=115.124.30.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="cIBWcbYa" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1786979902; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; bh=LZc3qwCUsh6/0o/S/EuPVqXvFA+E/rxqZAGvfeoj3z0=; b=cIBWcbYarxHsqSvjVyJhYKQitcQAQoSKnLSmQv5bYgo6akMo1aPnHLMppHi5Yt2LQdIdWygCBPoA3o9rJyZgpZZ4KyCOXmbv+FCxa7C3lH/pnd+gWu5/gO+yKiDJQN/NyWe66D8EtMHzo944sf6StKsDWTrhhn2ODd7Zh3EFsT0= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033032089153;MF=libaokun@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0X9A6oAG_1786979901; Received: from x31h02109.sqa.na131.tbsite.net(mailfrom:libaokun@linux.alibaba.com fp:SMTPD_---0X9A6oAG_1786979901 cluster:ay36) by smtp.aliyun-inc.com; Mon, 17 Aug 2026 23:18:21 +0800 From: Baokun Li To: fuse-devel@lists.linux.dev Cc: miklos@szeredi.hu, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, vgoyal@redhat.com, jefflexu@linux.alibaba.com, stable@vger.kernel.org Subject: [PATCH 2/2] fuse: fix invalidate lock leak on open O_TRUNC DAX failure Date: Mon, 17 Aug 2026 23:18:01 +0800 Message-ID: <20260817151801.2677899-3-libaokun@linux.alibaba.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260817151801.2677899-1-libaokun@linux.alibaba.com> References: <20260817151801.2677899-1-libaokun@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable fuse_open() takes filemap_invalidate_lock() for a DAX truncate (dax_truncate =3D true) and releases it before the out_inode_unlock label. But when fuse_dax_break_layouts() fails, the goto out_inode_unlock skips the unlock and leaks the rwsem, so any later fault or truncate on the file stalls on the stale lock. fuse_dax_break_layouts() can fail with -ERESTARTSYS when a signal interrupts the wait for busy DAX pages to drain: open("file", O_RDWR | O_TRUNC) =E2=94=94=E2=94=80 fuse_open() =E2=94=9C=E2=94=80 filemap_invalidate_lock() # dax_truncate =E2=94=94=E2=94=80 fuse_dax_break_layouts() =E2=94=94=E2=94=80 dax_break_layout() =E2=94=94=E2=94=80 wait_page_idle() # TASK_INTERRUPTIB= LE =E2=94=94=E2=94=80 fuse_wait_dax_page() # unlock, schedule= , re-lock =E2=94=94=E2=94=80 signal =E2=86=92 -ERESTARTSYS goto out_inode_unlock # <- lock leaked Fix this by moving filemap_invalidate_unlock() below the label so that all error paths release the lock, and rename the label to out_unlock as it now covers more than just the inode lock. Fixes: 2fdbb8dd0155 ("fuse: fix deadlock between atomic O_TRUNC and page in= validation") Cc: # v6.0+ Signed-off-by: Baokun Li --- fs/fuse/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index ceada75310b8..e7b2a839f081 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -272,7 +272,7 @@ static int fuse_open(struct inode *inode, struct file *= file) filemap_invalidate_lock(inode->i_mapping); err =3D fuse_dax_break_layouts(inode, 0, -1); if (err) - goto out_inode_unlock; + goto out_unlock; } =20 if (is_wb_truncate || dax_truncate) @@ -296,9 +296,9 @@ static int fuse_open(struct inode *inode, struct file *= file) else if (!(ff->open_flags & FOPEN_KEEP_CACHE)) invalidate_inode_pages2(inode->i_mapping); } +out_unlock: if (dax_truncate) filemap_invalidate_unlock(inode->i_mapping); -out_inode_unlock: if (is_wb_truncate || dax_truncate) inode_unlock(inode); =20 --=20 2.43.7