From: Jules Maselbas <jmaselbas@kalray.eu>
To: barebox@lists.infradead.org
Cc: Jules Maselbas <jmaselbas@kalray.eu>
Subject: [PATCH 3/3] usb: gadget: dfu: Reset global variables on unbind
Date: Tue, 24 Mar 2020 16:46:47 +0100 [thread overview]
Message-ID: <20200324154647.17341-4-jmaselbas@kalray.eu> (raw)
In-Reply-To: <20200324154647.17341-1-jmaselbas@kalray.eu>
Global variables must be reset to their default value before a new
dfu_bind is done. Otherwise things wont work and are likely to cause
a system crash due to a use after free: the global dfu_files was still
pointing deallocated structure after unbind.
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
---
drivers/usb/gadget/dfu.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/usb/gadget/dfu.c b/drivers/usb/gadget/dfu.c
index 592586db1..5504f4933 100644
--- a/drivers/usb/gadget/dfu.c
+++ b/drivers/usb/gadget/dfu.c
@@ -277,6 +277,15 @@ dfu_unbind(struct usb_configuration *c, struct usb_function *f)
{
struct f_dfu *dfu = func_to_dfu(f);
+ memset(&dfu_mtdinfo, 0, sizeof(dfu_mtdinfo));
+ dfu_files = NULL;
+ dfu_file_entry = NULL;
+ dfufd = -EINVAL;
+ dfudetach = 0;
+ dfu_written = 0;
+ dfu_erased = 0;
+ prog_erase = 0;
+
usb_free_all_descriptors(f);
dma_free(dfu->dnreq->buf);
--
2.21.0.196.g041f5ea
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2020-03-24 15:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-24 15:46 [PATCH 0/3] usb: gadget: dfu: Fix timeout on erase when using big partition Jules Maselbas
2020-03-24 15:46 ` [PATCH 1/3] usb: gadget: dfu: Add manifestation phase Jules Maselbas
2020-03-24 15:46 ` [PATCH 2/3] usb: gadget: dfu: Progressive erase if file is a mtd Jules Maselbas
2020-03-26 6:03 ` Sascha Hauer
2020-03-26 9:08 ` Jules Maselbas
2020-03-24 15:46 ` Jules Maselbas [this message]
2020-03-26 6:09 ` [PATCH 3/3] usb: gadget: dfu: Reset global variables on unbind Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200324154647.17341-4-jmaselbas@kalray.eu \
--to=jmaselbas@kalray.eu \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox