Skip to contentSkip to conversation

xen/ubsan: Fix UB in type_descriptor declaration

PATCH In review Andrew Cooper 3 participants 4 messages Jun 17, 2024 – Jun 18, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/ubsan: Fix UB in type_descriptor declaration

struct type_descriptor is arranged with a NUL terminated string following the kind/info fields.

The only reason this doesn't trip UBSAN detection itself (on more modern compilers at least) is because struct type_descriptor is only referenced in suppressed regions.

Switch the declaration to be a real flexible member. No functional change.

Fixes 00fcf4dd8eb4 ("xen/ubsan: Import ubsan implementation from Linux 4.13")

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Oleksii Kurochko <[email protected]>

For 4.19, and for backport to all reasonable versions. This bug deserves some kind of irony award.

---
 xen/common/ubsan/ubsan.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/ubsan/ubsan.h +1 -1
index a3159040fefb..3db42e75b138 100644
@@ -10,7 +10,7 @@ enum {
 struct type_descriptor {
 	u16 type_kind;
 	u16 type_info;
-	char type_name[1];
+	char type_name[];
 };
 
 struct source_location {

base-commit: 8b4243a9b560c89bb259db5a27832c253d4bebc7

Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Andrew Cooper

struct type_descriptor is arranged with a NUL terminated string following the kind/info fields.

The only reason this doesn't trip UBSAN detection itself (on more modern compilers at least) is because struct type_descriptor is only referenced in suppressed regions.

Switch the declaration to be a real flexible member. No functional change.

Fixes 00fcf4dd8eb4 ("xen/ubsan: Import ubsan implementation from Linux 4.13")
#2 lore raw
In reply to Andrew Cooper
Quoted 1 line · Andrew Cooper

struct type_descriptor is arranged with a NUL terminated string

Should it be NULL instead of NUL?

Quoted 9 lines

following the
kind/info fields.

The only reason this doesn't trip UBSAN detection itself (on more modern
compilers at least) is because struct type_descriptor is only referenced in
suppressed regions.

Quoted 6 lines

Switch the declaration to be a real flexible member.  No functional change.

Fixes 00fcf4dd8eb4 ("xen/ubsan: Import ubsan implementation from

Linux 4.13")

~ Oleksii

Quoted 29 lines

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Oleksii Kurochko <[email protected]>

For 4.19, and for backport to all reasonable versions.  This bug deserves some
kind of irony award.
---
 xen/common/ubsan/ubsan.h | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/ubsan/ubsan.h +1 -1
index a3159040fefb..3db42e75b138 100644
@@ -10,7 +10,7 @@ enum {
  struct type_descriptor {
  	u16 type_kind;
  	u16 type_info;
-	char type_name[1];
+	char type_name[];
  };


 struct source_location {

base-commit: 8b4243a9b560c89bb259db5a27832c253d4bebc7

#3 lore raw
Quoted 3 lines · Oleksii K.
Quoted 1 line · Andrew Cooper

struct type_descriptor is arranged with a NUL terminated string

Should it be NULL instead of NUL?

NULL and NUL can be used interchangeably; they're different spellings for the same thing.

In the ASCII spec, the character with value 0 is spelt NUL.

Quoted 10 lines
Quoted 10 lines

following the
kind/info fields.

The only reason this doesn't trip UBSAN detection itself (on more modern
compilers at least) is because struct type_descriptor is only referenced in
suppressed regions.

Quoted 7 lines
Quoted 6 lines

Switch the declaration to be a real flexible member.  No functional change.

Fixes 00fcf4dd8eb4 ("xen/ubsan: Import ubsan implementation from

Linux 4.13")

Thanks.

~Andrew