LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH][next] udf: Fix undefined behavior bug in struct udf_fileident_iter
@ 2023-10-02 16:14 Gustavo A. R. Silva
  2023-10-02 17:38 ` Kees Cook
  2023-10-03  9:26 ` Jan Kara
  0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2023-10-02 16:14 UTC (permalink / raw
  To: Jan Kara; +Cc: linux-kernel, Gustavo A. R. Silva, linux-hardening

`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.

Fixes: d16076d9b684 ("udf: New directory iteration code")
Cc: stable@vger.kernel.org
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
 fs/udf/udfdecl.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h
index 88692512a466..736f591abc89 100644
--- a/fs/udf/udfdecl.h
+++ b/fs/udf/udfdecl.h
@@ -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 {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] udf: Fix undefined behavior bug in struct udf_fileident_iter
  2023-10-02 16:14 [PATCH][next] udf: Fix undefined behavior bug in struct udf_fileident_iter Gustavo A. R. Silva
@ 2023-10-02 17:38 ` Kees Cook
  2023-10-03  9:26 ` Jan Kara
  1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2023-10-02 17:38 UTC (permalink / raw
  To: Gustavo A. R. Silva; +Cc: Jan Kara, linux-kernel, linux-hardening

On Mon, Oct 02, 2023 at 06:14:26PM +0200, Gustavo A. R. Silva wrote:
> `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.
> 
> Fixes: d16076d9b684 ("udf: New directory iteration code")
> Cc: stable@vger.kernel.org
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Looks right.

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH][next] udf: Fix undefined behavior bug in struct udf_fileident_iter
  2023-10-02 16:14 [PATCH][next] udf: Fix undefined behavior bug in struct udf_fileident_iter Gustavo A. R. Silva
  2023-10-02 17:38 ` Kees Cook
@ 2023-10-03  9:26 ` Jan Kara
  1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2023-10-03  9:26 UTC (permalink / raw
  To: Gustavo A. R. Silva; +Cc: Jan Kara, linux-kernel, linux-hardening

[-- Attachment #1: Type: text/plain, Size: 863 bytes --]

On Mon 02-10-23 18:14:26, Gustavo A. R. Silva wrote:
> `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.
> 
> Fixes: d16076d9b684 ("udf: New directory iteration code")
> Cc: stable@vger.kernel.org
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

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
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

[-- Attachment #2: 0001-udf-Avoid-unneeded-variable-length-array-in-struct-f.patch --]
[-- Type: text/x-patch, Size: 1000 bytes --]

From 7b530e7ad261dc6111874f2225c2f38f63d12ebf Mon Sep 17 00:00:00 2001
From: Jan Kara <jack@suse.cz>
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.

Reported-by: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/udf/ecma_167.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/udf/ecma_167.h b/fs/udf/ecma_167.h
index de17a97e8667..415b050b977d 100644
--- a/fs/udf/ecma_167.h
+++ b/fs/udf/ecma_167.h
@@ -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;
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-03  9:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-02 16:14 [PATCH][next] udf: Fix undefined behavior bug in struct udf_fileident_iter Gustavo A. R. Silva
2023-10-02 17:38 ` Kees Cook
2023-10-03  9:26 ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).