Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3547225pxb; Mon, 24 Jan 2022 11:56:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJxqXPFPlpcCSnZXeXkT/3X63OKLJSPA8KSes8adHiiPdiE+uOTZlZykex6548n/aSRAfvsL X-Received: by 2002:a17:902:bcc9:b0:14b:4a74:bb1d with SMTP id o9-20020a170902bcc900b0014b4a74bb1dmr6883052pls.40.1643054213703; Mon, 24 Jan 2022 11:56:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643054213; cv=none; d=google.com; s=arc-20160816; b=mhhZauXIJvSo6y4+2OJoMueepcocTycYRhFLfDrYgFHo6CHJAVTxUqtObrHo7PVKqv xGofCO1NvFzTHt1YcOA3TfDypNhTyZn8WvMjvd++/GoGEHYnLKP9UKCy558kRLSBE1dd 4BqD4CTeO5umTSC2jDGL1hU1qv/3IZgk9vPopPfUZ4blQytH7sMmedf0ouD1K5RDfCu7 a4gk/boMlJ5Asy/fxC7VPOJKMV78oGghW+IOEDQFUW0EWCoxhrNtxkxyrenWkWzwYwYy wbFCRfC1gYQ9+b0B1g+oK5DEVH9LNDYk3yMdFZ9vUqhZzKxlJw1f6w7eEfPiccTA72ma 7yRQ== 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=Ffv5bEu/3HHN/XKYbHMdiJKJSOTnKFkFU7VHDD4TX5M=; b=WoG0Ni4cBuVYOJ7YZn3CcVmHygQRUp/oGI6Y4j/Tu2vkTmvIMrVdKgxYeMGpm+sr55 /znvr+CpZU+V8IKVq+g7Yk1S4kv7zSwmrb01L9tMDX3jykH5qonJQI606Sd5F1vnzdtR RGJgp4zNWT17Ggk/7l61X2tSY44H/DBnW9NVmwj9A8VIn4SRo8pn75BKhBnKW04ISGRU Wi3KTYVXIPf46IC9eo4BgnIsyeOYwZ1/OXi2I3dalZzJJRL+wquAj8Ey/TZYI65f5qt8 T3RuN3KzVV5q+fwE4NhSjfC5wrrMFMCwMUEao0lWSKG6tVEA5Po163CNI6IjA/yH1eSI 1XZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BYV4ZJVK; 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 62si5362664pgc.281.2022.01.24.11.56.41; Mon, 24 Jan 2022 11:56:53 -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=BYV4ZJVK; 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 S1343616AbiAXSvJ (ORCPT + 99 others); Mon, 24 Jan 2022 13:51:09 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:48650 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245404AbiAXSuA (ORCPT ); Mon, 24 Jan 2022 13:50:00 -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 A55CC614FE; Mon, 24 Jan 2022 18:49:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85D8FC340E8; Mon, 24 Jan 2022 18:49:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643050199; bh=xyb7el4B8LdNx+P5MYu2OzNDCK3CD8EPUq/+flDETEc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BYV4ZJVKvVtH5vzFOoAIyhgbDvjkOVbqvGuGKGHPb+dx9tUHtPryP698peloDSE9s 3rVd6NsAbzZlcDS9mixCzoMhILBvun/KBMDOR6RYgGyTfFFozeW76EfwWan52k8fJ1 sK5e+Cs0No535aQ2ysaUtase24w9u9xuEoSFf9ns= 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.4 041/114] net: mcs7830: handle usb read errors properly Date: Mon, 24 Jan 2022 19:42:16 +0100 Message-Id: <20220124183928.377684769@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183927.095545464@linuxfoundation.org> References: <20220124183927.095545464@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 4f345bd4e6e29..95151b46f2001 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