From nobody Sun Sep 08 21:57:22 2024 X-Original-To: dev-commits-src-all@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 4X23jH1qW9z5WFvC; Sun, 08 Sep 2024 21:57:23 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X23jH0tTbz4b32; Sun, 8 Sep 2024 21:57:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725832643; 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=C8cjnwXGWa23WGbMtJx/wHPJzAeoJOaxxF3ozGa6SeY=; b=EcxJpFagiYrHhrZfSNi7R2QHrTARO/35RJGLoZMBdjMShmN7YB5stR5SAwUIqtMLLwkTmv IbaaDyuCx1wKio/GVErXcwcpwvLij1PXvtCsZ09pRlwd+FPcCs2XAsXnRzyww53Jx/5sZt YewLvSNjEZ9ISN4q6Cpnsy/OEoj4pHobdOow+VyUC9CDGIqwgSiZ5hTmQ8+Oe+hqKlfiys kw3TIj5gZ/LTwRoWz4R88cfxAKmZmbkjJQAY73TxEE/yMn5tME1Dz+KGbGsIjBiC1yuixp oUWrLw7KuV4OsoKm8/v0ZHgEDU7IKV93ihXEHWVloSsBNndNIbLPm2BOxQUqbQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1725832643; a=rsa-sha256; cv=none; b=KebE3cGkXHODAzaWIJlemVlsExk9zXqcdZ38b6H9PtwLzPnRzqgaM7vP1aNay13XbqTp4K NgheHLLE6RTCSOhqPIU+9yw/jGS3QiEUC9Kxan4YEQTSZa7YtIJPfynN09tSrasFyWxEkx iXKkCwNMUy6WvyFKEIGNh3abTsS2Oo+gqzDZUuxaBpKodwfLJb4ZXAgvFjdHpjE5d0bnz0 B7u3bmnN2HDND+s2qxjD4YA1J5gwIu5yF0I4rAODa7ecPFMjuuPIIcBGCZyOHscrddTgjw KAjc531DxUoYqb6ve69r/HV89Q+YvGUkJ4zpnEjesKwM1gP79GO1wXbRQET5QQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1725832643; 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=C8cjnwXGWa23WGbMtJx/wHPJzAeoJOaxxF3ozGa6SeY=; b=cEGVnQ3Txnpf6xcaU4qih2/VuO9EYTwwjn87dCJxXq/oGuBW08rPHAaBdiAX2qC25nq3cN 8ETWisc2+gbHUOsTbGby/ZgWSJPw30KNb90dtf7QDtby7mWkPZjXHGhn/noniHrr18/jmD TswcyQRFnBiHIPDGHAJExQJHZL0wM2UqAlpFV9psS5RcFtSlgA7ca+t2PFtFH8tC0cqEvx V7svcUPnnWTPplmX4/A3eODc/oZJGjN7qS62fs2/vQkHSqUNitzc7+2vI6ggi+wHJJ25dx c6EIZ/1rDZ+yVIqTi3DAxaQ87LzGgWPOukQTNhpOEGS9eETBItBNsW0S6yOp6Q== 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 4X23jH0TQSzcRb; Sun, 8 Sep 2024 21:57:23 +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 488LvMGZ089422; Sun, 8 Sep 2024 21:57:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 488LvMne089419; Sun, 8 Sep 2024 21:57:22 GMT (envelope-from git) Date: Sun, 8 Sep 2024 21:57:22 GMT Message-Id: <202409082157.488LvMne089419@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Somers Subject: git: f93a50d69df2 - main - fusefs: fix an uninitialized memory access in fuse_vnop_deallocate List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f93a50d69df2e996ff1d4f793d0dcb9de655ebdc Auto-Submitted: auto-generated The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=f93a50d69df2e996ff1d4f793d0dcb9de655ebdc commit f93a50d69df2e996ff1d4f793d0dcb9de655ebdc Author: Alan Somers AuthorDate: 2024-09-08 21:50:40 +0000 Commit: Alan Somers CommitDate: 2024-09-08 21:50:40 +0000 fusefs: fix an uninitialized memory access in fuse_vnop_deallocate If the FUSE_GETATTR issued to query a file's size during fuse_vnop_deallocate failed for any reason, then fuse_vnop_deallocate would attempt to destroy an uninitialized fuse_dispatcher struct, with a crash the likely result. This bug only affects FUSE file systems that implement FUSE_FALLOCATE, and is unlikely to be seen on those that don't disable attribute caching. Reported by: Coverity Scan CID: 1505308 MFC after: 2 weeks --- sys/fs/fuse/fuse_vnops.c | 2 +- tests/sys/fs/fusefs/fallocate.cc | 51 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/sys/fs/fuse/fuse_vnops.c b/sys/fs/fuse/fuse_vnops.c index bf272ab706da..30993441bd72 100644 --- a/sys/fs/fuse/fuse_vnops.c +++ b/sys/fs/fuse/fuse_vnops.c @@ -3075,8 +3075,8 @@ fuse_vnop_deallocate(struct vop_deallocate_args *ap) false); } -out: fdisp_destroy(&fdi); +out: if (closefufh) fuse_filehandle_close(vp, fufh, curthread, cred); diff --git a/tests/sys/fs/fusefs/fallocate.cc b/tests/sys/fs/fusefs/fallocate.cc index ff5e3eb4f4bb..a05760207648 100644 --- a/tests/sys/fs/fusefs/fallocate.cc +++ b/tests/sys/fs/fusefs/fallocate.cc @@ -310,6 +310,57 @@ TEST_F(Fspacectl, erofs) leak(fd); } +/* + * If FUSE_GETATTR fails when determining the size of the file, fspacectl + * should fail gracefully. This failure mode is easiest to trigger when + * attribute caching is disabled. + */ +TEST_F(Fspacectl, getattr_fails) +{ + const char FULLPATH[] = "mountpoint/some_file.txt"; + const char RELPATH[] = "some_file.txt"; + Sequence seq; + struct spacectl_range rqsr; + const uint64_t ino = 42; + const uint64_t fsize = 2000; + int fd; + + expect_lookup(RELPATH, ino, S_IFREG | 0644, fsize, 1, 0); + expect_open(ino, 0, 1); + EXPECT_CALL(*m_mock, process( + ResultOf([](auto in) { + return (in.header.opcode == FUSE_GETATTR && + in.header.nodeid == ino); + }, Eq(true)), + _) + ).Times(1) + .InSequence(seq) + .WillOnce(Invoke(ReturnImmediate([](auto i __unused, auto& out) { + SET_OUT_HEADER_LEN(out, attr); + out.body.attr.attr.ino = ino; + out.body.attr.attr.mode = S_IFREG | 0644; + out.body.attr.attr.size = fsize; + out.body.attr.attr_valid = 0; + }))); + EXPECT_CALL(*m_mock, process( + ResultOf([](auto in) { + return (in.header.opcode == FUSE_GETATTR && + in.header.nodeid == ino); + }, Eq(true)), + _) + ).InSequence(seq) + .WillOnce(ReturnErrno(EIO)); + + fd = open(FULLPATH, O_RDWR); + ASSERT_LE(0, fd) << strerror(errno); + rqsr.r_offset = 500; + rqsr.r_len = 1000; + EXPECT_EQ(-1, fspacectl(fd, SPACECTL_DEALLOC, &rqsr, 0, NULL)); + EXPECT_EQ(EIO, errno); + + leak(fd); +} + TEST_F(Fspacectl, ok) { const char FULLPATH[] = "mountpoint/some_file.txt";