From patchwork Tue May 16 15:04:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Fedor Pchelkin X-Patchwork-Id: 682893 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D23AC77B7A for ; Tue, 16 May 2023 15:04:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233577AbjEPPEs (ORCPT ); Tue, 16 May 2023 11:04:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233106AbjEPPEm (ORCPT ); Tue, 16 May 2023 11:04:42 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69BA35B80; Tue, 16 May 2023 08:04:40 -0700 (PDT) Received: from fpc.. (unknown [46.242.14.200]) by mail.ispras.ru (Postfix) with ESMTPSA id 120DC40737D7; Tue, 16 May 2023 15:04:37 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 120DC40737D7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1684249477; bh=sZ8kkT2TGWjUcst/Jgp8zQv5admnxY/XlfH+0rjhVWY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PZW38xBv9YAKyWUNlJmGaX05OwbSKR+p9YK4imq8ULOPNbmusdvStSlQcMMaSgtoB V9NsgMKaJyiAsyZX2d43eIs0ZzsdGjAPeLeQXiWb32r68tRCbwyTs/cAuukSD0Dm71 4C9zKY5MKF8FMSuY86+egeIDyCdQVn9Xw451cvo8= From: Fedor Pchelkin To: =?utf-8?q?Toke_H=C3=B8iland-J=C3=B8rgensen?= Cc: Fedor Pchelkin , Kalle Valo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Takeshi Misawa , Alexey Khoroshilov , lvc-project@linuxtesting.org, syzbot+b68fbebe56d8362907e8@syzkaller.appspotmail.com Subject: [PATCH v2] wifi: ath9k: don't allow to overwrite ENDPOINT0 attributes Date: Tue, 16 May 2023 18:04:27 +0300 Message-Id: <20230516150427.79469-1-pchelkin@ispras.ru> X-Mailer: git-send-email 2.34.1 In-Reply-To: <87r0rhdc46.fsf@toke.dk> References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org A bad USB device is able to construct a service connection response message with target endpoint being ENDPOINT0 which is reserved for HTC_CTRL_RSVD_SVC and should not be modified to be used for any other services. Reject such service connection responses. Found by Linux Verification Center (linuxtesting.org) with Syzkaller. Fixes: fb9987d0f748 ("ath9k_htc: Support for AR9271 chipset.") Reported-by: syzbot+b68fbebe56d8362907e8@syzkaller.appspotmail.com Signed-off-by: Fedor Pchelkin Acked-by: Toke Høiland-Jørgensen --- v2: per Toke's remark, use ENDPOINT0 macro and give a comment explaining why it should be checked. drivers/net/wireless/ath/ath9k/htc_hst.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath9k/htc_hst.c b/drivers/net/wireless/ath/ath9k/htc_hst.c index fe62ff668f75..99667aba289d 100644 --- a/drivers/net/wireless/ath/ath9k/htc_hst.c +++ b/drivers/net/wireless/ath/ath9k/htc_hst.c @@ -114,7 +114,13 @@ static void htc_process_conn_rsp(struct htc_target *target, if (svc_rspmsg->status == HTC_SERVICE_SUCCESS) { epid = svc_rspmsg->endpoint_id; - if (epid < 0 || epid >= ENDPOINT_MAX) + + /* Check that the received epid for the endpoint to attach + * a new service is valid. ENDPOINT0 can't be used here as it + * is already reserved for HTC_CTRL_RSVD_SVC service and thus + * should not be modified. + */ + if (epid <= ENDPOINT0 || epid >= ENDPOINT_MAX) return; service_id = be16_to_cpu(svc_rspmsg->service_id);