Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp5608309rwb; Wed, 21 Sep 2022 09:58:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4I9ZeF8yz//C9RY38OigIPXPjpLtLnmv6DHMDLwW7zp6RjSho2R7ZOt3+BJAEdIC9IpwKY X-Received: by 2002:a17:903:1249:b0:178:639a:1ab1 with SMTP id u9-20020a170903124900b00178639a1ab1mr5721590plh.64.1663779483574; Wed, 21 Sep 2022 09:58:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663779483; cv=none; d=google.com; s=arc-20160816; b=0CqnxyS0Mlx0sstM5gR4MnBQne+5I4HzMa+lD5XZtv/v56J4JU+s/FpYH/6ba4rJhw KLQEi8AeMYDHF4Ed8LEMvFwAJ1O0FtN/NgESiqjU7/k8A5Qu5PyUP3u2E2kJLNx8TmVy 7BvXVypTMP7OFo0/nGh1e9F6BLczO6BBVkCfpD8JdPrafsQiLogeuVwLhv9xj+IsebFj vap7gZdvBnQgBW78gV+1tqcY5zDxPbq5WCiEUbbg1WcF4tgHZJCYaTZPxtqoe1fxDZbx pVS6jC9SCmBmdFAx1eJ3fv//gKbl/t+82KlO+nM1gxZgyVLjO40U8njmfqBCuhiB/a+m OErw== 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=zBoRUIZv83cHgBn4512PZ8ZclRMuB5oLyzWPCaic2tw=; b=tMbctkLzaDhJjpZNcvG9lgi222etGgG1LTw6452yEO2luv6ldRbhyvqh2j6rlB/oIl LhYwRqRGacH7MUPSSlAui5zin3TV4wpVMxQYsMwA6g6m0PfE8zWd4vTrceiPVPSsAYwu Oq98jXpl5zfv+P9E89OnQgJCBMLC7MJ8p7QFD1iAWlRgpFjPhj9Sb6iG3kIyq8Xe++/2 WdlW5zwNGOQfduudE4bKLa6znB+Nm/v4oisn/dy/ek4RMwVBqAR+qmoSfJAsSnekXqI9 dOcHTfAynbLXDGSZPsSpijjFoL0hSYgvS9tGIUMTKbS4Hz1WRHtp54SsBvoJwhKsXJxX 16Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Pn5ScKly; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k9-20020aa78209000000b00538517f7ddasi2925686pfi.308.2022.09.21.09.57.52; Wed, 21 Sep 2022 09:58:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Pn5ScKly; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231960AbiIUP4a (ORCPT + 99 others); Wed, 21 Sep 2022 11:56:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231956AbiIUPza (ORCPT ); Wed, 21 Sep 2022 11:55:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0C879E6A7; Wed, 21 Sep 2022 08:50:33 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 3E765B81F98; Wed, 21 Sep 2022 15:50:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91892C433C1; Wed, 21 Sep 2022 15:50:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663775431; bh=WMzitYfYBWadqXg5FMoTpnzZqBxH9vZuDBnwbQfrJ8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Pn5ScKly6wpv5R+z05/7iNiF1nZWs0GutVkKJ6g6Wrkn1lfsA4MylUzr8FAtLi1jG MXFTBzJqehj8vevsOo6dMa2jFZRJqDP0n8zdFVWeaK2hjLwQGwVvgST+eqmEnvEMe6 r3yYksWGNGxAC4sTHRfdJS8f/Hplf/UiOyXhHRe8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Soenke Huster , Johannes Berg , Sasha Levin Subject: [PATCH 5.15 33/45] wifi: mac80211_hwsim: check length for virtio packets Date: Wed, 21 Sep 2022 17:46:23 +0200 Message-Id: <20220921153648.008041129@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220921153646.931277075@linuxfoundation.org> References: <20220921153646.931277075@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-kernel@vger.kernel.org From: Soenke Huster [ Upstream commit 8c0427842aaef161a38ac83b7e8d8fe050b4be04 ] An invalid packet with a length shorter 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. Change-Id: Ieaeb9a4c62d3beede274881a7c2722c6c6f477b6 Signed-off-by: Soenke Huster Signed-off-by: Johannes Berg Signed-off-by: Sasha Levin --- 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 feddf4045a8c..52a2574b7d13 100644 --- a/drivers/net/wireless/mac80211_hwsim.c +++ b/drivers/net/wireless/mac80211_hwsim.c @@ -4278,6 +4278,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) { @@ -4320,7 +4324,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.35.1