Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1471448pxa; Sun, 23 Aug 2020 04:16:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpyTYDFj2UJNoJtzpHVaccJZDpAc90fNuSWtxLZbhb17+8wTtZi+74g2g9l+xFvBTMLvAi X-Received: by 2002:a50:abe3:: with SMTP id u90mr983306edc.338.1598181369176; Sun, 23 Aug 2020 04:16:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598181369; cv=none; d=google.com; s=arc-20160816; b=ggKgHFx4CJA5xKYWXxCSE35B6w/WddWau49VTr7TLN3MnL1cMJCR61W8tz09qUqc5Z YS62COcoE8mjGBY5O7Hb4/AH7HKBIX4RXN5iLKSnDRBZryzvQ/ol2Ct+7Q5igaO86FYG PxiiMz3lczzDqSM4EOJpMSjgLwTnh5///SdtClqzwTrffxFQ71ThMG7hMEpApzZJOxr3 7gc5hyX4GY7JPNpngyUoOrcjYXKseaQI1WOOuNIK0//52BsYgowHIWZswi9As+ZoYyM8 QHi2ys8uvdQFqTWr7iLjW36ooCYT9ywY21JXdA4KZxPlG7aVIfeWjGkZ/qKarrnnLLII Bhtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=+ozHzPaYCuwJAbtVm3nLpTBKgxREHhLrPbdQIxp8EY0=; b=WiNIkhdtbnntBCZtjbkbGj+ccl6phxmAZPAQqBU6EkKNBp5XL/aGW/u7kTDT1yzwOi HwapK/1iddz5OjcMm3YptOBEwEobB4IW84ifOtugRRYA3L7eqllKkufJL1TMPt3F1aAB RBrYHwiQ+swTf+8ViETTYT5oD6/vrqnFn30/M7o5cDuKpcA8VCn6wg+Lx/TcWj8zdN3k QT8L26fx8MHvfVOoZjH6oIiN1nJNWUv6sjFOR1eMB0J0QaS2OE6ADPgIsxIIVk19Vl0+ +GPucyLB53NPFFpVj+aRZ0BMGDqWBNwQgUjILbDlYEG20NnoAF2JE1ZNUfE5P/G26aOO JTcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="v/aPdIfA"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p22si4957564eds.169.2020.08.23.04.15.46; Sun, 23 Aug 2020 04:16:09 -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=default header.b="v/aPdIfA"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726701AbgHWK4U (ORCPT + 99 others); Sun, 23 Aug 2020 06:56:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:47208 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725971AbgHWK4D (ORCPT ); Sun, 23 Aug 2020 06:56:03 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 130D92072D; Sun, 23 Aug 2020 10:56:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598180162; bh=4yd51JrmDIU9v+Uu6SenJKfbOo3beI55UZ1+lyBGMa4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=v/aPdIfAiaTcN17ybARTdRUaeD7Hd5J/SIBYkPBlSXaUP0egieEsu/OYYKZLS4tA+ 2Fz2FCNGu2cwIRqIpyfjeMXphy4vy+i6KDUPF8+huSX2XMC0NeoFplO97MSaEWdWdw kcIx2Jt3wxp9RDvWhg0qUl9QKI26gtne3FnlHOIk= Date: Sun, 23 Aug 2020 12:56:22 +0200 From: Greg Kroah-Hartman To: Dmitry Vyukov Cc: Himadri Pandya , David Miller , Jakub Kicinski , linux-kernel-mentees@lists.linuxfoundation.org, USB list , netdev , LKML , syzkaller-bugs Subject: Re: [PATCH] net: usb: Fix uninit-was-stored issue in asix_read_cmd() Message-ID: <20200823105622.GA87391@kroah.com> References: <20200823082042.20816-1-himadrispandya@gmail.com> <20200823101924.GA3078429@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Aug 23, 2020 at 12:31:03PM +0200, Dmitry Vyukov wrote: > On Sun, Aug 23, 2020 at 12:19 PM Greg Kroah-Hartman > > It's not always a failure, some devices have protocols that are "I could > > return up to a max X bytes but could be shorter" types of messages, so > > it's up to the caller to check that they got what they really asked for. > > Yes, that's why I said _separate_ helper function. There seems to be > lots of callers that want exactly this -- "I want 4 bytes, anything > else is an error". With the current API it's harder to do - you need > additional checks, additional code, maybe even additional variables to > store the required size. APIs should make correct code easy to write. One note on this, will respond to the rest of the email later. It should be the same exact amount of code in the driver to handle this either way: Today's correctly written driver: data_size = 4; data = kmalloc(data_size, GFP_KERNEL); ... retval = usb_control_msg(....., data, data_size, ...); if (retval < buf_size) { /* SOMETHING WENT WRONG! */ } With your new function: data_size = 4; data = kmalloc(data_size, GFP_KERNEL); ... retval = usb_control_msg_error_on_short(....., data, data_size, ...); if (retval < 0) { /* SOMETHING WENT WRONG! */ } Catch the difference, it's only in checking for retval, either way you are writing the exact same logic in the driver, you still have to tell the USB layer the size of the buffer you want to read into, still have to pass in the buffer, and everything else. You already know the size of the data you want, and you already are doing the check, those things you have to do no matter what, it's not extra work. We can write a wrapper around usb_control_msg() for something like this that does the transformation of a short read into an error, but really, does that give us all that much here? Yes, I want to make it easy to write correct drivers, and hard to get things wrong, but in this case, I don't see the new way any "harder" to get wrong. Unless you know of a simpler way here? thanks, greg k-h