Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp251055rdb; Sat, 27 Jan 2024 05:15:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+aPy9AaaauLDeXypI/y0QpJw7aaEg0v8EoK51PZPLk/qEpJhf8v4y0p9YQU4Ocg6ZIWig X-Received: by 2002:a05:6a20:da89:b0:19c:843d:a6e3 with SMTP id iy9-20020a056a20da8900b0019c843da6e3mr1820070pzb.18.1706361332277; Sat, 27 Jan 2024 05:15:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706361332; cv=pass; d=google.com; s=arc-20160816; b=wb58nKtfEvugj3sLhbqdV1xJ9No1whwF61kst9FS3OJndWEYesQ14aQTXUYgVtZecu xYTIODUxD5b3qMa7Tr0tlpUJadgDxg4E9mSUto5XWxxO1ah6EBdQ6IrpkuNx9oa800ty Gna0HNMNzljwZ56ZX+fXR6GccbmP4PyisqXS4EgfI6mG0O7HGqwScfuole4GWUUF0bgj cve7ksnlcLj4agAge2Cv9FGftT91MRZa4G9iysLV40LggYPTrJBXzUyohaDLPPPWq9yO NEurchZ+WBRLtbJuw39ymF+rU+rBrPQwH2/dyRmXPuLM9gai2jhj9YnZ4YZ4jud33A39 MLVQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=ZrazDqdbD6oanZQGLU+I+Chea6nbXarN1I/pTzbmfG4=; fh=545ggk01MUMHVkn0hIdGq1N1Eebc6G80Z1UeH5TF6gU=; b=humKpUyr5rS5GORMz5eDoEjLKCoB6soFCyE/P8x2jqmQLn0dtVfxGBpLxy/rNSZ4n+ vnRDVyBakeh9ljewfOotsHhjVPovLtwkiEMcWhq2UJH59gY6HmN6QRgRPPl//ezcsAFT XjvGr5ACsIorxOjySXIl876nLNZr7dmIGw+LjklNiH98/9qZ9T0Pas1a+CrqqIQYU9Mh JSQlqO1c65RuXfcSct7pX0PMT8lUJGnVkABopoGaQomiw6kfG9gmnOKUEydaqPoRX/QB 3FUxydB16AdRSURWB2Ndv07USXnETYWht5+P9aLetnBd/Ktu1OBn2MjAu+R0FsW5hjd/ bIGw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U79BX+bO; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-41190-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41190-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id p4-20020a056a000b4400b006dd89a2c692si2774238pfo.275.2024.01.27.05.15.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 05:15:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41190-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U79BX+bO; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-41190-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41190-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 320EAB22459 for ; Sat, 27 Jan 2024 13:15:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5609625611; Sat, 27 Jan 2024 13:15:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="U79BX+bO" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 ADDE32557F for ; Sat, 27 Jan 2024 13:15:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706361318; cv=none; b=FBmtcEGBimYbXC3UtJOgPhrIS8Ko913R2S4dTLIZ29BFt0djoF7aXo9O/MUZ1oIJ6tsqXELhFxsFaUvTKIWQ6hl4J8JKG/m9VZeLzX6XjB1F71qVnX9BLuYOciTIyLFYtys9k3mS9z4+pngVHaq1hIUQQfj/pnBU4xj3hWMGMiA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706361318; c=relaxed/simple; bh=Dqdc0+GiMMU9oBgocmuzdAz+2RL5EmpPsPfk0dVDRO0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=AXvmDUU2gr6Z0VslIkK0Et0mfEupzyW2OXt1Z8H5pGhZbsBUC7NsmNT1hhOJbUZ4Kv87PfW5PW2s8omcAxkQluWRdvLbEh30wW8NNqJLjB1RTBYV8+8Ik4rc/RvFDmW9aOO6CCBIHkJAe4BKQsd9jEu4P1xyD0zjA5FzCrhBYUA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=U79BX+bO; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706361315; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZrazDqdbD6oanZQGLU+I+Chea6nbXarN1I/pTzbmfG4=; b=U79BX+bOtnw4mpLk47nGVj9Qnk56vKB2pU6qwHQd1nR45/XflIH/PWkg8I/hv5fEp5rtbl GOCZHSgTIDRSJALGEUthsNUllBXiwubQLaQHXzeQhN2zFv9dUaHMG7Zq4MrzG5Fwmdq60+ rx2fvhmPyfvlHMoyD+OdhKtSDQCud5g= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-383-_xQ5oH9fPR6kh_SAAIO65g-1; Sat, 27 Jan 2024 08:15:13 -0500 X-MC-Unique: _xQ5oH9fPR6kh_SAAIO65g-1 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-51032b2fb9fso140120e87.1 for ; Sat, 27 Jan 2024 05:15:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706361312; x=1706966112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZrazDqdbD6oanZQGLU+I+Chea6nbXarN1I/pTzbmfG4=; b=lDSrogb/kQJS2sH4HhxZ/dxxZ4/smYJuIm24UBpe+nz2MbBl3QQd2Y/hwnwJJUvnvt 1/n6YYHsy6QOgLgUMMhkiGrx8ZSgum3yMP20CyhLJbtLCPMlSxKp5w3ecTOpQPHwjUNb 0lUmtE+fWOz956JHdY4OPRDig70wCbdbOuYRXKTF0ceQ/MGoO/8ieC1FEACijH/LqDdA nomUrufpNsAaoKC0OJWU78eM5uvLDFT/wX8XAvLfHHNtM784MWTP+EiO9U1/xVKOUl7E RltYXMJ4zQyWN3dzGwvFugrOeoZHZzHMMoM0PPomu0WuDZguZJQfsZ049v0ovi5t1ifB LUpA== X-Gm-Message-State: AOJu0YzHNBo/J3+hX8UBXRbLgXXtS5/ZKci7r0e62GmwRM4qGGaJTavd 6r2OBNBQDYuFN34Q+P0UOyS4/hohKJ5GllIb60+NoBYJEOsRw/CZRfa+1TXle2eMOnY7cIKvY8C Fvpb9jlT49riIWv4uwGKUS0lG9mG4O9ZUrBDeIaG/RS7zr9mZ3M8MrgjLf9Aq/A== X-Received: by 2002:ac2:4651:0:b0:50e:6a19:7a38 with SMTP id s17-20020ac24651000000b0050e6a197a38mr840744lfo.20.1706361312461; Sat, 27 Jan 2024 05:15:12 -0800 (PST) X-Received: by 2002:ac2:4651:0:b0:50e:6a19:7a38 with SMTP id s17-20020ac24651000000b0050e6a197a38mr840727lfo.20.1706361312120; Sat, 27 Jan 2024 05:15:12 -0800 (PST) Received: from ?IPV6:2001:1c00:c32:7800:5bfa:a036:83f0:f9ec? (2001-1c00-0c32-7800-5bfa-a036-83f0-f9ec.cable.dynamic.v6.ziggo.nl. [2001:1c00:c32:7800:5bfa:a036:83f0:f9ec]) by smtp.gmail.com with ESMTPSA id hd11-20020a170907968b00b00a31906f280asm1738295ejc.193.2024.01.27.05.15.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 27 Jan 2024 05:15:11 -0800 (PST) Message-ID: <8f225be1-647b-4421-b6b5-a2098f807d05@redhat.com> Date: Sat, 27 Jan 2024 14:15:10 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] wifi: brcmfmac: Adjust n_channels usage for __counted_by Content-Language: en-US, nl To: Kees Cook , Arend van Spriel Cc: Franky Lin , Hante Meuleman , Kalle Valo , Chi-hsien Lin , Ian Lin , Johannes Berg , Wright Feng , Hector Martin , linux-wireless@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com, "Gustavo A. R. Silva" , Linus Walleij , Jisoo Jang , Aloka Dixit , John Keeping , Jeff Johnson , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20240126223150.work.548-kees@kernel.org> From: Hans de Goede In-Reply-To: <20240126223150.work.548-kees@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi, On 1/26/24 23:31, Kees Cook wrote: > After commit e3eac9f32ec0 ("wifi: cfg80211: Annotate struct > cfg80211_scan_request with __counted_by"), the compiler may enforce > dynamic array indexing of req->channels to stay below n_channels. As a > result, n_channels needs to be increased _before_ accessing the newly > added array index. Increment it first, then use "i" for the prior index. > Solves this warning in the coming GCC that has __counted_by support: > > ../drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c: In function 'brcmf_internal_escan_add_info': > ../drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c:3783:46: warning: operation on 'req-> > n_channels' may be undefined [-Wsequence-point] > 3783 | req->channels[req->n_channels++] = chan; > | ~~~~~~~~~~~~~~~^~ > > Fixes: e3eac9f32ec0 ("wifi: cfg80211: Annotate struct cfg80211_scan_request with __counted_by") > Cc: Arend van Spriel > Cc: Franky Lin > Cc: Hante Meuleman > Cc: Kalle Valo > Cc: Chi-hsien Lin > Cc: Ian Lin > Cc: Johannes Berg > Cc: Wright Feng > Cc: Hector Martin > Cc: linux-wireless@vger.kernel.org > Cc: brcm80211-dev-list.pdl@broadcom.com > Signed-off-by: Kees Cook Thanks, patch looks good to me: Reviewed-by: Hans de Goede Regards, Hans > --- > drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c > index 133c5ea6429c..28d6a30cc010 100644 > --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c > +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c > @@ -3779,8 +3779,10 @@ static int brcmf_internal_escan_add_info(struct cfg80211_scan_request *req, > if (req->channels[i] == chan) > break; > } > - if (i == req->n_channels) > - req->channels[req->n_channels++] = chan; > + if (i == req->n_channels) { > + req->n_channels++; > + req->channels[i] = chan; > + } > > for (i = 0; i < req->n_ssids; i++) { > if (req->ssids[i].ssid_len == ssid_len &&