Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1777393pxp; Mon, 7 Mar 2022 02:04:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxG73If5pp9nwvrMsvj0cnL4aAe8l/jhoo923G6RxDcDm0DJdjHwAOPJL7NmCv7qZodbSlA X-Received: by 2002:a17:907:3f22:b0:6d7:8257:b27d with SMTP id hq34-20020a1709073f2200b006d78257b27dmr8126952ejc.190.1646647496759; Mon, 07 Mar 2022 02:04:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646647496; cv=none; d=google.com; s=arc-20160816; b=tk/E16CGMqU9vKngLO77u9G+oVih2MuM1LT11zkxALHfjr4FqV7x8Bd1aXa4KVCb1x 2H1ehmSibeNPQdNiaOTj0kSkSPX8SGYXYGsT3pKmfvzQjnnIWRO+WfzZpIyN95jVTJaB UBEkNUACWCCeURDne9uZZ54FZX0GC6bKm8x/DIDhX9G4BRkwozsjv6RFy/fxO9E3Npzu zF6HjcCTFZgUPvNQfhUm9aK6p/lIThnDtlQtMWJswJ+Nw+ELteW6moOmuCezWzTMtLRj 52W7raiKaRE8NZ/NazPImRWhBAXbqeVAVwTn4GCjlOY9uJ/poU12f/slJ4ZKZDLsIEyV fxag== 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=8lgHK4fISiMhlkQvDx3dNPNjekqj1f4LmeVlkx6EM4s=; b=Uad606MmKAAafl/kfraqkZpNq7KXB7h+2YMi3JgaMrQGIYu0lDk3ygHnBQVLL3vIkg 8o/mGAzS0FLEQGu7WW7lckoQOdyM3NrIfTwDgnaYWSWuR2Z5SwewQQtSQkVYftoq5YP8 T7/RNkfqwJ8ywAtBLe1AfmQERWrTxQzw1+XZKkzqbicOZpG+nTMRGVTuPYuPI/dfIa6o PdI9ODrVkwseqKzgbOcBbDBt2hq1Btk7y+n9ecXlZl1NotrEh4bwHhDMlXmn7wmONX2Y 1xNBNKfR5izFMRMbXzNWLe3U3hDb6E+v+1wxhBsuTvR4HaQh9SIeNabCvd1UpGC2pUxK lS2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rp+a5kW1; 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 dy25-20020a05640231f900b0041644faef40si1874139edb.236.2022.03.07.02.04.33; Mon, 07 Mar 2022 02:04:56 -0800 (PST) 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=rp+a5kW1; 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 S237122AbiCGJaz (ORCPT + 99 others); Mon, 7 Mar 2022 04:30:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237385AbiCGJ2D (ORCPT ); Mon, 7 Mar 2022 04:28:03 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BEE25BD1E; Mon, 7 Mar 2022 01:25:20 -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 ams.source.kernel.org (Postfix) with ESMTPS id 077B9B810B2; Mon, 7 Mar 2022 09:25:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42397C340E9; Mon, 7 Mar 2022 09:25:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646645117; bh=ZmDrpSXBxhFbiVSDxHqnr0OkvbLlHZXnWYI54QNgtlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rp+a5kW1MLJytD+dllVRHndVDWbxulxqH/UCP6HtElvgN9Ke5Tt1LEnIJJZA6447e dmFZoHvdQd8uhWydT/pLGybm2p0rRXyuE6YcDuUqAE0tIPhhCyyS3Tq4lzLIhgMPYl rJYv4SUbqR5R/J7tyzixx2ZtvI4C4AlVTl8HEIok= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiasheng Jiang , Johannes Berg , Sasha Levin Subject: [PATCH 4.19 44/51] nl80211: Handle nla_memdup failures in handle_nan_filter Date: Mon, 7 Mar 2022 10:19:19 +0100 Message-Id: <20220307091638.244181307@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091636.988950823@linuxfoundation.org> References: <20220307091636.988950823@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 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,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-kernel@vger.kernel.org From: Jiasheng Jiang [ Upstream commit 6ad27f522cb3b210476daf63ce6ddb6568c0508b ] As there's potential for failure of the nla_memdup(), check the return value. Fixes: a442b761b24b ("cfg80211: add add_nan_func / del_nan_func") Signed-off-by: Jiasheng Jiang Link: https://lore.kernel.org/r/20220301100020.3801187-1-jiasheng@iscas.ac.cn Signed-off-by: Johannes Berg Signed-off-by: Sasha Levin --- net/wireless/nl80211.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 04c4fd376e1d..c5806f46f6c9 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -11791,6 +11791,9 @@ static int handle_nan_filter(struct nlattr *attr_filter, i = 0; nla_for_each_nested(attr, attr_filter, rem) { filter[i].filter = nla_memdup(attr, GFP_KERNEL); + if (!filter[i].filter) + goto err; + filter[i].len = nla_len(attr); i++; } @@ -11803,6 +11806,15 @@ static int handle_nan_filter(struct nlattr *attr_filter, } return 0; + +err: + i = 0; + nla_for_each_nested(attr, attr_filter, rem) { + kfree(filter[i].filter); + i++; + } + kfree(filter); + return -ENOMEM; } static int nl80211_nan_add_func(struct sk_buff *skb, -- 2.34.1