udf: Fix undefined behavior bug in struct udf_fileident_iter
PATCH 1/1 udf: Fix undefined behavior bug in struct udf_fileident_iter
struct fileIdentDesc is a flexible structure, which means that it contains a flexible-array member at the bottom. This could potentially lead to an overwrite of the objects following fi in struct udf_fileident_iter at run-time.
Fix this by placing the declaration of object fi at the end of struct udf_fileident_iter.
-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting ready to enable it globally.
--- fs/udf/udfdecl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/udf/udfdecl.h +1 -1
@@ -93,11 +93,11 @@ struct udf_fileident_iter {sector_t loffset;/* Block offset of 'pos' within above * extent */ struct extent_position epos;/* Position after the above extent */ -struct fileIdentDesc fi;/* Copied directory entry */ uint8_t *name;/* Pointer to entry name */ uint8_t *namebuf;/* Storage for entry name in case * the name is split between two blocks */ +struct fileIdentDesc fi;/* Copied directory entry */ };struct udf_vds_record {
Signature · 1 line
2.34.1
Quoted 8 lines · Gustavo A. R. Silva
struct fileIdentDescis a flexible structure, which means that it contains a flexible-array member at the bottom. This could potentially lead to an overwrite of the objects followingfiinstruct udf_fileident_iterat run-time.Fix this by placing the declaration of object
fiat the end ofstruct udf_fileident_iter.
Quoted 6 lines
-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting ready to enable it globally.
Fixes d16076d9b684 ("udf: New directory iteration code")Signed-off-by Gustavo A. R. Silva <[email protected]>
Looks right.
Signature · 1 line
Kees Cook
Quoted 8 lines · Gustavo A. R. Silva
struct fileIdentDescis a flexible structure, which means that it contains a flexible-array member at the bottom. This could potentially lead to an overwrite of the objects followingfiinstruct udf_fileident_iterat run-time.Fix this by placing the declaration of object
fiat the end ofstruct udf_fileident_iter.
Quoted 6 lines
-Wflex-array-member-not-at-end is coming in GCC-14, and we are getting ready to enable it globally.
Fixes d16076d9b684 ("udf: New directory iteration code")Signed-off-by Gustavo A. R. Silva <[email protected]>
Thanks for the patch! This is in fact harmless since we never use the impUse field. But I agree it is confusing so I'll merge attached fix instead.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
From 7b530e7ad261dc6111874f2225c2f38f63d12ebf Mon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Tue, 3 Oct 2023 11:19:02 +0200
Subject: [PATCH] udf: Avoid unneeded variable length array in struct
fileIdentDesc
impUse variable length array in struct fileIdentDesc is never used. It serves only for documentation purposes of the on-disk format. Remove it from the struct so that it doesn't confuse the compiler and reviewers.
--- fs/udf/ecma_167.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/udf/ecma_167.h +1 -1
@@ -471,7 +471,7 @@ struct fileIdentDesc {uint8_t lengthFileIdent;struct long_ad icb;__le16 lengthOfImpUse; -uint8_t impUse[]; +/* uint8_t impUse[]; */ /* uint8_t fileIdent[]; */ /* uint8_t padding[]; */ } __packed;
Signature · 1 line
2.35.3