Skip to contentSkip to conversation

ALSA: 6fire: Fix undefined behavior bug in struct midi_runtime

PATCH In review Gustavo A. R. Silva 4 participants 4 messages Sep 29, 2023 – Oct 6, 2023 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: 6fire: Fix undefined behavior bug in struct midi_runtime

struct urb 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 out_urb in struct midi_runtime, among them a function pointer.

Fix this by placing the declaration of object out_urb at the end of struct midi_runtime.

Fixes c6d43ba816d1 ("ALSA: usb/6fire - Driver for TerraTec DMX 6Fire USB")
---
 sound/usb/6fire/midi.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/usb/6fire/midi.h +1 -1
index 47640c845903..df3f41913274 100644
@@ -22,12 +22,12 @@ struct midi_runtime {
 	spinlock_t in_lock;
 	spinlock_t out_lock;
 	struct snd_rawmidi_substream *out;
-	struct urb out_urb;
 	u8 out_serial; /* serial number of out packet */
 	u8 *out_buffer;
 	int buffer_offset;
 
 	void (*in_received)(struct midi_runtime *rt, u8 *data, int length);
+	struct urb out_urb;
 };
 
 int usb6fire_midi_init(struct sfire_chip *chip);
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Gustavo A. R. Silva

struct urb 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 out_urb in struct midi_runtime, among them a function pointer.

Fix this by placing the declaration of object out_urb at the end of struct midi_runtime.

Fixes c6d43ba816d1 ("ALSA: usb/6fire - Driver for TerraTec DMX 6Fire USB")

Another good find. :)

Signature · 1 line
Kees Cook
#2 lore raw
Quoted 6 lines · Kees Cook
Quoted 5 lines · Gustavo A. R. Silva

struct urb 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 out_urb in struct midi_runtime, among them a function pointer.

Quoted 8 lines
Quoted 6 lines

Fix this by placing the declaration of object out_urb at the end of struct midi_runtime.

Fixes c6d43ba816d1 ("ALSA: usb/6fire - Driver for TerraTec DMX 6Fire USB")

Another good find. :)

There are more coming. :)

Quoted 3 lines

Thanks!
--
Gustavo

#3 lore raw
In reply to Gustavo A. R. Silva
Quoted 6 lines · Gustavo A. R. Silva

struct urb 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 out_urb in struct midi_runtime, among them a function pointer.

Quoted 6 lines

Fix this by placing the declaration of object out_urb at the end of struct midi_runtime.

Fixes c6d43ba816d1 ("ALSA: usb/6fire - Driver for TerraTec DMX 6Fire USB")

The same question as your another 6fire patch is applied here: does it "fix" anything real?

thanks,

Takashi

Quoted 25 lines
---
 sound/usb/6fire/midi.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/usb/6fire/midi.h +1 -1
index 47640c845903..df3f41913274 100644
@@ -22,12 +22,12 @@ struct midi_runtime {
 	spinlock_t in_lock;
 	spinlock_t out_lock;
 	struct snd_rawmidi_substream *out;
-	struct urb out_urb;
 	u8 out_serial; /* serial number of out packet */
 	u8 *out_buffer;
 	int buffer_offset;
 
 	void (*in_received)(struct midi_runtime *rt, u8 *data, int length);
+	struct urb out_urb;
 };
 
 int usb6fire_midi_init(struct sfire_chip *chip);
Signature · 1 line
2.34.1