Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp509056rwe; Wed, 31 Aug 2022 06:36:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR6hxMxJDqW/72mQydJFZQSfX6lOPpAriRydaws/hQd6QSVxuJshGuL7M0BkYWpQR2FohNQK X-Received: by 2002:a63:fb4f:0:b0:42c:a1:43b4 with SMTP id w15-20020a63fb4f000000b0042c00a143b4mr12802900pgj.140.1661952969526; Wed, 31 Aug 2022 06:36:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661952969; cv=none; d=google.com; s=arc-20160816; b=IQekqfbCjK6rTsXy0GpYiqqEwiihDRdSe8/yWRnm88vqITT6vr1XZjX4VmDPzQ5c65 1RxyanEIQWJ6lU0kOi72Kadz+VC7NVEA/ABisb/fdd2hVv/wtG5HTbCEm4k0KSRo4eew va7SRxhkSbU7NVKGuG6DPv7bJw4/GHEWfypLDN1BOc+9xlQtKut5nX36r9g1NdAMPH1/ 3pn96KVOjDYkMsBkyAtwDsJ1IUKeXHFzXzQdC6u5cikTcdn8cD3gl7nSJce8xqZR3Saz zM8FnmpWHiLgNnJ4ijKqNPSqbHTWMbWXUoGNi48WzOVHkH6aFjpyCZEQXV9gpk7YhpQj yHaQ== 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 :message-id:date:subject:cc:to:from; bh=wTeG4lIRye+nVQw/jkrR+T71nLTpwjAOkS66Ay0+LH0=; b=az2v59IfgZK0/T49h/JrEqNbwBHym/J4pZm5BcUiaojZCN3S7MaYhUmwTmtaxCzek1 N6WvysWmYamO4D/Lp2FhtoJa3K7rf8ebpuZvGH1cmIssJsc3CS8dtW0AY7o5u6ST8Tia gWAPZ0ruVgCq2KMUFzsj5jufURw7q9f281i8Pyeuu11RKKDOJ95MJlgxQ1GFI1FKK+8k kcap+BfODlBREtc45qnod4BfXzlPz49H1ST8lR+AhiZ4QGAU5z5wrzIPcx5lZq8JDX+y JRs/9CWW6Qp+54/edgFX/cI1zn+zJ7nSNBxrEFKUS/roNXmk6//jiqQH39DbO1n1GuQP 0g8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n47-20020a056a000d6f00b0052c81ce0adasi5098412pfv.175.2022.08.31.06.35.54; Wed, 31 Aug 2022 06:36:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231356AbiHaNaE (ORCPT + 64 others); Wed, 31 Aug 2022 09:30:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbiHaNaD (ORCPT ); Wed, 31 Aug 2022 09:30:03 -0400 X-Greylist: delayed 402 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 31 Aug 2022 06:29:59 PDT Received: from giacobini.uberspace.de (giacobini.uberspace.de [185.26.156.129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D4C31A3B6 for ; Wed, 31 Aug 2022 06:29:57 -0700 (PDT) Received: (qmail 15005 invoked by uid 990); 31 Aug 2022 13:23:14 -0000 Authentication-Results: giacobini.uberspace.de; auth=pass (plain) From: Soenke Huster To: Johannes Berg , Kalle Valo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Soenke Huster , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] wifi: mac80211_hwsim: check length for virtio packets Date: Wed, 31 Aug 2022 15:22:06 +0200 Message-Id: <20220831132205.129922-1-soenke.huster@eknoes.de> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Bar: / X-Rspamd-Report: R_MISSING_CHARSET(0.5) MIME_GOOD(-0.1) MID_CONTAINS_FROM(1) BAYES_HAM(-0.616589) X-Rspamd-Score: 0.78341 Received: from unknown (HELO unkown) (::1) by giacobini.uberspace.de (Haraka/2.8.28) with ESMTPSA; Wed, 31 Aug 2022 15:23:14 +0200 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, MSGID_FROM_MTA_HEADER,RCVD_IN_DNSWL_NONE,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-wireless@vger.kernel.org An invalid packet with a length shorther than the specified length in the netlink header can lead to use-after-frees and slab-out-of-bounds in the processing of the netlink attributes, such as the following: BUG: KASAN: slab-out-of-bounds in __nla_validate_parse+0x1258/0x2010 Read of size 2 at addr ffff88800ac7952c by task kworker/0:1/12 Workqueue: events hwsim_virtio_rx_work Call Trace: dump_stack_lvl+0x45/0x5d print_report.cold+0x5e/0x5e5 kasan_report+0xb1/0x1c0 __nla_validate_parse+0x1258/0x2010 __nla_parse+0x22/0x30 hwsim_virtio_handle_cmd.isra.0+0x13f/0x2d0 hwsim_virtio_rx_work+0x1b2/0x370 process_one_work+0x8df/0x1530 worker_thread+0x575/0x11a0 kthread+0x29d/0x340 ret_from_fork+0x22/0x30 Discarding packets with an invalid length solves this. Therefore, skb->len must be set at reception. Signed-off-by: Soenke Huster --- drivers/net/wireless/mac80211_hwsim.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c index 4fb8f68e5c3b..6bd9bd50071e 100644 --- a/drivers/net/wireless/mac80211_hwsim.c +++ b/drivers/net/wireless/mac80211_hwsim.c @@ -5436,6 +5436,10 @@ static int hwsim_virtio_handle_cmd(struct sk_buff *skb) nlh = nlmsg_hdr(skb); gnlh = nlmsg_data(nlh); + + if (skb->len < nlh->nlmsg_len) + return -EINVAL; + err = genlmsg_parse(nlh, &hwsim_genl_family, tb, HWSIM_ATTR_MAX, hwsim_genl_policy, NULL); if (err) { @@ -5478,7 +5482,8 @@ static void hwsim_virtio_rx_work(struct work_struct *work) spin_unlock_irqrestore(&hwsim_virtio_lock, flags); skb->data = skb->head; - skb_set_tail_pointer(skb, len); + skb_reset_tail_pointer(skb); + skb_put(skb, len); hwsim_virtio_handle_cmd(skb); spin_lock_irqsave(&hwsim_virtio_lock, flags); -- 2.37.3