From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D2C1C32772 for ; Tue, 23 Aug 2022 20:37:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232566AbiHWUho (ORCPT ); Tue, 23 Aug 2022 16:37:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231243AbiHWUh0 (ORCPT ); Tue, 23 Aug 2022 16:37:26 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 7A84F4D4C6 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> Precedence: bulk List-ID: X-Mailing-List: linux-usb@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