From patchwork Fri Jan 14 08:16:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 532592 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 D0014C433F5 for ; Fri, 14 Jan 2022 08:23:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240587AbiANIXf (ORCPT ); Fri, 14 Jan 2022 03:23:35 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:33612 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240034AbiANIV7 (ORCPT ); Fri, 14 Jan 2022 03:21:59 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4F859B8243B; Fri, 14 Jan 2022 08:21:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C793C36AFC; Fri, 14 Jan 2022 08:21:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1642148516; bh=g57pxS2bCc3tWqe1XaCKL+bvkppkDCofhbjkD5BZP84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cl4krdD75uE8kZ3TYn9mXxCOiEvff+dBVWxYJNUpfQNB4TUPo9J9yD1OcEiVMoFCA P1VsaYI4Gg1HK1qYFM2qX80YdUSx1iGv4S/qPf3/eQstQx6ssM2YpTX0oAPbDNemqp rNHWAV5FgL3YMCg25kfyzB7ciouK0M/Df77yNZAk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Hovold , Marcel Holtmann Subject: [PATCH 5.16 15/37] Bluetooth: bfusb: fix division by zero in send path Date: Fri, 14 Jan 2022 09:16:29 +0100 Message-Id: <20220114081545.355871368@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220114081544.849748488@linuxfoundation.org> References: <20220114081544.849748488@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Johan Hovold commit b5e6fa7a12572c82f1e7f2f51fbb02a322291291 upstream. Add the missing bulk-out endpoint sanity check to probe() to avoid division by zero in bfusb_send_frame() in case a malicious device has broken descriptors (or when doing descriptor fuzz testing). Note that USB core will reject URBs submitted for endpoints with zero wMaxPacketSize but that drivers doing packet-size calculations still need to handle this (cf. commit 2548288b4fb0 ("USB: Fix: Don't skip endpoint descriptors with maxpacket=0")). Cc: stable@vger.kernel.org Signed-off-by: Johan Hovold Signed-off-by: Marcel Holtmann Signed-off-by: Greg Kroah-Hartman --- drivers/bluetooth/bfusb.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/bluetooth/bfusb.c +++ b/drivers/bluetooth/bfusb.c @@ -628,6 +628,9 @@ static int bfusb_probe(struct usb_interf data->bulk_out_ep = bulk_out_ep->desc.bEndpointAddress; data->bulk_pkt_size = le16_to_cpu(bulk_out_ep->desc.wMaxPacketSize); + if (!data->bulk_pkt_size) + goto done; + rwlock_init(&data->lock); data->reassembly = NULL;