Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3981755rwa; Tue, 23 Aug 2022 13:52:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR4zBGjD/mRwMla+fFf/afDXxGdHihHJPD+kChh4OYJSg4MvwWjj3a2sShlZjn+PUgLjMC/Q X-Received: by 2002:a17:903:2d1:b0:171:3773:b95 with SMTP id s17-20020a17090302d100b0017137730b95mr24890112plk.173.1661287941691; Tue, 23 Aug 2022 13:52:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661287941; cv=none; d=google.com; s=arc-20160816; b=Ja/xdeLcjkRB7JSoeJnQhRFOBg8Khl9zv5Z9DCq+eAN+dpgdjT6ghJVeXdMCymzlEN 0QpJJDVjLhJiLG8pqRjrrhdqXhelq9FUEuK9AJVxJWEkxkrBrOM0AUdBxRZFH9ieFO+U a/KZvIN7SGYnJirKZFtwjDfXZe26qhxwFx2yvmrwQ+tteEXrKq+SCBWl968oxaAi0Ny0 MQjN/KEt2faUjfwLY8Vm0K/4sm8vDLh6mON0oRj11cImEX6LI1xf9Ob55izqgy8j6NmC rN30jBGasKU3oe/x1c3dySeDXjraTQXaxzygUxQW6xU6OJ9GvIr4GLLstLQpQBbSVYMj +NBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=wzkydH+/D8+j1NdIylmFz4tFkf8KuPPP7Y7ymsVQZO0=; b=C2IdSeJl3aIfOABVl9jU9Wy2VuI/BmKSx4MeZFwwpwj6sszA5uDqbvO53bGbMTWvEv 1z8PXe9OUVQZNqROKv9A4Quj1cjX+16eU7mb/0fkTuJMsunc3TgfYnLdl+cY0j1Bnm8M 1hx0mZi33l5RAHmTdT52AqL8iNwahXM0t3G0HNJdakSrBjENOZLV/EgkLevQYbgLE7SA eN5e7umDVmt1PrwnJluHW8RvwoNibGI1azRehrwK+seFJbJGur/ffxX1zGWjOZHGZiIe 0HSqJSDPBOZ8weQhvezMNhpTMi06iKmBJ6MY24juFJFluqr7oJvKkmO7U7vxl1PUFSvt xwFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t37-20020a634465000000b0041beb6e9d14si8950857pgk.525.2022.08.23.13.52.10; Tue, 23 Aug 2022 13:52:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232591AbiHWUho (ORCPT + 99 others); Tue, 23 Aug 2022 16:37:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231308AbiHWUh1 (ORCPT ); Tue, 23 Aug 2022 16:37:27 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 8CB22543D3 for ; Tue, 23 Aug 2022 13:21:19 -0700 (PDT) Received: (qmail 357336 invoked by uid 1000); 23 Aug 2022 16:21:18 -0400 Date: Tue, 23 Aug 2022 16:21:18 -0400 From: Alan Stern To: Khalid Masum Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] usb: ehci: Prevent possible modulo by zero Message-ID: References: <20220823182758.13401-1-khalid.masum.92@gmail.com> <20220823182758.13401-2-khalid.masum.92@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220823182758.13401-2-khalid.masum.92@gmail.com> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 24, 2022 at 12:27:57AM +0600, Khalid Masum wrote: > usb_maxpacket() returns 0 if it fails to fetch the endpoint. This > value is later used for calculating modulo. Which can cause modulo > by zero in qtd_fill and qh_urb_transaction. > > Prevent this breakage by returning if maxpacket is found to be 0. > > Fixes coverity warning: 744857 ("Division or modulo by zero") > Signed-off-by: Khalid Masum I'm sure we've seen at least one patch doing this submitted in the past. It was wrong then and it's wrong now. Coverity doesn't have a full understanding of how the kernel's USB subsystem works and sometimes it makes mistakes. In short, qh_urb_transaction() can be called only by pathways that pass through usb_submit_urb(), which already includes this check: ep = usb_pipe_endpoint(dev, urb->pipe); if (!ep) return -ENOENT; There's no need to check it again in the ehci-hcd driver. On Wed, Aug 24, 2022 at 12:27:58AM +0600, Khalid Masum wrote: > usb_maxpacket() returns 0 if it fails to fetch the endpoint. This > value is later used for calculating modulo. Which can cause modulo > by zero in qtd_fill. > > Prevent this breakage by returning if maxpacket is found to be 0. > > Fixes coverity warning: 1487371 ("Division or modulo by zero") > Fixes: 9841f37a1cca ("usb: ehci: Add support for SINGLE_STEP_SET_FEATURE test of EHSET") > Signed-off-by: Khalid Masum This also is unnecessary. Calls to ehci_submit_single_step_set_feature() have to pass through request_single_step_set_feature_urb(), which already includes this check: if (!ep) { usb_free_urb(urb); return NULL; } Neither of these patches is needed. Alan Stern