Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2113122iof; Tue, 7 Jun 2022 20:10:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw285EbuFkLgAKoec8uEc0n56SZl84Au4WPC3+vy/zd1ubd4hxsvqzrS4El9AvmmYyFDWpL X-Received: by 2002:a65:554b:0:b0:3fc:159c:823e with SMTP id t11-20020a65554b000000b003fc159c823emr28258889pgr.33.1654657822772; Tue, 07 Jun 2022 20:10:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654657822; cv=none; d=google.com; s=arc-20160816; b=D/ffqiKh9liyZrAoY/SK+hK5Vm1grfwemYcM9VzQqgadYY57ol4fNduiUIVY0/31s5 sPz+P3FaeNyuCV+gP3BKM+MRF4rrT1YSDE3J5S4/HXL0Gv+EcQ5Q9RMSf3H1D/7jELrn G5y7WgLDv+5gFor+kZ/nobYWPekAtnO43YRvzMGnlS6QGwi1T6SJnZs2kQo/zfbbFzj5 p2scEurhS4WBlM0FSUGtZ+dltAg8bngcMu2KIP4aUivzY/GSCzv0rhNvoiyOHTTxgC85 SznrDfAfkKILYRdDGQH+sPGhUXO3JaWHXtaDlNzT39g/OkPdLlxRugLHvuPVf2rXg+gE Ex+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=LsvvBFhPEHjJTe9NrVsB8k+78CG/gh2gQTlrjppl0Fw=; b=LwKf0SLV+NWY+T3X/Uu9LFjhFSiNqjYyoDqaAL8ZIti0RNN1ioYp8ZyhEtNq8ZFMw2 rf/wWeU1SJ+W6Wdtl9Y4rnCPoSAMb7hVAVzf+7GHCwXcvO/P/YKYqz04PZ6fhpDAtLl8 aWuBsmBB8lfzWGe+uA5FUIO+aOnIuQA1z5X7W5Gp3Im98CBUrA6MVi2bEuYzDaOYJELi R/hNFszolp473Ao3+cyYug/yNKxrO1FCdmnXsoykbbmBfv/ySno3+AQagEHSiQHd41nU Dvvh0RXgMG9NJIoI5dMbdMpQx9oqHj1foz7DnBmLV1Rtnlf+ZpI67cR++Tb5j6cnDd1U xu1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20190130-41we5z8j header.b=Ou7nwaz3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m185-20020a633fc2000000b003fa0ae4f59fsi26134585pga.52.2022.06.07.20.10.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 20:10:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20190130-41we5z8j header.b=Ou7nwaz3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 20BF83C07A3; Tue, 7 Jun 2022 19:20:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238613AbiFGMbI (ORCPT + 99 others); Tue, 7 Jun 2022 08:31:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237079AbiFGMbG (ORCPT ); Tue, 7 Jun 2022 08:31:06 -0400 Received: from smtp125.iad3b.emailsrvr.com (smtp125.iad3b.emailsrvr.com [146.20.161.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB5F6C1EC3 for ; Tue, 7 Jun 2022 05:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mev.co.uk; s=20190130-41we5z8j; t=1654605060; bh=iJdH+cC9+3qmvcM+VtHfSdCQIx+u2/nDFIKkNrB6JRA=; h=Date:Subject:To:From:From; b=Ou7nwaz3C4YR1bss+QGw6bfEzcya2amxMTCdnV4jnF0/d4FcyzEiTjcSF8Z9glWXD YS7u5i+92JkgLm+odysevHCCMhOWlujLDkoFc7tQEZdF3GkjiKmtMLPjIo9tQnmoCk YhBz+RRRoTgxtNutVXuHzRX6qfmhAJGs7EetORr8= X-Auth-ID: abbotti@mev.co.uk Received: by smtp8.relay.iad3b.emailsrvr.com (Authenticated sender: abbotti-AT-mev.co.uk) with ESMTPSA id 1022F400F0; Tue, 7 Jun 2022 08:30:59 -0400 (EDT) Message-ID: Date: Tue, 7 Jun 2022 13:30:59 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH 1/1] comedi: ni_usb6501: fix transfer-buffer overflows Content-Language: en-GB To: Xiaohui Zhang , H Hartley Sweeten , Greg Kroah-Hartman , Johan Hovold , linux-kernel@vger.kernel.org References: <20220607111802.13311-1-xiaohuizhang@ruc.edu.cn> From: Ian Abbott Organization: MEV Ltd. In-Reply-To: <20220607111802.13311-1-xiaohuizhang@ruc.edu.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Classification-ID: 8a778d23-9852-4091-b4fb-bd1a2b7f2295-1-1 X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 07/06/2022 12:18, Xiaohui Zhang wrote: > Similar to the handling of vmk80xx_alloc_usb_buffers in commit > a23461c47482("comedi: vmk80xx: fix transfer-buffer overflows"), > we thought a patch might be needed here as well. > > The driver uses endpoint-sized USB transfer buffers but up until > recently had no sanity checks on the sizes. > > Signed-off-by: Xiaohui Zhang > --- > drivers/comedi/drivers/ni_usb6501.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/comedi/drivers/ni_usb6501.c b/drivers/comedi/drivers/ni_usb6501.c > index 0dd9edf7bced..8303bfc305c5 100644 > --- a/drivers/comedi/drivers/ni_usb6501.c > +++ b/drivers/comedi/drivers/ni_usb6501.c > @@ -90,6 +90,7 @@ > #include > > #define NI6501_TIMEOUT 1000 > +#define MIN_BUF_SIZE 64 > > /* Port request packets */ > static const u8 READ_PORT_REQUEST[] = {0x00, 0x01, 0x00, 0x10, > @@ -459,12 +460,12 @@ static int ni6501_alloc_usb_buffers(struct comedi_device *dev) > struct ni6501_private *devpriv = dev->private; > size_t size; > > - size = usb_endpoint_maxp(devpriv->ep_rx); > + size = max(usb_endpoint_maxp(devpriv->ep_rx), MIN_BUF_SIZE); > devpriv->usb_rx_buf = kzalloc(size, GFP_KERNEL); > if (!devpriv->usb_rx_buf) > return -ENOMEM; > > - size = usb_endpoint_maxp(devpriv->ep_tx); > + size = max(usb_endpoint_maxp(devpriv->ep_tx), MIN_BUF_SIZE); > devpriv->usb_tx_buf = kzalloc(size, GFP_KERNEL); > if (!devpriv->usb_tx_buf) > return -ENOMEM; The code change looks OK but this patch should have been sent as a "v2" patch and should have a brief description of the v2 changes after the "---" line. Reviewed-by: Ian Abbott -- -=( Ian Abbott || MEV Ltd. is a company )=- -=( registered in England & Wales. Regd. number: 02862268. )=- -=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=- -=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-