From patchwork Sun Jun 27 03:28:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qiang Liu X-Patchwork-Id: 12346609 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71367C49EA6 for ; Sun, 27 Jun 2021 03:29:42 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D4D876162F for ; Sun, 27 Jun 2021 03:29:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D4D876162F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lxLUK-0003mm-J5 for qemu-devel@archiver.kernel.org; Sat, 26 Jun 2021 23:29:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lxLTc-00036H-Gt for qemu-devel@nongnu.org; Sat, 26 Jun 2021 23:28:56 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:40540) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lxLTa-00063T-LK for qemu-devel@nongnu.org; Sat, 26 Jun 2021 23:28:56 -0400 Received: by mail-wr1-x429.google.com with SMTP id g7so11254391wri.7 for ; Sat, 26 Jun 2021 20:28:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Zubl8mgJImZll2lQi+hFnjquenEVGAsVZioeT3sF1Kc=; b=Dbc4tdmqqhiQHcEDFyc1vgs5CkM0iBEIXDVRBQphaovB6Tx1PAGX6BIgS43R3hh41/ C9JVKpGsToHgx5uqUMqmR7KPECDMy/0EaSjI6/zbYQerMhXWgeGWO5rUYWJlrhPDXY6c lEb5d8WSgJAyatAIdtMoXejdxr7SmDkjMjfXkUGzmYqELWXl4TdScVzGnr5HbK2bWeI5 W6aavMYVz0eVHdFrTK+9wzEhrm3lNOUoLE+Q+FteYfuWeaMlarpuD3AClDvAeF0/i1ek 6xeFLNNwqVjLEhPu87crYd3WOoPh2AHIaqevnfqMFIcZEkuTm6JRyubzWDyFBweOd6p6 4Zug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Zubl8mgJImZll2lQi+hFnjquenEVGAsVZioeT3sF1Kc=; b=TOsJ3Av9+7W3f5KJy+/wmmPipe3RyepbJvsMNpcQIJS7rPiMePidttUv/j0Mj1Gnig TuZNqOizvngj5e77oKuXE+0zf/OT0LYhb78sMw5IlZ0tqy6I32gZiLjh85dAXeaTSo19 75C1pewiCNdKY56K/Nt5d/7aJ2KNK8zXl53T8d+7VWMHd9+Dmzzzptonpvtp+NAM7x8R YdM73eCESwXU38W7HmGkqp3YiR45vIbWBIvZgnsVVv9adfGN5DnfdsXWcUmjdPuIpMru uS+5geHxtashikcGz2bxH13fd17sZRKTCVUbi7Ba8PFUlPtnArq0gUQoBP1oDl9hDfzu cegg== X-Gm-Message-State: AOAM5319cna5zcn03trOEJt5DBFz2xoovkkzu4vEKQdsRvPUXSrQrC83 go7PAVOF5dsJtcfX3WJQiNo= X-Google-Smtp-Source: ABdhPJx3NuSYdFoPe+QI6GurMzsDocn7NwV/FnrgytfoFEmpC8HRnRR77lg7xdYtt13elDgafXhdmQ== X-Received: by 2002:adf:ebd2:: with SMTP id v18mr13838985wrn.248.1624764531838; Sat, 26 Jun 2021 20:28:51 -0700 (PDT) Received: from localhost ([147.78.177.108]) by smtp.gmail.com with ESMTPSA id c12sm10003795wrw.46.2021.06.26.20.28.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 26 Jun 2021 20:28:51 -0700 (PDT) From: Qiang Liu To: Subject: [PATCH] hw/usb/hcd-dwc2: Enforce epnum to 0 for the control endpoint to avoid the assertion failure in usb_ep_get() Date: Sun, 27 Jun 2021 11:28:26 +0800 Message-Id: <1624764506-19841-1-git-send-email-cyruscyliu@gmail.com> X-Mailer: git-send-email 2.7.4 Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=cyruscyliu@gmail.com; helo=mail-wr1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "open list:All patches CC here" , Qiang Liu , Gerd Hoffmann , Paul Zimmerman Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" When eptype is USB_ENDPOINT_XFER_CONTROL and pid is TSIZ_SC_MC_PID_SETUP, usb_ep_get() should return the control endpoint. In hw/usb/core.c, the assumed epnum of the control endpoint is 0. When epnum is not 0, usb_ep_get() will crash due to the check assert(pid == USB_TOKEN_IN || pid == USB_TOKEN_OUT). The description http://www.capital-micro.com/PDF/CME-M7_Family_User_Guide_EN.pdf (18.5.3.4 (14), 18.5.3.4 (10)) a) mentions that the pid is maintained by the host, b) but doesn't mention that whether the epnum should be 0 for the control endpoint. However, usb_ep_get() assumes it is 0. To avoid potential assertion failure in usb_ep_get(), we could enforce epnum to 0 and warn users. Fixes: 153ef1662c3 ("dwc-hsotg (dwc2) USB host controller emulation") Signed-off-by: Qiang Liu --- hw/usb/hcd-dwc2.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/usb/hcd-dwc2.c b/hw/usb/hcd-dwc2.c index e1d96ac..65d9d46 100644 --- a/hw/usb/hcd-dwc2.c +++ b/hw/usb/hcd-dwc2.c @@ -636,6 +636,11 @@ static void dwc2_enable_chan(DWC2State *s, uint32_t index) } if (eptype == USB_ENDPOINT_XFER_CONTROL && pid == TSIZ_SC_MC_PID_SETUP) { + if (epnum != 0) { + qemu_log_mask(LOG_GUEST_ERROR, + "epnum should be 0 for the control endpoint\n"); + epnum = 0; + } pid = USB_TOKEN_SETUP; } else { pid = epdir ? USB_TOKEN_IN : USB_TOKEN_OUT;