From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796135760; b=4GR5WbcCkyxSNU6eN1yF9P5OU1iEcRQJ6rI551VBcJow7zJW4HVQ/QjbdMtgd/1hucsP qdjqZnCdXDmXdK+/YjaICJPy2TrICPE//QBMIcCX41M8L7d7LXxr2C97O0akZziAImoz/ XrPJK0M1TUxmAESVqCb3BfSXdAq064/zyuK+5vGlldP6VYLLgMO1YbdRDae1llF2/T9a3 CQCxtT9bUhylzpVY6Q0d1lZUc0opyLlcRXeK0wl04XNhlrc76WxSD9ao9ccbeLsMAtIBP fWSjjaukxrVlDvHcn4cB9iMTij8L/eduPlhPiTD882hY46SE/uz0CYt5dLfXVeW3Iqw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796135760; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=/Kx+6dmaZrzHU5kjOHdG/+zaR25eXFS9nUVzf3DEGl0=; b=tS6LPk4nOdSP5q+g0KOPYII+FjFQC4B0BnDK3WJOwq3fFnGUXcQzLDTD4xXRxs5YFD+R U8XwicHuq0Bjnx6VMp0KRrAMzZGtBn7nBzsT2mA6uww5IKqhRw5NDTSZ41b1RJpb00s50 ONyelRd1CzDqbmY+qzryoQwns1n2B6vlLqIZG9KOYM/8eCzNHHiDqcIXBJblvPbjll/ts /kTthsl7WOtBx0A/CAKtvm0JysXW4qnTh/78sDiuTF1nxTY4P/zFYh6LC8ms/1WW0iXvm alZpczx64rUGtiW6OluQxoTuSJBEWF8rofBSlZkRTAwOhfFC5dDi7O8/iPtMhFzST1A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YLAGnEVE; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BFC1606A31A for ; Tue, 1 Dec 2026 14:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YLAGnEVE Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19B811F00898; Tue, 1 Dec 2026 14:35:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796135759; bh=/Kx+6dmaZrzHU5kjOHdG/+zaR25eXFS9nUVzf3DEGl0=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=YLAGnEVEbL55dkwq+scOVQ4sKaAtZIX8bWyK8qlF8ZGiFEmcJQXc+HT4vRu4N2EEb WQ5RIfEheixfGCCO6q3mW3gDvgI5xOILHvc95VPKVNjDWZHUnfpkgqxj+2B7a1i2PA HFyyKEJkPqDNl34/kjZB81G8C3IG6p+URRT8YUW7QyXEArD+5KN/L4JwSpU5msSU5z D+bvUwwsCvggnb+Ne1aUJAclFALHmxACz9IQkAoedBeHEswJV+P27IPG/eVBnCLQy9 olSdGMchRielctV/6Ao0hb3XpksBqkeQMryfchKSVfUC1oBF0EM0kc3K+Zjkf6EvG6 Rx0MrcWboxLPw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] ext2: validate directory entries before rename Reply-To: sashiko-reviews@lists.linux.dev To: "Shawn Shao" Cc: linux-ext4@vger.kernel.org, tytso@mit.edu In-Reply-To: <179613469562.187341.6558824516172704292.1796134695.4-1-shawnq1@163.com> References: <20261128045214.2649994-1-shawnq1@163.com> <4bwzyxnv3vfqbbkdrdx4bz3u2fahssmxnjvfh6t2jwc25zvd7n@utyjr2gpy7fd> <179613469562.187341.6558824516172704292.1796134695.4-1-shawnq1@163.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 14:35:58 +0000 X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] ext2: lax dot_len check in ext2_check_folio() lets ext2_add_link() split '.' - [Low] ext2: commit message formatted as email reply without problem description -- commit 9941f46a8139b486ee5aa49e86c4ccf959cce7a4 Author: Shawn Shao > ext2: validate directory entries before rename > > Hello Jan, > > Thanks for the suggestion. I moved validation of the `.` and `..` records > to `ext2_check_folio()` for the first directory folio, after the existing > record-boundary checks. `ext2_get_folio()` runs this validation before a > caller can use a directory-entry pointer. The `..` inode comparison stays > in `ext2_rename()`, where `old_dir` is available. > > The malformed image still makes cross-directory rename return `-EIO`; the > valid-image rename control succeeds. I also rebuilt the full x86-64 kernel > and ran both cases in QEMU. > > Tested on Linux 7.4-rc4, commit > 7cd8495c0f16275c4f9abe1cef09a7b5fcd6d046, tree > 194227446ae61b4971eea1b7bed06856fe3cc477, with gcc 11.4.0 and QEMU 6.2.0. > The reproducer, image builder, kernel configuration, and updated console > logs are collected here: > https://gist.github.com/shaos26/afcee45e1ee5b8da6bbfdb8b642093a8 > > Changes in v2: > - Validate the first two directory entries in `ext2_check_folio()`. > - Keep the expected-parent check in `ext2_rename()`. > > Thanks, > Shawn Shao > > Signed-off-by: Shawn Shao [Severity: Low] The commit message is formatted as an email reply with v2 changelog notes rather than a standalone description of the bug being fixed. Conversational notes and version history belong below the --- separator, while the commit log should explain why missing or invalid "." and ".." entries cause a problem in ext2_dotdot() and ext2_rename(). > diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c > index 5de32c221a83b..10f33a2de0acc 100644 > --- a/fs/ext2/dir.c > +++ b/fs/ext2/dir.c > @@ -112,9 +112,11 @@ static bool ext2_check_folio(struct folio *folio, in= t quiet, char *kaddr) > limit =3D offset_in_folio(folio, dir->i_size); > if (limit & (chunk_size - 1)) > goto Ebadsize; > - if (!limit) > + if (!limit && folio_pos(folio)) > goto out; > } > + if (!limit) > + goto bad_dot; > for (offs =3D 0; offs <=3D limit - EXT2_DIR_REC_LEN(1); offs +=3D rec_l= en) { > p =3D (ext2_dirent *)(kaddr + offs); > rec_len =3D ext2_rec_len_from_disk(p->rec_len); > @@ -132,6 +134,24 @@ static bool ext2_check_folio(struct folio *folio, in= t quiet, char *kaddr) > } > if (offs !=3D limit) > goto Eend; > + if (!folio_pos(folio)) { > + unsigned int dot_len, dotdot_len; > + > + p =3D (ext2_dirent *)kaddr; > + dot_len =3D ext2_rec_len_from_disk(p->rec_len); > + if (p->name_len !=3D 1 || p->name[0] !=3D '.' || > + le32_to_cpu(p->inode) !=3D dir->i_ino || > + dot_len > chunk_size - EXT2_DIR_REC_LEN(2)) > + goto bad_dot; [Severity: Medium] Should dot_len be required to equal EXT2_DIR_REC_LEN(1) instead of only checking dot_len > chunk_size - EXT2_DIR_REC_LEN(2)? If a crafted image has "." at offset 0 with dot_len >=3D 24 and ".." at kaddr + dot_len, ext2_check_folio() marks the folio checked. When a new entry is later added to that directory, ext2_add_link() starts scanning at offset 0, sees rec_len >=3D name_len + reclen on ".", and splits "." to ins= ert the new entry at offset 12 ahead of "..". After that, ext2_dotdot() returns the new entry instead of "..", causing a later cross-directory ext2_rename() or folio re-read to trigger ext2_error(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/179613469562.187341= .6558824516172704292.1796134695.4-1-shawnq1@163.com?part=3D1