From nobody Fri Dec 19 14:11:23 2025 Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32B9B2848AA; Mon, 13 Oct 2025 06:49:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.181.97.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760338149; cv=none; b=AK+oS/VOIWxO5zRe/Uqc9HIdFcSF2iM26319bhUzW4zbkyOXFdyw6P84TaRrqb07+qCH5YvSU3F4zoZRPUIEJf5/RRUaX2TioGzcLIc3lCHQVLGvw1QdqIAgDzbwRhT9LgzZaSMt0BXFMDsdABLjc8PIze7+cwNU1hhMIHb4sfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760338149; c=relaxed/simple; bh=Oj5AyQeF1q/G4g4eHS4beZKCTAHzZin6dWoYk0X06YA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=FLHzwlDd3xe4oJYp6Pw+rfb5XX7pSz+++JJ5sNaszXKnaA21lrrKf+aHf/Y3+tr/fYTtB5tamrwMUIAMzskWfZotVOI37V/o0RKs1UuBg+ApQMuqVYvOAgjdrage+PgajpSCW7Cg67OTJKTCqZV0+ribi3h5pijlhCVD3CVgoFU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=I-love.SAKURA.ne.jp; spf=pass smtp.mailfrom=I-love.SAKURA.ne.jp; arc=none smtp.client-ip=202.181.97.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=I-love.SAKURA.ne.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=I-love.SAKURA.ne.jp Received: from www262.sakura.ne.jp (localhost [127.0.0.1]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 59D5ixPE088993; Mon, 13 Oct 2025 14:44:59 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from [192.168.1.10] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 59D5ip8b088958 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Mon, 13 Oct 2025 14:44:59 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: <1007e06d-c2d1-4905-ab93-9d66ed7da505@I-love.SAKURA.ne.jp> Date: Mon, 13 Oct 2025 14:44:49 +0900 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH v2] bfs: Reconstruct file type when loading from disk To: Tigran Aivazian Cc: LKML , linux-fsdevel References: <340c759f-d102-4d46-b1f2-a797958a89e4@I-love.SAKURA.ne.jp> Content-Language: en-US From: Tetsuo Handa In-Reply-To: Content-Transfer-Encoding: quoted-printable X-Virus-Status: clean X-Anti-Virus-Server: fsav201.rs.sakura.ne.jp Content-Type: text/plain; charset="utf-8" syzbot is reporting that S_IFMT bits of inode->i_mode can become bogus when the S_IFMT bits of the 32bits "mode" field loaded from disk are corrupted or when the 32bits "attributes" field loaded from disk are corrupted. A documentation says that BFS uses only lower 9 bits of the "mode" field. But I can't find an explicit explanation that the unused upper 23 bits (especially, the S_IFMT bits) are initialized with 0. Therefore, ignore the S_IFMT bits of the "mode" field loaded from disk. Also, verify that the value of the "attributes" field loaded from disk is either BFS_VREG or BFS_VDIR (because BFS supports only regular files and the root directory). Reported-by: syzbot+895c23f6917da440ed0d@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D895c23f6917da440ed0d Signed-off-by: Tetsuo Handa Reviewed-by: Tigran Aivazian --- fs/bfs/inode.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/fs/bfs/inode.c b/fs/bfs/inode.c index 1d41ce477df5..984b365df046 100644 --- a/fs/bfs/inode.c +++ b/fs/bfs/inode.c @@ -61,7 +61,19 @@ struct inode *bfs_iget(struct super_block *sb, unsigned = long ino) off =3D (ino - BFS_ROOT_INO) % BFS_INODES_PER_BLOCK; di =3D (struct bfs_inode *)bh->b_data + off; =20 - inode->i_mode =3D 0x0000FFFF & le32_to_cpu(di->i_mode); + /* + * https://martin.hinner.info/fs/bfs/bfs-structure.html explains that + * BFS in SCO UnixWare environment used only lower 9 bits of di->i_mode + * value. This means that, although bfs_write_inode() saves whole + * inode->i_mode bits (which include S_IFMT bits and S_IS{UID,GID,VTX} + * bits), middle 7 bits of di->i_mode value can be garbage when these + * bits were not saved by bfs_write_inode(). + * Since we can't tell whether middle 7 bits are garbage, use only + * lower 12 bits (i.e. tolerate S_IS{UID,GID,VTX} bits possibly being + * garbage) and reconstruct S_IFMT bits for Linux environment from + * di->i_vtype value. + */ + inode->i_mode =3D 0x00000FFF & le32_to_cpu(di->i_mode); if (le32_to_cpu(di->i_vtype) =3D=3D BFS_VDIR) { inode->i_mode |=3D S_IFDIR; inode->i_op =3D &bfs_dir_inops; @@ -71,6 +83,11 @@ struct inode *bfs_iget(struct super_block *sb, unsigned = long ino) inode->i_op =3D &bfs_file_inops; inode->i_fop =3D &bfs_file_operations; inode->i_mapping->a_ops =3D &bfs_aops; + } else { + brelse(bh); + printf("Unknown vtype=3D%u %s:%08lx\n", + le32_to_cpu(di->i_vtype), inode->i_sb->s_id, ino); + goto error; } =20 BFS_I(inode)->i_sblock =3D le32_to_cpu(di->i_sblock); --=20 2.47.3