Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1776228pxp; Mon, 7 Mar 2022 02:03:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJwyZ6L8ouDRBvxjQdz2ePSorAeIzhdq4+Kk+4W+AYyh7+tX6+hGgAGHWFf/+8a4Ia7mOj3/ X-Received: by 2002:a17:907:97c5:b0:6da:c285:44f5 with SMTP id js5-20020a17090797c500b006dac28544f5mr8482341ejc.208.1646647409028; Mon, 07 Mar 2022 02:03:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646647409; cv=none; d=google.com; s=arc-20160816; b=RJjMGqJa1glHBFWlpvvvNm/3ZgYiau9p6FaKo+r6T97F6tOwzWESEv4txQzNDa1kKf byA5InOsS1FcEXIT9Po0JkBjff+9LjGYvMdOUL444kTc+azOCZRiquJl9rndB2+MltPQ UAJ00cHY6CZEeoYXsw2aD8UXbsWbN9ihujqwGRc16Lm4kTKBRUtYubDH3BKmcjSFggdi 6owbXwbR1ml5dVg3nZbtvsv8geCUvQUlUh4nsyMOL4KxnbuHiDyPDkByyC61eXNujfv/ NItSlNKwOFpxO3fiamM6jcI+VxKrJA5xByC8y7uprJECg5k6pqBCXrhLgYQ7nr4OmeFx 657w== 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=7yXFTwAKeH7j9XJJ83srzNe/7xOZDeQCtTh0UR21P5E=; b=iMrF1xxfMavN5kap7f9lQ6Z47SJMoQgZlukUAO/QHiaNSnZRdXquN6YQ0rRo8gqwDi J7kd7akp8MM/eNVUWkPwIUvS+w7f+4BE4HCVUTE2DQiMaR7IGJSq5nKBRk9YH5ETjKxy glCF3zHSZoBwZjxFOXMEAekbmRMog40NlcIsgR8G1ahaILN8Bdh63ztE6duZWcghpriL UYuOJzGi+pBaJu/ZamLLM+oE+S/RSPAx7/J/+wcNPv/Cz6FK712iHJq8skHE1V3YRsNv TKiUQo1Ci0GUj0sO1WK85z41xOmJK7ZogopW0YjO+tJPxtPiuUYZP9hztuNJskYRTx6u 5bKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=m1m6OR+s; 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 f16-20020a0564021e9000b004159ec4d34esi11817668edf.249.2022.03.07.02.03.06; Mon, 07 Mar 2022 02:03:29 -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=m1m6OR+s; 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 S236817AbiCGJZi (ORCPT + 99 others); Mon, 7 Mar 2022 04:25:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50336 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237331AbiCGJXp (ORCPT ); Mon, 7 Mar 2022 04:23:45 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D252B41F9D; Mon, 7 Mar 2022 01:22:44 -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 6BF196112D; Mon, 7 Mar 2022 09:22:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77235C340F3; Mon, 7 Mar 2022 09:22:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646644963; bh=21DyHoJWypXmQyJ2NJWEq5dGsoSvsOayLI1yONg1z8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m1m6OR+sVgJ6O1u9FISdd4AjMFO8o+JZZ/Jw3oXU9urE2AidLJSaNR55N2lu/b5hJ 6SrpXtFX9kASdvUIuQ8t+fkJqL8KaYEg7iNhUe0NuHTj3G/YyJlDfGy8K7h6bQPzAV 9kW4YEE7uw85gnwevKz0EhEdibcQWqf+GF5H2lfg= 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.14 37/42] nl80211: Handle nla_memdup failures in handle_nan_filter Date: Mon, 7 Mar 2022 10:19:11 +0100 Message-Id: <20220307091637.232978926@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091636.146155347@linuxfoundation.org> References: <20220307091636.146155347@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 f630fa2e3164..bbc3c876a5d8 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c @@ -11257,6 +11257,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++; } @@ -11269,6 +11272,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