From nobody Mon Nov 03 20:29:46 2025 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4d0jqv0hDRz6Fj4w; Mon, 03 Nov 2025 20:29:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4d0jqt6pj2z3Khn; Mon, 03 Nov 2025 20:29:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1762201787; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Rx7l0mLewPeeTcmpzXyA8+Ix6oRbmIfM9n45iHRAU50=; b=gpQmtQ+vnEflGPc3D0WiXbTM3cc+O7IS+vX0PGMcQ5/N9UEQU9tT7ljZsd74/tjJPvYnlu RUaCDA3nMmn0ofJPy4p1ny7cJkkkc2FXfnn9BYDyDJlCpvelsG3eRODdO3FcE+5aoP5b9j eAJhCcCbHZP4d7PEPyGNaRJxHxO5DVTTsk2MjaUu3X2Mn/nFOxg4QTgZC+UnunlO7K2SLg aE08FXX+1g4ZKVy6WUSLwzjybrDxXeeyZXEBqUfKnBj0m3KgIYHVJR2XsdhbWqfOr2TUJq 2IDfbuzmD3lAXAdyazILrI01DJHHlL31pgr3yg9kQeqI2N3mj2NhNPTNPNFzIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1762201787; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Rx7l0mLewPeeTcmpzXyA8+Ix6oRbmIfM9n45iHRAU50=; b=FnNwkfAaneK2fEniWAfGfBvYmxCYnmM8INLOpALm5d6LX9NsnPsZxmilWse/hlInEdLB/i D8QFQqhVyMDE8wxxiynNi4YKNrQpS8iYGs+vDo6HiDPsaM+mpvNUamJqle0EC1bhSH3qPt G91mlM3VfWZdG5LeY5agbkEOceOORVu/N/+c6SCwadHVp9/c9qrxhcj7kAReDmxnHmMjlr 6TegOKOWxgtYVIzqAhuuFp4Mdf8V2/IQv7dsqDsqr12Dk85dcjZHaLizMiM0NlXh/RNZsR XK6TDkUnFCaTJ+EE03Iqh3Ti+wKXZqAtpifgbA4Xg+mt0f/2E5P29FahQdzNGQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1762201787; a=rsa-sha256; cv=none; b=Y56yfkiMYdoVSMx9UnBdIE0IwAtSF3/pL9JAh4nF7WAeWoSL3VZhOpgKDJeUP8ENHvw5T1 RY8Je1F0T1ERsn1xnHh9/qh4Xgl6A2sAcvhTyclpJEcnsBu/mEDxkzlnSkyMOC7LCbsu3F kxSXeeptSQHrCiGew8TWgIgy2FG4R3ZhpFzuBFDvAenzjal/QSWOB4++7lfwROCxR9Dhax FnNHF/fRdesfwGK5/t1Kfc1n3uVFj6fjrQMJKxaj3qWezQ91LEqIz43UH1p4ROECz3auei 7XMPZWa9Wjx4NXu3nU+vr6JT1r4xgjoFlOVIx0k2cOutKgjfPHd5BKEyrAvbOA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4d0jqt6Q6Vz9j8; Mon, 03 Nov 2025 20:29:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 5A3KTklg051125; Mon, 3 Nov 2025 20:29:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 5A3KTkBj051122; Mon, 3 Nov 2025 20:29:46 GMT (envelope-from git) Date: Mon, 3 Nov 2025 20:29:46 GMT Message-Id: <202511032029.5A3KTkBj051122@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Colin Percival Subject: git: c3f3b96725ef - releng/15.0 - fusefs: fix page fault triggered by async notification when unmounted List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: cperciva X-Git-Repository: src X-Git-Refname: refs/heads/releng/15.0 X-Git-Reftype: branch X-Git-Commit: c3f3b96725ef78ff283ae38c835bae4dad7de64a Auto-Submitted: auto-generated The branch releng/15.0 has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=c3f3b96725ef78ff283ae38c835bae4dad7de64a commit c3f3b96725ef78ff283ae38c835bae4dad7de64a Author: Alan Somers AuthorDate: 2025-10-26 00:37:02 +0000 Commit: Colin Percival CommitDate: 2025-11-03 20:29:04 +0000 fusefs: fix page fault triggered by async notification when unmounted A FUSE daemon can send asynchronous notification to the kernel in order to, for example, invalidate an inode's cache. Fix a page fault that can happen if the file system isn't yet mounted, or is already unmounted, when that notification arrives. Approved by: re (cperciva) PR: 290519 Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D53356 (cherry picked from commit 5d42c8813976af484fd3e9a896c7839ba27ca764) (cherry picked from commit 25e368c4dad3df37184258eac5809ad7791e71c4) --- sys/fs/fuse/fuse_device.c | 7 ++++++ tests/sys/fs/fusefs/mockfs.cc | 4 +++- tests/sys/fs/fusefs/mockfs.hh | 4 +++- tests/sys/fs/fusefs/notify.cc | 56 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/sys/fs/fuse/fuse_device.c b/sys/fs/fuse/fuse_device.c index 57b3559731f7..dff20ded202c 100644 --- a/sys/fs/fuse/fuse_device.c +++ b/sys/fs/fuse/fuse_device.c @@ -548,6 +548,13 @@ fuse_device_write(struct cdev *dev, struct uio *uio, int ioflag) } else if (ohead.unique == 0){ /* unique == 0 means asynchronous notification */ SDT_PROBE1(fusefs, , device, fuse_device_write_notify, &ohead); + if (data->mp == NULL) { + SDT_PROBE2(fusefs, , device, trace, 1, + "asynchronous notification before mount" + " or after unmount"); + return (EXTERROR(ENODEV, + "This FUSE session is not mounted")); + } mp = data->mp; vfs_ref(mp); err = vfs_busy(mp, 0); diff --git a/tests/sys/fs/fusefs/mockfs.cc b/tests/sys/fs/fusefs/mockfs.cc index e8081dea9604..55c191716629 100644 --- a/tests/sys/fs/fusefs/mockfs.cc +++ b/tests/sys/fs/fusefs/mockfs.cc @@ -827,10 +827,12 @@ void MockFS::loop() { } } -int MockFS::notify_inval_entry(ino_t parent, const char *name, size_t namelen) +int MockFS::notify_inval_entry(ino_t parent, const char *name, size_t namelen, + int expected_errno) { std::unique_ptr out(new mockfs_buf_out); + out->expected_errno = expected_errno; out->header.unique = 0; /* 0 means asynchronous notification */ out->header.error = FUSE_NOTIFY_INVAL_ENTRY; out->body.inval_entry.parent = parent; diff --git a/tests/sys/fs/fusefs/mockfs.hh b/tests/sys/fs/fusefs/mockfs.hh index ba6f7fded9d0..4b0628d34dd7 100644 --- a/tests/sys/fs/fusefs/mockfs.hh +++ b/tests/sys/fs/fusefs/mockfs.hh @@ -390,8 +390,10 @@ class MockFS { * @param parent Parent directory's inode number * @param name name of dirent to invalidate * @param namelen size of name, including the NUL + * @param expected_errno The error that write() should return */ - int notify_inval_entry(ino_t parent, const char *name, size_t namelen); + int notify_inval_entry(ino_t parent, const char *name, size_t namelen, + int expected_errno = 0); /* * Send an asynchronous notification to invalidate an inode's cached diff --git a/tests/sys/fs/fusefs/notify.cc b/tests/sys/fs/fusefs/notify.cc index 1e22bde13db7..d370a1e6e706 100644 --- a/tests/sys/fs/fusefs/notify.cc +++ b/tests/sys/fs/fusefs/notify.cc @@ -385,6 +385,27 @@ TEST_F(Notify, inval_inode_with_clean_cache) leak(fd); } +/* + * Attempting to invalidate an entry or inode after unmounting should fail, but + * nothing bad should happen. + * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=290519 + */ +TEST_F(Notify, notify_after_unmount) +{ + const static char *name = "foo"; + struct inval_entry_args iea; + + expect_destroy(0); + + m_mock->unmount(); + + iea.mock = m_mock; + iea.parent = FUSE_ROOT_ID; + iea.name = name; + iea.namelen = strlen(name); + iea.mock->notify_inval_entry(iea.parent, iea.name, iea.namelen, ENODEV); +} + /* FUSE_NOTIFY_STORE with a file that's not in the entry cache */ /* disabled because FUSE_NOTIFY_STORE is not yet implemented */ TEST_F(Notify, DISABLED_store_nonexistent) @@ -544,3 +565,38 @@ TEST_F(NotifyWriteback, inval_inode_attrs_only) leak(fd); } + +/* + * Attempting asynchronous invalidation of an Entry before mounting the file + * system should fail, but nothing bad should happen. + * + * Note that invalidating an inode before mount goes through the same path, and + * is not separately tested. + * + * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=290519 + */ +TEST(PreMount, inval_entry_before_mount) +{ + const static char name[] = "foo"; + size_t namelen = strlen(name); + struct mockfs_buf_out *out; + int r; + int fuse_fd; + + fuse_fd = open("/dev/fuse", O_CLOEXEC | O_RDWR); + ASSERT_GE(fuse_fd, 0) << strerror(errno); + + out = new mockfs_buf_out; + out->header.unique = 0; /* 0 means asynchronous notification */ + out->header.error = FUSE_NOTIFY_INVAL_ENTRY; + out->body.inval_entry.parent = FUSE_ROOT_ID; + out->body.inval_entry.namelen = namelen; + strlcpy((char*)&out->body.bytes + sizeof(out->body.inval_entry), + name, sizeof(out->body.bytes) - sizeof(out->body.inval_entry)); + out->header.len = sizeof(out->header) + sizeof(out->body.inval_entry) + + namelen; + r = write(fuse_fd, out, out->header.len); + EXPECT_EQ(-1, r); + EXPECT_EQ(ENODEV, errno); + delete out; +}