From nobody Fri Feb 23 10:49:50 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 4Th6GQ3DGMz5CF7j; Fri, 23 Feb 2024 10:49:50 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Th6GQ2n5xz4Z8v; Fri, 23 Feb 2024 10:49:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1708685390; 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=oCoebOZIZpUUZe56RTuu8tVTV6dApa88vDtIH/j7dLk=; b=TgLuXkN3WXgiM6kEJ4M/tasio7aaWzgJDEQqxaQ4H+IC3DxiYVrRnYkKn6JFqVLrWjwadb 2BfoXlUgOU3dHNraPB7vXqyfaRBm5mxwiLQohcSx31yKq0d3DjjX19h6fy9xMHx0pZ3Ar6 8tSocjTbswNUQZafgBVZiEXNQ+FjFcpaX/RW/JnRq/mQ6MEB+fax3b6ESq/jKhdQriaCKG VkhOdrhXRgfI2Nty7Syrw9jzdAjGpFpetGdFODHf3/LxNoIx8PN64GbGZeBzDYMVDq1UQs UvRAVLTnRv/v8yRJ2pxfBYRIsWf28ZZC8zPYHs4q4fzf+pWQk8MD3XR1Q6gWBQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1708685390; a=rsa-sha256; cv=none; b=NyxFWQ0/GN7nIy5ZY/Sn6p1bAC7glnArmra1Sp4MkK0zLj2+Od3uJJPSv+BJWniJTOIYX9 iGdS03AVRoKOO6T8QqZLxhUBNKO7PT0KNKDNffXKbyofDTIAOdEMIjRkImSC9v2rkIFL46 dIlkBuKCLMMQ/R+2Vb1EB5jjbYGqcmRM3+lsn/o5UrrSmynxrd2IedHlPT0DBxSkhW4ce4 l2cyvlh54F6cZunVp4Ah/QMrh5CGKgLvwXKWnsykfuS91ygxmbZXgigkPU8Ll72X5T0CRE q+nlbGAEGqC/TDeDbBxInI9p31DcSSTBQoXdLvxOSLHubQ6ketDl/7+PM3BC6A== 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=1708685390; 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=oCoebOZIZpUUZe56RTuu8tVTV6dApa88vDtIH/j7dLk=; b=m1QwWzbYkknjTa2HMgxd/foLa3/YczwrGh3wbiaamlJ9Vww/alnGMaBMJjaF4WJ0nXKm8L WMEHvolOOwfVBY6Q3oW9ObcF14dl3xviu02OSuQPWfia+RGMmwQddJny6UgcmFd8vpdTLy +p4HxM2yECgpkaz27IwpVb5B3ju/TCVrAXw7G2cDBkRP3Jbfmch5+jcXrK7WjBhKq1OBos iU5SzIECwG40mwDzOrlCeIgZkA93jAY1t0Yl95bIXU6nMns6wJPl1zs1SBFzl7fJcCY7Xw qv7ZaB31df2XRXW23sQbzQg57hfrBPNeBd2yrsEwCHD2n8r2Qv64ATqKy7tjLA== 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 4Th6GQ1qy2z1BWr; Fri, 23 Feb 2024 10:49:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 41NAnom8079583; Fri, 23 Feb 2024 10:49:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 41NAnoUf079580; Fri, 23 Feb 2024 10:49:50 GMT (envelope-from git) Date: Fri, 23 Feb 2024 10:49:50 GMT Message-Id: <202402231049.41NAnoUf079580@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Stefan =?utf-8?Q?E=C3=9Fer?= Subject: git: fba1a994acfe - stable/14 - msdosfs: fix potential inode collision on FAT12 and FAT16 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: se X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: fba1a994acfe31d957e9e26a5f12a6fdd1689bd2 Auto-Submitted: auto-generated The branch stable/14 has been updated by se: URL: https://cgit.FreeBSD.org/src/commit/?id=fba1a994acfe31d957e9e26a5f12a6fdd1689bd2 commit fba1a994acfe31d957e9e26a5f12a6fdd1689bd2 Author: Stefan Eßer AuthorDate: 2024-02-20 12:02:24 +0000 Commit: Stefan Eßer CommitDate: 2024-02-23 10:47:58 +0000 msdosfs: fix potential inode collision on FAT12 and FAT16 PR: 277239 Approved by: mckusick (cherry picked from commit 445d3d227e68f85157d0301d1706aa488e8423da) --- sys/fs/msdosfs/denode.h | 8 +++++++- sys/fs/msdosfs/msdosfs_denode.c | 19 ++++++++++++++++--- sys/fs/msdosfs/msdosfs_lookup.c | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/sys/fs/msdosfs/denode.h b/sys/fs/msdosfs/denode.h index ad52a736592c..0d31b0583fa6 100644 --- a/sys/fs/msdosfs/denode.h +++ b/sys/fs/msdosfs/denode.h @@ -162,7 +162,7 @@ struct denode { u_long de_FileSize; /* size of file in bytes */ struct fatcache de_fc[FC_SIZE]; /* FAT cache */ u_quad_t de_modrev; /* Revision level for lease. */ - uint64_t de_inode; /* Inode number (really byte offset of direntry) */ + uint64_t de_inode; /* Inode number (really index of DOS style direntry) */ }; /* @@ -217,6 +217,12 @@ struct denode { #define VTODE(vp) ((struct denode *)(vp)->v_data) #define DETOV(de) ((de)->de_vnode) +#define DETOI(pmp, cn, off) \ + ((cn) == MSDOSFSROOT \ + ? (((uint64_t)(off) >> 5)) \ + : (((((uint64_t)pmp->pm_bpcluster * ((cn) - 2) + (off))) >> 5) \ + + pmp->pm_RootDirEnts)) + #define DETIMES(dep, acc, mod, cre) do { \ if ((dep)->de_flag & DE_UPDATE) { \ (dep)->de_flag |= DE_MODIFIED; \ diff --git a/sys/fs/msdosfs/msdosfs_denode.c b/sys/fs/msdosfs/msdosfs_denode.c index 612b318ce6e8..7f275d387a25 100644 --- a/sys/fs/msdosfs/msdosfs_denode.c +++ b/sys/fs/msdosfs/msdosfs_denode.c @@ -133,10 +133,13 @@ deget(struct msdosfsmount *pmp, u_long dirclust, u_long diroffset, * entry that represented the file happens to be reused while the * deleted file is still open. */ - inode = (uint64_t)pmp->pm_bpcluster * dirclust + diroffset; + inode = DETOI(pmp, dirclust, diroffset); error = vfs_hash_get(mntp, inode, lkflags, curthread, &nvp, de_vncmpf, &inode); +#ifdef MSDOSFS_DEBUG + printf("vfs_hash_get(inode %lu) error %d\n", inode, error); +#endif if (error) return (error); if (nvp != NULL) { @@ -191,6 +194,9 @@ badoff: } error = vfs_hash_insert(nvp, inode, lkflags, curthread, &xvp, de_vncmpf, &inode); +#ifdef MSDOSFS_DEBUG + printf("vfs_hash_insert(inode %lu) error %d\n", inode, error); +#endif if (error) { *depp = NULL; return (error); @@ -589,8 +595,11 @@ reinsert(struct denode *dep) return; #endif vp = DETOV(dep); - dep->de_inode = (uint64_t)dep->de_pmp->pm_bpcluster * dep->de_dirclust + - dep->de_diroffset; + dep->de_inode = DETOI(dep->de_pmp, dep->de_dirclust, dep->de_diroffset); +#ifdef MSDOSFS_DEBUG + printf("vfs_hash_rehash(inode %lu, refcnt %lu, vp %p)\n", + dep->de_inode, dep->de_refcnt, vp); +#endif vfs_hash_rehash(vp, dep->de_inode); } @@ -608,6 +617,10 @@ msdosfs_reclaim(struct vop_reclaim_args *ap) /* * Remove the denode from its hash chain. */ +#ifdef MSDOSFS_DEBUG + printf("vfs_hash_remove(inode %lu, refcnt %lu, vp %p)\n", + dep->de_inode, dep->de_refcnt, vp); +#endif vfs_hash_remove(vp); /* * Purge old data structures associated with the denode. diff --git a/sys/fs/msdosfs/msdosfs_lookup.c b/sys/fs/msdosfs/msdosfs_lookup.c index eb4cbaa21ab7..2a90339d0878 100644 --- a/sys/fs/msdosfs/msdosfs_lookup.c +++ b/sys/fs/msdosfs/msdosfs_lookup.c @@ -586,7 +586,7 @@ foundroot: } if (FAT32(pmp) && scn == MSDOSFSROOT) scn = pmp->pm_rootdirblk; - inode1 = scn * pmp->pm_bpcluster + blkoff; + inode1 = DETOI(pmp, scn, blkoff); if (VTODE(*vpp)->de_inode != inode1) { vput(*vpp); goto restart;