Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp879591pxb; Wed, 27 Oct 2021 14:20:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx08MUYWZI/7SyrCn7fCY6PfqCvz2S451cxT7xOH5d/YyppV0obxTYSsGYVECnW+Q6AFh1n X-Received: by 2002:a17:906:7ac9:: with SMTP id k9mr10976ejo.411.1635369643894; Wed, 27 Oct 2021 14:20:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635369643; cv=none; d=google.com; s=arc-20160816; b=vy5gjw3JL9YVoNsrnJf1ppEFN/x8QEwCX7K06MTvqpuZhS8dmX7ljxZ8xeCoK0+xtg NSRrvHL2cqO4ElpKUw/m7vHnLr7tb/gu65W6bOOaM4EgxwxYyTJqk/bg/Ylj+YHW1wml D6+gihe5dQcEgwjAt2zT0RmQZgY6CrZfU/jLMpwdZeWU1CbI8Vep60DvW6EivONCSO0s mZkTf0toM8QEB330bw7tcJy9LHfxAVVkx/uAdrVYq076vXYmRL9amjYl6IiJAMmgroOF +5fThpWAURExCrtAtREX6URqtTJIiXNMTxBdu3g9Nl5B0zysxaYNn62GBdv31o8xF0v4 9Jlg== 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:dkim-signature; bh=XfK4VLJqaSleHnOS/eS2hlZHj1Dvs+C1UmU3CFluHrc=; b=E41tA5Q/wIbEMzBdUi9rcKEhhEdt47qLerEQgSwwcQo5Un66PlIyWFkDjGSqR5YrGG cXmkEg65X93FZk67qN3/I/q9YlXls0GKU/Q32hUj6Sf6M5wfwcs9TMi0papYcZyPjjFX 8GJtCgJOlOAtEJ1g5v6YeTzSFw4v1kqFzymNYlsUiNnpF5o6f1iYpoPr5+fBbTDzzPcX Maf+nIbDk5KmJfkS/CLZW08yJz3OB/JSyZ0kQ1C3bjopYSLDY28XBQyIiNAD7gnKGzkx E/n5axgv3OOWEGmqdTKHaevSXd39POjzCm9cWqZOBOmuLnX7gBs206oS8TQP4wBd09zO ZEYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u20JBEpP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z10si1170783ejg.497.2021.10.27.14.20.20; Wed, 27 Oct 2021 14:20:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u20JBEpP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239671AbhJ0I5e (ORCPT + 97 others); Wed, 27 Oct 2021 04:57:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:58040 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231566AbhJ0I5d (ORCPT ); Wed, 27 Oct 2021 04:57:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5E02660C51; Wed, 27 Oct 2021 08:55:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635324908; bh=jsFQ2hTPk1o/ulS9XWmpRn7TcjUOhIqJs34hGUXQZ08=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=u20JBEpP23dqtrJiBCgr8MYA30VQEXwx5LDZt+duCBCQxoQedfaJVSonFvtc9HwmY YYzxtCdI+nvFAA9BlZvmyVdtrYARMlOuTY5N4XgFA9iBgT09sM4vk4s83eM5p8ylB9 I9JdxW3h0utZCbq8PZS2aeQfEf4IwtIeLJfCFr5Mdtj263MafplBx0efD1Ynsla7/z euiqL6tWvcq4HnppBBBf1erMWz8mgiCvopm6ihwFj8pMOyW6TBXSpUyJVJ5V1rroCj 3lRUqpChMaTzJ1SFT1mqAYSxOpYnR4rMf4TOLqkx582LbKJPd9OxzgQLzKvRD/atDy v8DmDcnOiDMPg== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1mfehv-00037H-S0; Wed, 27 Oct 2021 10:54:52 +0200 Date: Wed, 27 Oct 2021 10:54:51 +0200 From: Johan Hovold To: Ian Abbott Cc: H Hartley Sweeten , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Luca Ellero Subject: Re: [PATCH 1/5] comedi: ni_usb6501: fix NULL-deref in command paths Message-ID: References: <20211025114532.4599-1-johan@kernel.org> <20211025114532.4599-2-johan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 26, 2021 at 03:12:28PM +0100, Ian Abbott wrote: > On 25/10/2021 12:45, Johan Hovold wrote: > > The driver uses endpoint-sized USB transfer buffers but had no sanity > > checks on the sizes. This can lead to zero-size-pointer dereferences or > > overflowed transfer buffers in ni6501_port_command() and > > ni6501_counter_command() if a (malicious) device has smaller max-packet > > sizes than expected (or when doing descriptor fuzz testing). > > > > Add the missing sanity checks to probe(). > > > > Fixes: a03bb00e50ab ("staging: comedi: add NI USB-6501 support") > > Cc: stable@vger.kernel.org # 3.18 > > Cc: Luca Ellero > > Signed-off-by: Johan Hovold > > --- > > drivers/comedi/drivers/ni_usb6501.c | 8 ++++++++ > > 1 file changed, 8 insertions(+) > > > > diff --git a/drivers/comedi/drivers/ni_usb6501.c b/drivers/comedi/drivers/ni_usb6501.c > > index 5b6d9d783b2f..eb2e5c23f25d 100644 > > --- a/drivers/comedi/drivers/ni_usb6501.c > > +++ b/drivers/comedi/drivers/ni_usb6501.c > > @@ -144,6 +144,10 @@ static const u8 READ_COUNTER_RESPONSE[] = {0x00, 0x01, 0x00, 0x10, > > 0x00, 0x00, 0x00, 0x02, > > 0x00, 0x00, 0x00, 0x00}; > > > > +/* Largest supported packets */ > > +static const size_t TX_MAX_SIZE = sizeof(SET_PORT_DIR_REQUEST); > > +static const size_t RX_MAX_SIZE = sizeof(READ_PORT_RESPONSE); > > + > > enum commands { > > READ_PORT, > > WRITE_PORT, > > @@ -486,12 +490,16 @@ static int ni6501_find_endpoints(struct comedi_device *dev) > > ep_desc = &iface_desc->endpoint[i].desc; > > > > if (usb_endpoint_is_bulk_in(ep_desc)) { > > + if (usb_endpoint_maxp(ep_desc) < RX_MAX_SIZE) > > + continue; > > if (!devpriv->ep_rx) > > devpriv->ep_rx = ep_desc; > > continue; > > } > > > > if (usb_endpoint_is_bulk_out(ep_desc)) { > > + if (usb_endpoint_maxp(ep_desc) < TX_MAX_SIZE) > > + continue; > > if (!devpriv->ep_tx) > > devpriv->ep_tx = ep_desc; > > continue; > > > > Perhaps it should return an error if the first encountered bulk-in > endpoint has the wrong size or the first encountered bulk-out endpoint > has the wrong size. Something like: > > if (usb_endpoint_is_bulk_in(ep_desc)) { > if (!devpriv->ep_rx) { > if (usb_endpoint_maxp(ep_desc) < RX_MAX_SIZE) > break; > } > continue; This is too convoluted, but I can move the max-packet sanity checks after the endpoint look-ups instead. It doesn't really matter in the end as the real devices presumably only have two bulk endpoints. Johan