Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1459646pxa; Sun, 23 Aug 2020 03:49:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFNtUoQNCy+1lmqCVLX7J5Ycj7Bg6MQ+EiOIZoRtwk9MADY+14vLjrI21TSqJle2XCYpzl X-Received: by 2002:a05:6402:b45:: with SMTP id bx5mr933716edb.214.1598179775025; Sun, 23 Aug 2020 03:49:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598179775; cv=none; d=google.com; s=arc-20160816; b=kKFoyL6CiBXH4tDjnvTWhMfy6w0sh4AkxMxHi/wldM+5D9qhHsgaab9mTOVDU6VBgE W8A9Q8UejB28iHrCUjv9f0onWnTZLrpqV/4+n+vRHEKkEKeMqKCF1rMBjEIWowqLrc5x utTft08n9neJGeanNdl5oWOIzo+XKuwZkbWSB2DgLQmQyubYWS1TAIomKR63+aSIsfao 1Yth+cIbcaus41IsOV/3+esTMZ0dxcxh6B+OyTx9/4eUe2MqUK5B/sUYvPPwojU7iFEl pBwpzE+kGQ+2TgXTz1DqDFmlnjVG0hDOnW0Le5/EcRjtjRF1xvOLUjYEZeEyioGbew3A KVNg== 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=MDvrzYJy30Udnp+rLVypIMxlH9i9aD6AaplKfeiXpN0=; b=chmIUF98j/Wh3MbtzcIRxP2FUfJ+nq9cab3tLexrp2g3RjiVXuhaeSgzT3dH8l5d2K TueMiC0bKlkevdN92551ZrpuPMh3JUO9dcrndprnGJX9KsUzOjed4FXx/L6wpF9y/HfC QW36DXwny1MuzxMe4edMuYJaoH+7M4oFx0Q3x/K839NHJXXHGM/4UsMPpRBMumgtQJWj xiBF1Hj5xSGPn0F8n5huTyIgrmFkjEj8Vf5Qu6p03fkGNkZS6A84NjRdnK5PB+t6UgAz ouN6yA7k/3fzwXnkZx2K8cfVDdF1IltItGlKqQWXOTN80bcqzAnsomrJ5BJWN7rpccS/ 67BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0NF1MK1u; 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 o16si4875908ejc.319.2020.08.23.03.49.11; Sun, 23 Aug 2020 03:49:34 -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=0NF1MK1u; 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 S1726947AbgHWKTH (ORCPT + 99 others); Sun, 23 Aug 2020 06:19:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:32968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725905AbgHWKTG (ORCPT ); Sun, 23 Aug 2020 06:19:06 -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 D21762075B; Sun, 23 Aug 2020 10:19:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598177945; bh=Ujak7Kc517HcPZ0LyBiz0rIH59QGuYtCtf+7xmhT4G0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=0NF1MK1uPeo4chp3b3OeVF3gntArq7804AdQn5p/vFZQPYHLStv4l/ojbpmmEREiM LH+z03UqMadgSGfgYxn/yfcAvAGEqN6mPgJfxLRfvE7EFZ5QVByuL3HXW5l/NS58k1 ELQRH9UOuSkb8chxVn+ppKNIRirtp99toiAZnqmg= Date: Sun, 23 Aug 2020 12:19:24 +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: <20200823101924.GA3078429@kroah.com> References: <20200823082042.20816-1-himadrispandya@gmail.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 11:26:27AM +0200, Dmitry Vyukov wrote: > On Sun, Aug 23, 2020 at 10:21 AM Himadri Pandya > wrote: > > > > Initialize the buffer before passing it to usb_read_cmd() function(s) to > > fix the uninit-was-stored issue in asix_read_cmd(). > > > > Fixes: KMSAN: kernel-infoleak in raw_ioctl > > Reported by: syzbot+a7e220df5a81d1ab400e@syzkaller.appspotmail.com > > > > Signed-off-by: Himadri Pandya > > --- > > drivers/net/usb/asix_common.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c > > index e39f41efda3e..a67ea1971b78 100644 > > --- a/drivers/net/usb/asix_common.c > > +++ b/drivers/net/usb/asix_common.c > > @@ -17,6 +17,8 @@ int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, > > > > BUG_ON(!dev); > > > > + memset(data, 0, size); > > Hi Himadri, > > I think the proper fix is to check > usbnet_read_cmd/usbnet_read_cmd_nopm return value instead. > Memsetting data helps to fix the warning at hand, but the device did > not send these 0's and we use them as if the device did send them. But, for broken/abusive devices, that really is the safest thing to do here. They are returning something that is obviously not correct, so either all callers need to check the size received really is the size they asked for, or we just plod onward with a 0 value like this. Or we could pick some other value, but that could cause other problems if it is treated as an actual value. > Perhaps we need a separate helper function (of a bool flag) that will > fail on incomplete reads. Maybe even in the common USB layer because I > think we've seen this type of bug lots of times and I guess there are > dozens more. 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, it's more work to do this checking. However converting the world over to a "give me an error value if you don't read X number of bytes" function would also be the same amount of work, right? So personally, I think this patch is right for when you are trying to abuse the USB driver stack :) Reviewed-by: Greg Kroah-Hartman