From nobody Sat Mar 18 06:16:50 2023 X-Original-To: dev-commits-src-main@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 4PdrPG4NPcz3y9WD; Sat, 18 Mar 2023 06:16: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 4PdrPG3Dshz3J49; Sat, 18 Mar 2023 06:16:50 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679120210; 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=KvnBmriykkQhc4RGbrj2K574e0gMPLt1tLXQnVFnqRI=; b=HmOT+ZTx4Q4DxDgHoD+bYldzSJ2vac9ITW2b9DRiLi0Z9NxQ45pZKfH77MrQqiauK2Ii9A NW4pRLCXTJpYiJYeujBxBRLuXPBQqvet6DGEykul1/rS7xHNg08bS5PkGv/ZVU1EvqvpQJ fKzWpLn4LYpkWkuFJw9J9+H1cSeZUqSOyyauzgNVCQHmE0+PzdYrsGXB98lXJIviF4WU2f G8dvBmY1hx2dPY16RtkqKmUektY6r3Q2cETIBym5YByATZcgsml5GKnxHUCyEumuEGlrL3 2vem9EQumdahzJxchrINm0oei82FOP4qCRmLf/OX9dPTQBH6M7B9OLDR6FXO3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679120210; 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=KvnBmriykkQhc4RGbrj2K574e0gMPLt1tLXQnVFnqRI=; b=mrgfVfbiGuoG6EKbgUkcg2EcyTrB05eECMJJNLbD83Bf1hpv9qYPAQ+AD4Xd0AYoJAPicr lKEqeM+P2Fx4sCfl1iK8gQY75Rq4SAjNfv69EjCl2JeVOi5rYp4gnWYYygg3bE4gJXxRhi zYSZc79wW/iRrjUF5UUQFFfsVCLcdLkD5lVNhT9olK2g40FUH7xNcFt4FWWfKYhlKZmH3F MxF6wvwS6fmFsoOZ7hPF+kPK91aFbike+6DGRyPbmWRqPw6fQHKIWtlnZrFnKTCwq3zXK8 ZegfX99sim9k9Opmh7TMllgLw69UZr7HbIKCv+rjhXgFgrGNutc/IytsJTpNMA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679120210; a=rsa-sha256; cv=none; b=DqrHaaX5anDJTrqD8BJylEFlWRvtyqcmAmmr+Oxz8aBVgO+xlW/gD2nP+c5rkRQWPikR0Z YMZE/gFJW2ICHJrKJI4ob46/b+uK3zARtOgI52focli4F9D6RN8gu7VbEoKDAY5uzGz2Eh iMLXjCWIuMRos9eIK5RNbv8PnNs2aUsxybBQ/6x0T3caoxvFaQebyjaeWXbxzw0eSWjsS6 FG4JhSyp9B1HfgqXbmWwBrNWwgs35t3NWI67rkGBFlZW3HKfW46BVxYJ4fqmRPHYi0QJCB ctFH4MTEiDYalslpsyzYWqruSDe2/SCeTUmpsgkA5XLJNm6UNVBDGWfS7IrxaQ== 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 4PdrPG2BxCzwHy; Sat, 18 Mar 2023 06:16:50 +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 32I6Go1I023072; Sat, 18 Mar 2023 06:16:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32I6GovC023071; Sat, 18 Mar 2023 06:16:50 GMT (envelope-from git) Date: Sat, 18 Mar 2023 06:16:50 GMT Message-Id: <202303180616.32I6GovC023071@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Fedor Uporov Subject: git: 366da717deda - main - Add root directory entry check. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: fsu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 366da717deda3964ae369f1f2fbd62114d14c587 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by fsu: URL: https://cgit.FreeBSD.org/src/commit/?id=366da717deda3964ae369f1f2fbd62114d14c587 commit 366da717deda3964ae369f1f2fbd62114d14c587 Author: Fedor Uporov AuthorDate: 2023-02-09 09:34:25 +0000 Commit: Fedor Uporov CommitDate: 2023-03-18 06:16:22 +0000 Add root directory entry check. Add check that directory entry with ino=EXT2_ROOTINO have correct namelength and name. It is possible to create malicious image which will cause panic if root directory entry have incorrect name. PR: 259068 Reported by: Robert Morris Reviewed by: pfg MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D38502 --- sys/fs/ext2fs/ext2_lookup.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sys/fs/ext2fs/ext2_lookup.c b/sys/fs/ext2fs/ext2_lookup.c index 67409a5e2a17..93a2d172e01f 100644 --- a/sys/fs/ext2fs/ext2_lookup.c +++ b/sys/fs/ext2fs/ext2_lookup.c @@ -818,6 +818,8 @@ ext2_dirbad(struct inode *ip, doff_t offset, char *how) * record must be large enough to contain entry * name is not longer than MAXNAMLEN * name must be as long as advertised, and null terminated + * inode number less then inode count + * if root inode entry, it have correct name */ static int ext2_check_direntry(struct vnode *dp, struct ext2fs_direct_2 *de, @@ -836,6 +838,11 @@ ext2_check_direntry(struct vnode *dp, struct ext2fs_direct_2 *de, error_msg = "directory entry across blocks"; else if (le32toh(de->e2d_ino) > fs->e2fs->e2fs_icount) error_msg = "directory entry inode out of bounds"; + else if (le32toh(de->e2d_ino) == EXT2_ROOTINO && + ((de->e2d_namlen != 1 && de->e2d_namlen != 2) || + (de->e2d_name[0] != '.') || + (de->e2d_namlen == 2 && de->e2d_name[1] != '.'))) + error_msg = "bad root directory entry"; if (error_msg != NULL) { SDT_PROBE5(ext2fs, , trace, ext2_dirbadentry_error,