Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3707627pxb; Mon, 24 Jan 2022 15:58:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJytuLmVJCuZjhxHH79AaVTjaN9R8fAmfldkTojtjGgpkl6eBmXFhSM+sP57BnjQP/TySRpl X-Received: by 2002:a17:902:bb87:b0:148:a2e8:2798 with SMTP id m7-20020a170902bb8700b00148a2e82798mr15737683pls.159.1643068691643; Mon, 24 Jan 2022 15:58:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643068691; cv=none; d=google.com; s=arc-20160816; b=HSA+mePxwjv+3myQE3/+mGzzuk5/obXcHq+BdPJ1MH9ygdM3KoC/ePMZRy5jwi5xGr LgGR7G8+CC2vyax/Brb633ejVI7c29MI4AmdA50gqhbc9eOun+vdjdt1xcj4o6kcv0Lz N9Zw/4w7lTfeWRjWjPaPnTvpOz95xxUbkB8eMhj/x3f76b+TjJB9/MTQ7f4MHKrrV22n 37n1naGqnQwpzXqeInbA/Cp2WKYA688FS2r8+3jlmPo6p+3D783VAmDRhEpG0sCQi+ir 8HD11B0FvMSVTpIf7fDnT7Ndmrns2UL2VAuuqi+/IFh3nlVLJMxdRkOeEcYsdOLe34Kq XryQ== 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=7MryKuR9TDbkfYppPn2yTkWGc9x3baMtdqOLSp/DhW4=; b=LmV1vRIuPg/GLn+SpiwZFAti03DavYTfjg+NzDON4dfXDhP6Y1nURvUN6pYwjLQ4MC itAqo3jN0dNl2hQCL3FXTjCnyejq/2Z2zu5aT2oI0kwfddGX7L/by/3L/mOjNUTxc/5X BqnTFz2pXamM2Drxt8orJQNnDwVb9qI367y5Ag8F+ROYG3EJMNj9FRfZgNuDxWoO0qD+ S4D6KUHQbQ0z6G8ykDOPhR/P8QocCeL8IcdoczqTYQckonaCHElL4Z08gRpYBsF+ovDx JB3m5WSFgqrQY+KAgekPbXlRkCIPVrc7V3mQPSPrYfPPRQryrqcq7lqApmyOIbaYBgCD 5BIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Bxn8PyKZ; 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 u184si3728948pgd.569.2022.01.24.15.57.59; Mon, 24 Jan 2022 15:58:11 -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=Bxn8PyKZ; 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 S2366944AbiAXXxt (ORCPT + 99 others); Mon, 24 Jan 2022 18:53:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1846108AbiAXXO1 (ORCPT ); Mon, 24 Jan 2022 18:14:27 -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 44D7BC061760; Mon, 24 Jan 2022 13:23:07 -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 D6DD5611C8; Mon, 24 Jan 2022 21:23:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB83DC340E4; Mon, 24 Jan 2022 21:23:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059386; bh=tgMxk0poZY5zYAaPiVwW6ZLGXckdFm/KF9btJSEKfHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bxn8PyKZiRnSD0X41YCrwGyaXHgjXFJg7/Mo6+8o3fgjI4ZvmEyng0JpwfrI9E37C R8x4c+WZAcJNI5UYfEs99JSr9H4uIjZFfD68lPe4TeDRe+tHDEb9S+2jflxoebpwEA GLbw/G18vZkIdaYOqQscQND07U3WfrDRDpOEMzAw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brendan Dolan-Gavitt , Zekun Shen , Kalle Valo , Sasha Levin Subject: [PATCH 5.16 0599/1039] rsi: Fix out-of-bounds read in rsi_read_pkt() Date: Mon, 24 Jan 2022 19:39:48 +0100 Message-Id: <20220124184145.480831077@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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: Zekun Shen [ Upstream commit f1cb3476e48b60c450ec3a1d7da0805bffc6e43a ] rsi_get_* functions rely on an offset variable from usb input. The size of usb input is RSI_MAX_RX_USB_PKT_SIZE(3000), while 2-byte offset can be up to 0xFFFF. Thus a large offset can cause out-of-bounds read. The patch adds a bound checking condition when rcv_pkt_len is 0, indicating it's USB. It's unclear whether this is triggerable from other type of bus. The following check might help in that case. offset > rcv_pkt_len - FRAME_DESC_SZ The bug is trigerrable with conpromised/malfunctioning USB devices. I tested the patch with the crashing input and got no more bug report. Attached is the KASAN report from fuzzing. BUG: KASAN: slab-out-of-bounds in rsi_read_pkt+0x42e/0x500 [rsi_91x] Read of size 2 at addr ffff888019439fdb by task RX-Thread/227 CPU: 0 PID: 227 Comm: RX-Thread Not tainted 5.6.0 #66 Call Trace: dump_stack+0x76/0xa0 print_address_description.constprop.0+0x16/0x200 ? rsi_read_pkt+0x42e/0x500 [rsi_91x] ? rsi_read_pkt+0x42e/0x500 [rsi_91x] __kasan_report.cold+0x37/0x7c ? rsi_read_pkt+0x42e/0x500 [rsi_91x] kasan_report+0xe/0x20 rsi_read_pkt+0x42e/0x500 [rsi_91x] rsi_usb_rx_thread+0x1b1/0x2fc [rsi_usb] ? rsi_probe+0x16a0/0x16a0 [rsi_usb] ? _raw_spin_lock_irqsave+0x7b/0xd0 ? _raw_spin_trylock_bh+0x120/0x120 ? __wake_up_common+0x10b/0x520 ? rsi_probe+0x16a0/0x16a0 [rsi_usb] kthread+0x2b5/0x3b0 ? kthread_create_on_node+0xd0/0xd0 ret_from_fork+0x22/0x40 Reported-by: Brendan Dolan-Gavitt Signed-off-by: Zekun Shen Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/YXxXS4wgu2OsmlVv@10-18-43-117.dynapool.wireless.nyu.edu Signed-off-by: Sasha Levin --- drivers/net/wireless/rsi/rsi_91x_main.c | 4 ++++ drivers/net/wireless/rsi/rsi_91x_usb.c | 1 - drivers/net/wireless/rsi/rsi_usb.h | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/rsi/rsi_91x_main.c b/drivers/net/wireless/rsi/rsi_91x_main.c index f1bf71e6c6081..5d1490fc32db4 100644 --- a/drivers/net/wireless/rsi/rsi_91x_main.c +++ b/drivers/net/wireless/rsi/rsi_91x_main.c @@ -23,6 +23,7 @@ #include "rsi_common.h" #include "rsi_coex.h" #include "rsi_hal.h" +#include "rsi_usb.h" u32 rsi_zone_enabled = /* INFO_ZONE | INIT_ZONE | @@ -168,6 +169,9 @@ int rsi_read_pkt(struct rsi_common *common, u8 *rx_pkt, s32 rcv_pkt_len) frame_desc = &rx_pkt[index]; actual_length = *(u16 *)&frame_desc[0]; offset = *(u16 *)&frame_desc[2]; + if (!rcv_pkt_len && offset > + RSI_MAX_RX_USB_PKT_SIZE - FRAME_DESC_SZ) + goto fail; queueno = rsi_get_queueno(frame_desc, offset); length = rsi_get_length(frame_desc, offset); diff --git a/drivers/net/wireless/rsi/rsi_91x_usb.c b/drivers/net/wireless/rsi/rsi_91x_usb.c index 3cca1823c458a..66fe386ec9cc6 100644 --- a/drivers/net/wireless/rsi/rsi_91x_usb.c +++ b/drivers/net/wireless/rsi/rsi_91x_usb.c @@ -330,7 +330,6 @@ static int rsi_rx_urb_submit(struct rsi_hw *adapter, u8 ep_num, gfp_t mem_flags) struct sk_buff *skb; u8 dword_align_bytes = 0; -#define RSI_MAX_RX_USB_PKT_SIZE 3000 skb = dev_alloc_skb(RSI_MAX_RX_USB_PKT_SIZE); if (!skb) return -ENOMEM; diff --git a/drivers/net/wireless/rsi/rsi_usb.h b/drivers/net/wireless/rsi/rsi_usb.h index 254d19b664123..961851748bc4c 100644 --- a/drivers/net/wireless/rsi/rsi_usb.h +++ b/drivers/net/wireless/rsi/rsi_usb.h @@ -44,6 +44,8 @@ #define RSI_USB_BUF_SIZE 4096 #define RSI_USB_CTRL_BUF_SIZE 0x04 +#define RSI_MAX_RX_USB_PKT_SIZE 3000 + struct rx_usb_ctrl_block { u8 *data; struct urb *rx_urb; -- 2.34.1