From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 497514AA58F for ; Fri, 11 Sep 2026 19:32:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789155157; cv=none; b=gbHrOi7qo7rnZlk6XDBbmz4S5UM4lyS2e8MaZEk8rtc7W/YWMV3YuxkJxGaSHfZWO2TUckxHQC+SSNMQplR4+B+3fozoxAsoJH7D0caW9xeA2iE6zH8k/nqnOn/1nWI5hBWVdyKfSV9YX5mgQyDzZaoQX2uDu09XmBGGJBVK3JQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789155157; c=relaxed/simple; bh=Dsnk99H6VfYkVhMKbuQRkehU1Hy+QQOTqdma3yUcgzM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qggt52dVUAsaFjtsp08BjgghOcb5LrYoIztFDK6GG1abCfBVZ/uNywgy1nJkjptRq9CyEn3o5ZX0F6Vpg25gZKM20mvYShn67twH6QqbEq6DotziBHe8ori4f2deroXeRIJ5K9pCmtD1D4s7JA8SR6nsJVKVgoNRdM0mSHkVzZ8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UQyFR9oQ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UQyFR9oQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4735B1F00893; Fri, 11 Sep 2026 19:32:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789155154; bh=fSzgH2vt/o3z/ihRjab0i5gD/qLmKQNR+BndDFgJERA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UQyFR9oQnSZ4y+NzQJEwCqzzXC9kUNFEuuno16s5VvN6OV2aqEcec4+ioEj/QND+P qoPwtYmOL8bSYOh8Qw3jPC5nko0shTIOJWsJfwORxyIwaJG4Tou2MUHi+kkjRrcZgi loB5pm3aqMkjRyk06PyWYhk4eLGgaHSEQP1bq0s7HG2AJ4JkRTyq+f5A2cUWNh6my5 bxNtvVTx4b7DZxPRoto8Kk7SRh8IsnUB2/y67aLn/Y8LHQzwrnm0RxdxTaZFnH/aCR xzrou9MESni0EHOvusVvXzb4b/2/IeY/+PFz2IDHH6feY9XBR7VizTecQne6J0HYcL 5v2zj8S06rVKw== From: Sasha Levin To: stable@vger.kernel.org Cc: Wenjie Qi , stable@kernel.org, Wenjie Qi , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 6.18.y] f2fs: limit recovery filename logging to stored length Date: Fri, 11 Sep 2026 15:32:31 -0400 Message-ID: <20260911193231.1414208-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026090931-derby-unsaid-8e7f@gregkh> References: <2026090931-derby-unsaid-8e7f@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Wenjie Qi [ Upstream commit 01027b2fcb74dade59fb833b51023f6593b6a9a2 ] F2FS stores recovery filenames as a length plus a fixed-size i_name buffer. The buffer is not NUL-terminated, but recover_inode() and recover_dentry() print it with %s. For a 255-byte filename, recovery logging can read past i_name into the following raw inode fields. Print the name with a precision bounded by i_namelen and F2FS_NAME_LEN. Fixes: f356fe0cba0e ("f2fs: add debug msgs in the recovery routine") Cc: stable@kernel.org Assisted-by: Codex:gpt-5.5 Signed-off-by: Wenjie Qi Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim [ Retained %lx instead of %llu for the branch’s unsigned long directory inode numbers. ] Signed-off-by: Sasha Levin --- fs/f2fs/recovery.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c index 06674e694b271..e954e356c8089 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c @@ -169,7 +169,8 @@ static int recover_dentry(struct inode *inode, struct folio *ifolio, struct inode *dir, *einode; struct fsync_inode_entry *entry; int err = 0; - char *name; + const char *name; + int name_len; entry = get_fsync_inode(dir_list, pino); if (!entry) { @@ -228,12 +229,16 @@ static int recover_dentry(struct inode *inode, struct folio *ifolio, out_put: f2fs_folio_put(folio, false); out: - if (file_enc_name(inode)) + if (file_enc_name(inode)) { name = ""; - else + name_len = sizeof("") - 1; + } else { name = raw_inode->i_name; - f2fs_notice(F2FS_I_SB(inode), "%s: ino = %x, name = %s, dir = %lx, err = %d", - __func__, ino_of_node(ifolio), name, + name_len = min_t(unsigned int, le32_to_cpu(raw_inode->i_namelen), + F2FS_NAME_LEN); + } + f2fs_notice(F2FS_I_SB(inode), "%s: ino = %x, name = %.*s, dir = %lx, err = %d", + __func__, ino_of_node(ifolio), name_len, name, IS_ERR(dir) ? 0 : dir->i_ino, err); return err; } @@ -281,7 +286,8 @@ static int recover_inode(struct inode *inode, struct folio *folio) { struct f2fs_inode *raw = F2FS_INODE(folio); struct f2fs_inode_info *fi = F2FS_I(inode); - char *name; + const char *name; + int name_len; int err; inode->i_mode = le16_to_cpu(raw->i_mode); @@ -330,13 +336,18 @@ static int recover_inode(struct inode *inode, struct folio *folio) f2fs_mark_inode_dirty_sync(inode, true); - if (file_enc_name(inode)) + if (file_enc_name(inode)) { name = ""; - else - name = F2FS_INODE(folio)->i_name; + name_len = sizeof("") - 1; + } else { + name = raw->i_name; + name_len = min_t(unsigned int, le32_to_cpu(raw->i_namelen), + F2FS_NAME_LEN); + } - f2fs_notice(F2FS_I_SB(inode), "recover_inode: ino = %x, name = %s, inline = %x", - ino_of_node(folio), name, raw->i_inline); + f2fs_notice(F2FS_I_SB(inode), "%s: ino = %x, name = %.*s, inline = %x", + __func__, ino_of_node(folio), name_len, name, + raw->i_inline); return 0; } -- 2.53.0