Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1471888pxb; Tue, 8 Feb 2022 19:12:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9iOXuwkL83wcYV7911j69s36OLt1IcQeFd1h/1KZH3Vjc0C1Iq16VLBFEjzUyNRZnz3Su X-Received: by 2002:a50:8e12:: with SMTP id 18mr361950edw.433.1644376351516; Tue, 08 Feb 2022 19:12:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644376351; cv=none; d=google.com; s=arc-20160816; b=NKrPzS2/pwTGvKqfjD8rdX+olEt/JcI7YMXdxS55MzG370oBcNDWRGbmw2SyFCbJMm vrW8hkjxo3t8bZz9XW9bSlEaId2zeEfe7CsO4If5aoqHUJk31vGIMlNVkYIrBev7q/Pu khNTOYW2jMKCybnN76QQIOym2r6rPpMzVTmLH2TbCDdB27ZnwZwvzLqRztN46japeRSl OZWBZunxxDnEXIXBhkSRoYLjQz/6gRahaG58OC6gxHO/cd40y8R9TuorXC0vu7o4HwGF G+IOsz/7V61KwrAsEm4uRjBhrB40sPA3SdjaQEd31VmGM8M96zihXkQVAHY1Tx02lZrq Bxgw== 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=oRUCD9etgrfdbcIq1stlkPq3UIRcdqIjrBcv5+9V3vE=; b=jH2PynPUsdUyu1MvvXdTq5Ko087qLdamnkHB9XQksBLdqjYjvc71d5ma6vp4Fms+/e LZWDqba5dsKYJ4nYnZkN57+IDAzRhQl38kMlF2tar0jnttf5f+fZLdyrCEC6LiEneNNZ JSdIHVvkYoartU/W7Jvo9zFAUFtAQVdWOteW2N0dcPTYicXOEKlkJTcyaE2IGLNpv9Ro lck7qdU5x0h2MpQvPXUVB+DqQQZZQXMiLwbBjWP3jMgnqn6Ut9c0NJEjwt+32fd3t6Ko IgBpkD5Ez116WHr4Jmt28DMPoHNqRnXDZnc+dUX5NYDaieyfEjDKqomsZfnVL4J24P96 apDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gxp6gjMo; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hr21si2574123ejc.613.2022.02.08.19.12.06; Tue, 08 Feb 2022 19:12:31 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=gxp6gjMo; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347042AbiBGKjF (ORCPT + 99 others); Mon, 7 Feb 2022 05:39:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245021AbiBGK1b (ORCPT ); Mon, 7 Feb 2022 05:27:31 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC5B6C043181; Mon, 7 Feb 2022 02:27:30 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 6221D612F0; Mon, 7 Feb 2022 10:27:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9849C004E1; Mon, 7 Feb 2022 10:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644229649; bh=Ea/XgchYNUyDyZnHDIWZphGznZHyvYvoO3mp+EI+3DM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gxp6gjMooNt+0+/sJ9licDOZQh2gXK56cR44iURJCiAjpMcitNE0Aih4wIENC7p9I BbflIonrJj5D1ZzJ2gx2qEc/kPc71t9MOMV3BUtqaSyDQsP5XfEALcUifa0EUXJzyK PfhC6PqMQEAMbdf/uwsA+Deqy8S4ZPQRJXFUfgu4= Date: Mon, 7 Feb 2022 11:27:26 +0100 From: Greg KH To: Pavel Skripkin Cc: davem@davemloft.net, kuba@kernel.org, linux@rempel-privat.de, andrew@lunn.ch, oneukum@suse.com, robert.foss@collabora.com, linux-usb@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+6ca9f7867b77c2d316ac@syzkaller.appspotmail.com, Oleksij Rempel Subject: Re: [PATCH net-next] net: asix: add proper error handling of usb read errors Message-ID: References: <20220206180516.28439-1-paskripkin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220206180516.28439-1-paskripkin@gmail.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Sun, Feb 06, 2022 at 09:05:16PM +0300, Pavel Skripkin wrote: > Syzbot once again hit uninit value in asix driver. The problem still the > same -- asix_read_cmd() reads less bytes, than was requested by caller. > > Since all read requests are performed via asix_read_cmd() let's catch > usb related error there and add __must_check notation to be sure all > callers actually check return value. > > So, this patch adds sanity check inside asix_read_cmd(), that simply > checks if bytes read are not less, than was requested and adds missing > error handling of asix_read_cmd() all across the driver code. > > Fixes: d9fe64e51114 ("net: asix: Add in_pm parameter") > Reported-and-tested-by: syzbot+6ca9f7867b77c2d316ac@syzkaller.appspotmail.com > Signed-off-by: Pavel Skripkin > Tested-by: Oleksij Rempel > --- > > Changes since RFT: > - Added Tested-by: tag > > --- > drivers/net/usb/asix.h | 4 ++-- > drivers/net/usb/asix_common.c | 19 +++++++++++++------ > drivers/net/usb/asix_devices.c | 21 ++++++++++++++++++--- > 3 files changed, 33 insertions(+), 11 deletions(-) > > diff --git a/drivers/net/usb/asix.h b/drivers/net/usb/asix.h > index 2a1e31def..4334aafab 100644 > --- a/drivers/net/usb/asix.h > +++ b/drivers/net/usb/asix.h > @@ -192,8 +192,8 @@ extern const struct driver_info ax88172a_info; > /* ASIX specific flags */ > #define FLAG_EEPROM_MAC (1UL << 0) /* init device MAC from eeprom */ > > -int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, > - u16 size, void *data, int in_pm); > +int __must_check asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, > + u16 size, void *data, int in_pm); > > int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, > u16 size, void *data, int in_pm); > diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c > index 71682970b..524805285 100644 > --- a/drivers/net/usb/asix_common.c > +++ b/drivers/net/usb/asix_common.c > @@ -11,8 +11,8 @@ > > #define AX_HOST_EN_RETRIES 30 > > -int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, > - u16 size, void *data, int in_pm) > +int __must_check asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, > + u16 size, void *data, int in_pm) > { > int ret; > int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16); > @@ -27,9 +27,12 @@ int asix_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, > ret = fn(dev, cmd, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, > value, index, data, size); > > - if (unlikely(ret < 0)) > + if (unlikely(ret < size)) { > + ret = ret < 0 ? ret : -ENODATA; > + Didn't I suggest using the proper USB core functions for this instead of rolling your own functions? We now have usb_control_msg_read() and usb_control_msg_send() that prevents this type of thing from happening. Ah, it's a bit more tangled up than that it seems, the number of layers of abstractions here is odd and deep. This change looks fine for now to keep syzbot happy: Reviewed-by: Greg Kroah-Hartman