Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1859961rbb; Tue, 27 Feb 2024 03:42:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWE2TZfK5q4etm5eWYT3beL4AKYCCopQLGthVPztL2UkuY6frBKNqYRyJ//MHBoVok4/0AMOQ9WnjU8ObXbWl1moQZSyi65+EN6B+Eczg== X-Google-Smtp-Source: AGHT+IFxncSfoAWMTONy4tEAS1ItE2xZWFKlrCOLJKp7OPl1CubfCMADZcOGMoVXJYHhESeWLvo+ X-Received: by 2002:a62:cec7:0:b0:6e1:dbd:e800 with SMTP id y190-20020a62cec7000000b006e10dbde800mr9283140pfg.17.1709034163071; Tue, 27 Feb 2024 03:42:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709034163; cv=pass; d=google.com; s=arc-20160816; b=LOR+DKtKC72GC/3zAk/aa6Lh5QhZrryXL4SezsUO8OHinwg883D52nNxBTDHZzHRXG CbxgvxgiOK6sUBvGzCbhwfOiv+6Nh5LVo4j57wTjKDX3QFiwfPoWepQ4UQq0HpLCTase fds0LkK2QnWcUBvLvE8QFJSXhs70szRtxGCJ/S47Re8d7f6ZxVUVJ8RA3/KdFd5+xHrO +drlsdMcZ7BjpBy9il987giuOSOqfIi+j4pgnXZgG5+uOjAngLCS0C03X8HtjlzLKiYV vjFdKmsb7WFsQHpjKuQ49PQomUYdhMbGU5xTIWDItFk7yRNhYffwGBZo12Xij1fLQ89j M6FA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id; bh=sbvSCHxxYeBJYOtolTY/Jw5mo+DkbsF3I6ES5WbPJ7E=; fh=TahmSvB2m/2znwHiBs22eBZlp5vJLl1nqP0/xAz53Ak=; b=rIc5RnyotNHdNr0S/NPGmcqG+XYIdfOwkOR9ktYvh77byZ0aJ8rWt0rXiM0kIZ1uzZ 9jVd344jAGoOAiQjAZg3hzk+fSmLa+4F/r/DyWL5MmANHhVm5igyc0t4U+WIERid+L0p HbwgGLi0hhqWiI+s+k7xsSprT0nIwWT4WpCD9kB8eHMAGw6dXFjnAimLvwqrJTQgRs5N Jh4vtf06uoKySuwhmTPAMBkL6hcNN4oAe6fqH9Cv146Pk2sBR8jNMdkBbpoRdVOijFqC vP/DNyGHR9tg8nK3hqnX4+WLen6Z3vMvtq2wQOS8aMTAc9u6GiYvnKm0tj/1bchXdRBj 5C4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=perches.com); spf=pass (google.com: domain of linux-kernel+bounces-83139-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83139-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y2-20020a056a00180200b006e543d6fdcfsi1686538pfa.279.2024.02.27.03.42.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 03:42:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83139-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=perches.com); spf=pass (google.com: domain of linux-kernel+bounces-83139-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83139-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BB8782849EF for ; Tue, 27 Feb 2024 11:42:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E6F913A273; Tue, 27 Feb 2024 11:42:28 +0000 (UTC) Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB62B13958A; Tue, 27 Feb 2024 11:42:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.40.44.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709034147; cv=none; b=ijrPYLQRYg6ApthaiMkC1N7aJaeqS1ZrBNAQtaZWqZ1aA3ATPGWY7kqS8D2QtjKLzwgTcFVlfvgCm7LCHXZ90QnqhVP9mdYnDFVSW1opaWhZ0w2576g9BvbJCzzCwga7mu67Hj2Ntw2/yq3eIYSZ2gRFNBoTYeyMXKzFpSh0fs4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709034147; c=relaxed/simple; bh=ycpsLMGqKQfrLYCH+x1HWi2wiMddtCqg7V3YbCTEAC4=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=od+s689A1CrA/WaBI+7a02F4s8+fIs0CrhC8G4jhY1KN5AtxF4Pph6S+6IMVgQTlltwq8PlPs30Ijs+rZ1rFxXCYfv7EKMtCbFLfpgwS5SaK/r9U/J9A24MtkP8FOQkIrCE8rVUqV/XqXhNWH6SYLw/Qd6/xIGtwXB3FgPxABPM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=perches.com; spf=pass smtp.mailfrom=perches.com; arc=none smtp.client-ip=216.40.44.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=perches.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=perches.com Received: from omf09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E681EA0EEC; Tue, 27 Feb 2024 11:42:17 +0000 (UTC) Received: from [HIDDEN] (Authenticated sender: joe@perches.com) by omf09.hostedemail.com (Postfix) with ESMTPA id 4AD102002A; Tue, 27 Feb 2024 11:42:14 +0000 (UTC) Message-ID: Subject: Re: [PATCH] wifi: brcm80211: handle pmk_op allocation failure From: Joe Perches To: Arend van Spriel , Duoming Zhou , linux-kernel@vger.kernel.org Cc: brcm80211-dev-list.pdl@broadcom.com, brcm80211@lists.linux.dev, linux-wireless@vger.kernel.org, justinstitt@google.com, john@keeping.me.uk, quic_alokad@quicinc.com, marcan@marcan.st, johannes.berg@intel.com, linus.walleij@linaro.org, kvalo@kernel.org Date: Tue, 27 Feb 2024 03:42:13 -0800 In-Reply-To: <87166784-79ab-4eb4-ad1e-af4bc31757b7@broadcom.com> References: <20240227080613.34001-1-duoming@zju.edu.cn> <87166784-79ab-4eb4-ad1e-af4bc31757b7@broadcom.com> Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4AD102002A X-Stat-Signature: edoqsgf7ic6us6cah63pub7niog877mg X-Rspamd-Server: rspamout01 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Session-ID: U2FsdGVkX1/WU0+q9CP9YB3iZf4lKGg5gQDCP5sOEeA= X-HE-Tag: 1709034134-96182 X-HE-Meta: U2FsdGVkX19TCIOBunB/trdZTRgi6R4E3PcqVCwEybxKePZ9o1W7it2/qFbLqYIs53EHyYYfFl8x0B7R0mINy3zRdpVuP62lhcb9V7LUa22u8kjylexBvXmWH/ecs+KGvdffoGc3N21S68SK05i+3sCg4yJKblnZZTtR9y3ZFxqx/XrR2Fx8zpCVrwxACFBpbGXXmULsj5PWzCO+8qQ4Sf5JJkE5OuwhWad6Y21UZJOdYOUuHe1DnpGQYM0ZOzykoLlS5HlC4zSAApnXrYm04btVQnyvH/v0N3YQ+i4aW6ciBJ22DDCTQgzDCFICBj+o On Tue, 2024-02-27 at 12:21 +0100, Arend van Spriel wrote: > On 2/27/2024 9:06 AM, Duoming Zhou wrote: > > The kzalloc() in brcmf_pmksa_v3_op() will return null if the > > physical memory has run out. As a result, if we dereference > > the null value, the null pointer dereference bug will happen. > >=20 > > Return -ENOMEM from brcmf_pmksa_v3_op() if kzalloc() fails > > for pmk_op. >=20 > NAK (see below) >=20 > Also this issue was reported earlier by Joe Perches. Not sure if he=20 > wants to be mentioned as such. I think it's unimportant to be mentioned. I think it's more important that the code be researched that the simple return of -ENOMEM the appropriate fix and is handled by all possible callers of the function. >=20 > > Fixes: a96202acaea4 ("wifi: brcmfmac: cfg80211: Add support for PMKID_V= 3 operations") > > Signed-off-by: Duoming Zhou > > --- > > drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 5 +++++ > > 1 file changed, 5 insertions(+) > >=20 > > diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.= cq b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c > > index 28d6a30cc01..3b420b33188 100644 > > --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c > > +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c > > @@ -4322,6 +4322,10 @@ brcmf_pmksa_v3_op(struct brcmf_if *ifp, struct c= fg80211_pmksa *pmksa, > > int ret; > > =20 > > pmk_op =3D kzalloc(sizeof(*pmk_op), GFP_KERNEL); > > + if (!pmk_op) { > > + ret =3D -ENOMEM; > > + goto out; > > + } >=20 > There is really no need to introduce a new label for this. Although you= =20 > can kfree() a NULL pointer there is no need to do so when you know=20 > already it is NULL. Just return -ENOMEM and be done with it. >=20 > Regards, > Arend >=20 > > pmk_op->version =3D cpu_to_le16(BRCMF_PMKSA_VER_3); > > =20 > > if (!pmksa) { > > @@ -4340,6 +4344,7 @@ brcmf_pmksa_v3_op(struct brcmf_if *ifp, struct cf= g80211_pmksa *pmksa, > > pmk_op->length =3D cpu_to_le16(length); > > =20 > > ret =3D brcmf_fil_iovar_data_set(ifp, "pmkid_info", pmk_op, sizeof(*= pmk_op)); > > +out: > > kfree(pmk_op); > > return ret; > > }