* [PATCH v1 1/3] f_rockusb: Use NULL instead of 0 for pointers
@ 2020-12-03 15:32 Andy Shevchenko
2020-12-03 15:32 ` [PATCH v1 2/3] f_rockusb: Avoid use-after-free in the global pointer variable Andy Shevchenko
2020-12-03 15:32 ` [PATCH v1 3/3] f_fastboot: " Andy Shevchenko
0 siblings, 2 replies; 3+ messages in thread
From: Andy Shevchenko @ 2020-12-03 15:32 UTC (permalink / raw)
To: u-boot
get_rkusb() mistakenly uses integers without cast.
Convert them to proper type.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/usb/gadget/f_rockusb.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/gadget/f_rockusb.c b/drivers/usb/gadget/f_rockusb.c
index 9ae02ae78c1e..9dd10f9e9aa1 100644
--- a/drivers/usb/gadget/f_rockusb.c
+++ b/drivers/usb/gadget/f_rockusb.c
@@ -110,7 +110,7 @@ struct f_rockusb *get_rkusb(void)
if (!f_rkusb) {
f_rkusb = memalign(CONFIG_SYS_CACHELINE_SIZE, sizeof(*f_rkusb));
if (!f_rkusb)
- return 0;
+ return NULL;
rockusb_func = f_rkusb;
memset(f_rkusb, 0, sizeof(*f_rkusb));
@@ -120,7 +120,7 @@ struct f_rockusb *get_rkusb(void)
f_rkusb->buf_head = memalign(CONFIG_SYS_CACHELINE_SIZE,
RKUSB_BUF_SIZE);
if (!f_rkusb->buf_head)
- return 0;
+ return NULL;
f_rkusb->buf = f_rkusb->buf_head;
memset(f_rkusb->buf_head, 0, RKUSB_BUF_SIZE);
--
2.29.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v1 2/3] f_rockusb: Avoid use-after-free in the global pointer variable
2020-12-03 15:32 [PATCH v1 1/3] f_rockusb: Use NULL instead of 0 for pointers Andy Shevchenko
@ 2020-12-03 15:32 ` Andy Shevchenko
2020-12-03 15:32 ` [PATCH v1 3/3] f_fastboot: " Andy Shevchenko
1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2020-12-03 15:32 UTC (permalink / raw)
To: u-boot
In case of usb_add_function() failure the error path has two issues:
- the potentially allocated structure isn't getting freed
- the global pointer variable is assigned to garbage
Fix the above mentioned issues by freeing memory and assigning NULL.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/usb/gadget/f_rockusb.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/f_rockusb.c b/drivers/usb/gadget/f_rockusb.c
index 9dd10f9e9aa1..bd846ce9a77b 100644
--- a/drivers/usb/gadget/f_rockusb.c
+++ b/drivers/usb/gadget/f_rockusb.c
@@ -309,8 +309,9 @@ static int rockusb_add(struct usb_configuration *c)
status = usb_add_function(c, &f_rkusb->usb_function);
if (status) {
+ free(f_rkusb->buf_head);
free(f_rkusb);
- rockusb_func = f_rkusb;
+ rockusb_func = NULL;
}
return status;
}
--
2.29.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v1 3/3] f_fastboot: Avoid use-after-free in the global pointer variable
2020-12-03 15:32 [PATCH v1 1/3] f_rockusb: Use NULL instead of 0 for pointers Andy Shevchenko
2020-12-03 15:32 ` [PATCH v1 2/3] f_rockusb: Avoid use-after-free in the global pointer variable Andy Shevchenko
@ 2020-12-03 15:32 ` Andy Shevchenko
1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2020-12-03 15:32 UTC (permalink / raw)
To: u-boot
In case of usb_add_function() failure the error path has an issue,
i.e the global pointer variable is assigned to garbage
Fix the above mentioned issue by assigning pointer to NULL.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/usb/gadget/f_fastboot.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c
index d1d087e12b2b..d0d865cf3d08 100644
--- a/drivers/usb/gadget/f_fastboot.c
+++ b/drivers/usb/gadget/f_fastboot.c
@@ -315,7 +315,7 @@ static int fastboot_add(struct usb_configuration *c)
status = usb_add_function(c, &f_fb->usb_function);
if (status) {
free(f_fb);
- fastboot_func = f_fb;
+ fastboot_func = NULL;
}
return status;
--
2.29.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-03 15:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-03 15:32 [PATCH v1 1/3] f_rockusb: Use NULL instead of 0 for pointers Andy Shevchenko
2020-12-03 15:32 ` [PATCH v1 2/3] f_rockusb: Avoid use-after-free in the global pointer variable Andy Shevchenko
2020-12-03 15:32 ` [PATCH v1 3/3] f_fastboot: " Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox