From nobody Sat Jan 15 00:51:39 2022 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 DCDE91951424; Sat, 15 Jan 2022 00:51:41 +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 4JbKP81sfPz4kMV; Sat, 15 Jan 2022 00:51:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642207900; 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=Qhsy/dP/yaJC3F1Pgojbh3YUMQRUGVhWdhYKdBp605I=; b=sOFYXXIZUxqaqypIzeezgskiFeSwS1gC0X7on6dPw/HeZw1FwCH9kHW1Xf1S//6xI/byRO hJ6OVLdNDEg/W3wSaJ9iJ/Xm5SryVcyj1oZGm+7IW8ThHIY4cooK47yYHtLNZU2qQmEPfb j2qxCuzlbSWKes7qg1vjHrjNJF9aZEi1sHeTtnbXY3LBiMll22mh9hlYa8N9HIvLSVoQ40 Lt6GWbscV0NQw+PmMx+idOjWKMiOaVQIOeV4kQlaq0hcgsrfkZvZ8grY7xUq9iM6JyRp54 kjJCJbjIbiAgldmFtIEmnjI6XsEvPUMvYWxvW1l7wpNzbojxK6KdsOSM4QhjEQ== 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 06F891DCB3; Sat, 15 Jan 2022 00:51:40 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20F0pdaD031176; Sat, 15 Jan 2022 00:51:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20F0pdI3031175; Sat, 15 Jan 2022 00:51:39 GMT (envelope-from git) Date: Sat, 15 Jan 2022 00:51:39 GMT Message-Id: <202201150051.20F0pdI3031175@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 95a83a5fffd4 - stable/13 - msdosfs: do no allow lookup to return vdp except for dot lookups 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: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 95a83a5fffd4722b105b33067682157601e821d2 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642207900; 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=Qhsy/dP/yaJC3F1Pgojbh3YUMQRUGVhWdhYKdBp605I=; b=HrTfwk/jTqjsnUIRRp5RjGwdEeHQ8NNv3yEaeOG6+hczADQvY8Ks9OryAaQ2SX5KXOLaAW V8O8gYl3aLK4+/WaW0WHEn2CVeJ0x56Uujpo5EzmxJvuyBI2AW7/1fqWBChh/Jzi2SKXs6 DEeIbrr43zyQx4RGtjY5M/h9E8d6CPOuYbabN0s/61tVOmIAn2Xu1SLWfWH7HkhCfMygp7 7GbQX3Rr7u666Ognl44DPm8ivzuEut3bs5tk2EYbFHuhGJoi86cJx+JTyIA5LSbvzfFN8G MRKfbWJdHP1gSwsEv27TmeHBzbRcurW52vjiwto2K1E3MBZF3Ro4wx4uh52AQg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642207900; a=rsa-sha256; cv=none; b=KaOsG1J6qyWTuMj2MyXjX02DwOOvL4WGhM23j8GSIqMfR60ar3ns98YwEDgwUlwjXrbFOw Y8hoBLVYu4oxsrX/nhefwWEhuZPk2DJHh9cVpQsZyi33E1Db2aUIZcavdRKJwxIaVHHs1R azvb+AVoHqmpbsTv64aAAEctCSIej9nmzfLIh5wTdy9NM4HghQgnznX63+n/jpLkj4tMS/ 6jYfIHoE+SDqtC7V2TX+OtumPcYrY1InwkBjPlAzVFrVVpdCBq04YLT5Ck0wmJV49oSoUu FBdCfd1d+9yYKqyIfI4ekXRO6KwRJFmYQozvz8wbSSBuRbG4luSdSkbbMP/Ajg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=95a83a5fffd4722b105b33067682157601e821d2 commit 95a83a5fffd4722b105b33067682157601e821d2 Author: Konstantin Belousov AuthorDate: 2021-12-26 21:51:48 +0000 Commit: Konstantin Belousov CommitDate: 2022-01-14 18:11:02 +0000 msdosfs: do no allow lookup to return vdp except for dot lookups (cherry picked from commit aec97963cd03f10e04083537ed449a84a5e42f87) --- sys/fs/msdosfs/msdosfs_lookup.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/sys/fs/msdosfs/msdosfs_lookup.c b/sys/fs/msdosfs/msdosfs_lookup.c index 2478cab84a0a..e30866b5bedd 100644 --- a/sys/fs/msdosfs/msdosfs_lookup.c +++ b/sys/fs/msdosfs/msdosfs_lookup.c @@ -63,6 +63,28 @@ #include #include +static int +msdosfs_lookup_checker(struct msdosfsmount *pmp, struct vnode *dvp, + struct denode *tdp, struct vnode **vpp) +{ + struct vnode *vp; + + vp = DETOV(tdp); + + /* + * Lookup assumes that directory cannot be hardlinked. + * Corrupted msdosfs filesystem could break this assumption. + */ + if (vp == dvp) { + vput(vp); + *vpp = NULL; + return (EBADF); + } + + *vpp = vp; + return (0); +} + int msdosfs_lookup(struct vop_cachedlookup_args *ap) { @@ -501,8 +523,7 @@ foundroot: error = deget(pmp, cluster, blkoff, LK_EXCLUSIVE, &tdp); if (error) return (error); - *vpp = DETOV(tdp); - return (0); + return (msdosfs_lookup_checker(pmp, vdp, tdp, vpp)); } /* @@ -529,7 +550,9 @@ foundroot: if ((error = deget(pmp, cluster, blkoff, LK_EXCLUSIVE, &tdp)) != 0) return (error); - *vpp = DETOV(tdp); + if ((error = msdosfs_lookup_checker(pmp, vdp, tdp, vpp)) + != 0) + return (error); cnp->cn_flags |= SAVENAME; return (0); } @@ -572,6 +595,7 @@ foundroot: vput(*vpp); goto restart; } + return (msdosfs_lookup_checker(pmp, vdp, VTODE(*vpp), vpp)); } else if (dp->de_StartCluster == scn && isadir) { if (cnp->cn_namelen != 1 || cnp->cn_nameptr[0] != '.') { /* fs is corrupted, non-dot lookup returned dvp */ @@ -583,7 +607,8 @@ foundroot: if ((error = deget(pmp, cluster, blkoff, LK_EXCLUSIVE, &tdp)) != 0) return (error); - *vpp = DETOV(tdp); + if ((error = msdosfs_lookup_checker(pmp, vdp, tdp, vpp)) != 0) + return (error); } /*