Skip to contentSkip to conversation

USB: Fix NULLPTR dereference when serial# is unset

PATCH In review Michael Ferolito 4 participants 6 messages Jan 28, 2025 USB

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 USB: Fix NULLPTR dereference when serial# is unset

The current behaviour of this function will dereference a null pointer if the serial# environment variable is unset. This was discovered on a board where U-Boot did not have access to the first 256MB of ram, resulting in a board crash.
In the event that U-Boot has full access to memory, it will still read from address 0, which is probably not optimal.
This simple check is enough to fix it

Cc Marek Vasut <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Kyungmin Park <[email protected]>
---
 drivers/usb/gadget/g_dnl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/gadget/g_dnl.c +2 -1
index 631969b340..f2540eb6de 100644
@@ -207,7 +207,8 @@ void g_dnl_clear_detach(void)
 static int on_serialno(const char *name, const char *value, enum env_op op,
 		int flags)
 {
-	g_dnl_set_serialnumber((char *)value);
+	if (value)
+		g_dnl_set_serialnumber((char *)value);
 	return 0;
 }
 U_BOOT_ENV_CALLBACK(serialno, on_serialno);
Signature · 1 line
2.48.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Michael Ferolito

The current behaviour of this function will dereference a null pointer if the serial# environment variable is unset. This was discovered on a board where U-Boot did not have access to the first 256MB of ram, resulting in a board crash.
In the event that U-Boot has full access to memory, it will still read from address 0, which is probably not optimal.
This simple check is enough to fix it

Quoted 4 lines
Cc Marek Vasut <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Kyungmin Park <[email protected]>

The subject tag is "usb: gadget: g_dnl:" instead of "USB:" , with that fixed:

Thanks

#2 lore raw

Hi Michael,

Thank you for the patch.

Quoted 9 lines · Marek Vasut
Quoted 8 lines · Michael Ferolito

The current behaviour of this function will dereference a null pointer if the serial# environment variable is unset. This was discovered on a board where U-Boot did not have access to the first 256MB of ram, resulting in a board crash.
In the event that U-Boot has full access to memory, it will still read from address 0, which is probably not optimal.
This simple check is enough to fix it

Quoted 8 lines
Quoted 4 lines
Cc Marek Vasut <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Kyungmin Park <[email protected]>

The subject tag is "usb: gadget: g_dnl:" instead of "USB:" , with that fixed:

Agreed with Marek on this. Please add:

As well.

Marek, since this is gadget, can this go through my tree?
In that case, Michael, I can fix up the subject when applying (to avoid you sending a v2)

Let me know if that works.

Thanks,
Mattijs

Quoted 2 lines

Thanks

#3 lore raw

Hello Mattijs,

Quoted 26 lines · Mattijs Korpershoek

Hi Michael,

Thank you for the patch.

Quoted 9 lines · Marek Vasut
Quoted 8 lines · Michael Ferolito

The current behaviour of this function will dereference a null pointer if the serial# environment variable is unset. This was discovered on a board where U-Boot did not have access to the first 256MB of ram, resulting in a board crash.
In the event that U-Boot has full access to memory, it will still read from address 0, which is probably not optimal.
This simple check is enough to fix it

Quoted 8 lines
Quoted 4 lines
Cc Marek Vasut <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Kyungmin Park <[email protected]>

The subject tag is "usb: gadget: g_dnl:" instead of "USB:" , with that fixed:

Agreed with Marek on this. Please add:

Quoted 7 lines

As well.

Marek, since this is gadget, can this go through my tree?
In that case, Michael, I can fix up the subject when applying (to avoid you sending a v2)

There is already a v4, see:

https://lists.denx.de/pipermail/u-boot/2025-January/578746.html

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]
#4 lore raw

Hi Heiko,

Quoted 33 lines · Heiko Schocher

Hello Mattijs,

Quoted 30 lines · Mattijs Korpershoek

Hi Michael,

Thank you for the patch.

Quoted 9 lines · Marek Vasut
Quoted 8 lines · Michael Ferolito

The current behaviour of this function will dereference a null pointer if the serial# environment variable is unset. This was discovered on a board where U-Boot did not have access to the first 256MB of ram, resulting in a board crash.
In the event that U-Boot has full access to memory, it will still read from address 0, which is probably not optimal.
This simple check is enough to fix it

Quoted 8 lines
Quoted 4 lines
Cc Marek Vasut <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Kyungmin Park <[email protected]>

The subject tag is "usb: gadget: g_dnl:" instead of "USB:" , with that fixed:

Agreed with Marek on this. Please add:

As well.

Quoted 7 lines
Quoted 3 lines

Marek, since this is gadget, can this go through my tree?
In that case, Michael, I can fix up the subject when applying (to avoid you sending a v2)

There is already a v4, see:

https://lists.denx.de/pipermail/u-boot/2025-January/578746.html

Indeed. Seems I'm a bit slow today :)

Thanks for sharing the link.

Quoted 7 lines

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]
#5 lore raw
In reply to Mattijs Korpershoek
Quoted 24 lines · Mattijs Korpershoek

Hi Michael,

Thank you for the patch.

Quoted 9 lines · Marek Vasut
Quoted 8 lines · Michael Ferolito

The current behaviour of this function will dereference a null pointer if the serial# environment variable is unset. This was discovered on a board where U-Boot did not have access to the first 256MB of ram, resulting in a board crash.
In the event that U-Boot has full access to memory, it will still read from address 0, which is probably not optimal.
This simple check is enough to fix it

Quoted 8 lines
Quoted 4 lines
Cc Marek Vasut <[email protected]>
Cc Heiko Schocher <[email protected]>
Cc Kyungmin Park <[email protected]>

The subject tag is "usb: gadget: g_dnl:" instead of "USB:" , with that fixed:

Quoted 7 lines

Agreed with Marek on this. Please add:

As well.

Marek, since this is gadget, can this go through my tree?

Yes of course.