Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3558622pxb; Mon, 24 Jan 2022 12:11:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxpYUCptmVtl9hqt4tZDHoGljt6KOK75KPTJ5grvPtm+trpi+byFrBMJbl5rCKpju8vrYZ+ X-Received: by 2002:aa7:8084:0:b0:4bc:9423:96b2 with SMTP id v4-20020aa78084000000b004bc942396b2mr15252896pff.45.1643055101216; Mon, 24 Jan 2022 12:11:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643055101; cv=none; d=google.com; s=arc-20160816; b=sBWf5fdDPNUZhrXxnzfUedGGZVegXzTTssFcXrR7rlFA2OxcsBp9LeCQ1e8vlTCFaP V/JOivw396YeJlYTEWFOcEPiWqYMRAAMqPYoVxJuBgLGiYI4OGBGqXsuvKyRSfP60dXq Wp32/LkreH2wy06vaekqodTaa0+s/w+damzNXWRiXvO3UupgYS5aeNWVFUY82IhLt2Wj GiMazA+tSvH1ru+cJ3re3xoR0Yhdb+aIma70ErxgvrxfnN66PXvvAdbypefkvsHqXTpY uIseSaJm5VTB79ZAwQWKuHzzYfg/VEcTRnPZgeXXYQqxF8Paexvricmej0MUH/213k5j XeFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/gitrqRk5NY+5aEJ0Lngzp32ruDUxvra6oGJ6yZ/miU=; b=docS4lFCh/JeD+gLZSN/1VpbH7AZ3/NlsxT+RkkPCxlnLLE+Xaaxd8oc7B5MOsO2lE vAFTEJnTDcXNpBTVxajhIaURaV1EM3hV6G+VZawQUSoNBxud3iYMbuSP/bwVnxse5jg+ ChADk3YYOh6KQ+CGCjg80YmuGN2eMRLH6l+CG4MFav27BucUKAlvW0pnStHmVeuOWHl0 eCX3SKnybFo5J4KAQ0SW7H6LTpFaw0JrEQ7d5JU11fELsa7k449eBFk8ST7zPm+kI+aL 4oxab8VyPluRrplgzu9L6twvgDbekJz0J4wCE0YbHAc4CmQ20G8x/2oZBL8fky2yD0mm 4EAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2OtncbY9; 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 l8si13779563pgp.156.2022.01.24.12.11.29; Mon, 24 Jan 2022 12:11:41 -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=2OtncbY9; 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 S1347951AbiAXTOi (ORCPT + 99 others); Mon, 24 Jan 2022 14:14:38 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:35572 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345483AbiAXTFo (ORCPT ); Mon, 24 Jan 2022 14:05:44 -0500 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 64F8D60917; Mon, 24 Jan 2022 19:05:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FF69C340E5; Mon, 24 Jan 2022 19:05:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643051143; bh=gUBygmoEBQDPFQekCp2li5xY7NKosJ7ZgGesRhBIraQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2OtncbY9G1m/Z3Y01GYouL82l6YDa3tvcqF73UtvPftN2DQrzXHj+mRhksPgpdVNN TTfDny4R5vu3fB8plnbNNfbZ/rIy0RsqSew+SBIPeN+DiZBv/ZOUluB4JQDpWJuwG8 ywOdYp5lZT/z9IMr5zzJsWNvLTfuxo2jivGK/e/I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Skripkin , Arnd Bergmann , Jakub Kicinski , Sasha Levin , syzbot+003c0a286b9af5412510@syzkaller.appspotmail.com Subject: [PATCH 4.14 067/186] net: mcs7830: handle usb read errors properly Date: Mon, 24 Jan 2022 19:42:22 +0100 Message-Id: <20220124183939.276113106@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183937.101330125@linuxfoundation.org> References: <20220124183937.101330125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Skripkin [ Upstream commit d668769eb9c52b150753f1653f7f5a0aeb8239d2 ] Syzbot reported uninit value in mcs7830_bind(). The problem was in missing validation check for bytes read via usbnet_read_cmd(). usbnet_read_cmd() internally calls usb_control_msg(), that returns number of bytes read. Code should validate that requested number of bytes was actually read. So, this patch adds missing size validation check inside mcs7830_get_reg() to prevent uninit value bugs Reported-and-tested-by: syzbot+003c0a286b9af5412510@syzkaller.appspotmail.com Fixes: 2a36d7083438 ("USB: driver for mcs7830 (aka DeLOCK) USB ethernet adapter") Signed-off-by: Pavel Skripkin Reviewed-by: Arnd Bergmann Link: https://lore.kernel.org/r/20220106225716.7425-1-paskripkin@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/usb/mcs7830.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/net/usb/mcs7830.c b/drivers/net/usb/mcs7830.c index 5a47e5510ca82..c0f52a622964f 100644 --- a/drivers/net/usb/mcs7830.c +++ b/drivers/net/usb/mcs7830.c @@ -121,8 +121,16 @@ static const char driver_name[] = "MOSCHIP usb-ethernet driver"; static int mcs7830_get_reg(struct usbnet *dev, u16 index, u16 size, void *data) { - return usbnet_read_cmd(dev, MCS7830_RD_BREQ, MCS7830_RD_BMREQ, - 0x0000, index, data, size); + int ret; + + ret = usbnet_read_cmd(dev, MCS7830_RD_BREQ, MCS7830_RD_BMREQ, + 0x0000, index, data, size); + if (ret < 0) + return ret; + else if (ret < size) + return -ENODATA; + + return ret; } static int mcs7830_set_reg(struct usbnet *dev, u16 index, u16 size, const void *data) -- 2.34.1