Skip to content

Commit c70c3db

Browse files
Venkatesh Yadav AbbarapuAlif Zakuan Yuslaimi
authored andcommitted
usb: gadget: dfu: Fix the unchecked length field
DFU implementation does not bound the length field in USB DFU download setup packets, and it does not verify that the transfer direction. Fixing the length and transfer direction. CVE-2022-2347 Signed-off-by: Venkatesh Yadav Abbarapu <venkatesh.abbarapu@amd.com> Reviewed-by: Marek Vasut <marex@denx.de>
1 parent 265934e commit c70c3db

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/usb/gadget/f_dfu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ static int state_dfu_idle(struct f_dfu *f_dfu,
324324

325325
switch (ctrl->bRequest) {
326326
case USB_REQ_DFU_DNLOAD:
327-
if (!(ctrl->bRequestType & USB_DIR_IN)) {
327+
if (ctrl->bRequestType == USB_DIR_OUT) {
328328
if (len == 0) {
329329
f_dfu->dfu_state = DFU_STATE_dfuERROR;
330330
value = RET_STALL;
@@ -336,7 +336,7 @@ static int state_dfu_idle(struct f_dfu *f_dfu,
336336
}
337337
break;
338338
case USB_REQ_DFU_UPLOAD:
339-
if (ctrl->bRequestType & USB_DIR_IN) {
339+
if (ctrl->bRequestType == USB_DIR_IN) {
340340
f_dfu->dfu_state = DFU_STATE_dfuUPLOAD_IDLE;
341341
f_dfu->blk_seq_num = 0;
342342
value = handle_upload(req, len);
@@ -435,7 +435,7 @@ static int state_dfu_dnload_idle(struct f_dfu *f_dfu,
435435

436436
switch (ctrl->bRequest) {
437437
case USB_REQ_DFU_DNLOAD:
438-
if (!(ctrl->bRequestType & USB_DIR_IN)) {
438+
if (ctrl->bRequestType == USB_DIR_OUT) {
439439
f_dfu->dfu_state = DFU_STATE_dfuDNLOAD_SYNC;
440440
f_dfu->blk_seq_num = w_value;
441441
value = handle_dnload(gadget, len);
@@ -526,7 +526,7 @@ static int state_dfu_upload_idle(struct f_dfu *f_dfu,
526526

527527
switch (ctrl->bRequest) {
528528
case USB_REQ_DFU_UPLOAD:
529-
if (ctrl->bRequestType & USB_DIR_IN) {
529+
if (ctrl->bRequestType == USB_DIR_IN) {
530530
/* state transition if less data then requested */
531531
f_dfu->blk_seq_num = w_value;
532532
value = handle_upload(req, len);

0 commit comments

Comments
 (0)