From nobody Thu Oct 10 19:07:24 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 4XPfQN4fHBz5YTTQ; Thu, 10 Oct 2024 19:07:24 +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 4XPfQN3rXwz4CcX; Thu, 10 Oct 2024 19:07:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728587244; 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=etRjQaUdQ1sMP0smLWAny3u7SpmjX7q0ER847HplSQI=; b=yxllAKTwvOqOtowgQEMrl+DARrFcO27DM/CaoNmh2KHtkpQAgwFfGBf4Q+f1767l1YPc7B AaZxtH2nvo81C52Q6Nu+KrF67lFovDQZfGj+MsWbdl95RC2Z4iutGgJbD1IALoxlmMuRcD 4/UAjK7PX8UPsio0IyQx9dztd3FxHsxUUy9L7/y++D3my20w/tOFAOjVz7PHwy4cxJycbU LAIn/D+hyqOe4W3deOD2rPAnG1mSTkiesI0HK81025hmPcrcGRAzuOj4beXT77i31cg+jp BEmuVNvRpFzJS5gP9u1GBVHfH7aER8WDGpofLPtx9qmBEZqQziCVrddzGYzLJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728587244; 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=etRjQaUdQ1sMP0smLWAny3u7SpmjX7q0ER847HplSQI=; b=ZYkd64xmbBFYQD/QQciLOIbWkiD7nD/QDpyxEHzO4HFvPsnUAufxcHBgve+lj8bUGgtOQi AdT46eIDcwoGSJWCEobRdzAUZ0/qpHu0+K2js+UH3/ZSP9C6yORjFHm8xr6hj9cR+AJ3x5 JIzvKp0oCS1JF8BEaEZaMadkXDE8TdYm5Vhlc9piJ0pDTQXc7ycaDeCCRuqaJQH2J7PHQK EUub0eqgi+uYmuGhV1bnKpZDflxHqZ2L+ZrkUIuOHr5mhPappC3yMakSxrXKLnp7e9pTWn OjThm6JALrgBTeMesa7Ccqftgouz+j0GUinWTUiw+drF06DrCeO5aUprZa211A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728587244; a=rsa-sha256; cv=none; b=uqcQ+/BS2/l1Fp+vR56KfGV41GuZ/bJua4BU5lJSUsvlNaLLKbP/mcN2tyTx3SeZZkS3Sv rqEiYpL7v8xrTgE49PCt6Cel0HdhJykjZhGTUZSFj97mBaOQWjZKqdYrHQKfAb/BAsNxh/ VP4zJZ6AwZALrpJuGSO2PpXdcwGsvsUgLQrHhm11ydfrbSUEacmvAhDZg3KktMG7VqlJcF uGSyTQyk9+W7eUJhSzOfSknkwXoGUP94obi88fSkx+D4b+HQ2YKtqoDirjBLrbJ0GPJ5oG olnC+BAvZCWjJzBaAShdCOrUn7YjIK8wnXqY9y5P8wvUUbAyYsTjqWwQUckq3w== 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 4XPfQN3Rsdz18tJ; Thu, 10 Oct 2024 19:07:24 +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 49AJ7ODp069680; Thu, 10 Oct 2024 19:07:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49AJ7OAX069677; Thu, 10 Oct 2024 19:07:24 GMT (envelope-from git) Date: Thu, 10 Oct 2024 19:07:24 GMT Message-Id: <202410101907.49AJ7OAX069677@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alan Somers Subject: git: cf2ed0edaefb - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: cf2ed0edaefbd273da4dc4fc51392fddb2165891 Auto-Submitted: auto-generated The branch stable/14 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=cf2ed0edaefbd273da4dc4fc51392fddb2165891 commit cf2ed0edaefbd273da4dc4fc51392fddb2165891 Author: Alan Somers AuthorDate: 2024-09-08 21:50:40 +0000 Commit: Alan Somers CommitDate: 2024-10-10 18:48:39 +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 (cherry picked from commit f93a50d69df2e996ff1d4f793d0dcb9de655ebdc) --- 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 8eb37423618c..22564c65c44d 100644 --- a/sys/fs/fuse/fuse_vnops.c +++ b/sys/fs/fuse/fuse_vnops.c @@ -3082,8 +3082,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";