Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2126262rdb; Mon, 9 Oct 2023 13:33:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHGTgMy5LJH+5jkGKVOraGabyij3jkBxG4RlbDC8vTB86A7b/haZcxh3Z75ajS150aFNPs8 X-Received: by 2002:a17:902:ecc9:b0:1c1:f15c:976f with SMTP id a9-20020a170902ecc900b001c1f15c976fmr15962937plh.26.1696883603480; Mon, 09 Oct 2023 13:33:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696883603; cv=none; d=google.com; s=arc-20160816; b=KegLDfsd6ObJl+17CpTugRYzy6Z9SnhIC3gtds54YfyzUXHe3YLXKVAujfhrR3R/sL wVTq/omHQSuSRHVGm1d2L7frBbhK31bTrJNhAPXYebaN8ifMGU2HjJOpVPI0gWI9Atgy dVHuuT5XJdiN08jF+0G+9ABwrao6t4y2WZt/WcaoUGUVBwqn6iiZ96t6M/OUyzzbY8v9 jXaGgMeXd8TQ47Kb3vdu5aYcKxvUIDP7Q1LvvH47OP8A+MsglVGvEvaW/SJ2VVUJD7bD Urc2qlOgV8Cs7NgRww88I+9e6/G1Bfr3D0gqXaNyQsg9tz/mU2rHLXkxKPlPD8J/PSx1 S30A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=kxVhA3iC5cF5Bpjygso+wLdoa0I8qR+aXtKisYTFkO4=; fh=PiEsAZr1QvSANHP3oMeCfRThzCqAEKrJ/1Q2J60fqdQ=; b=UO50J7+yZ8JEt5EpC2KOiM/TgV39DAAbiY2/iCHWFNOVirwUhzj7+toHkwRjeXWysZ ezAIzs/+AwwBtKG0zYPfNmD5ycvsfdoo6Mts+clPYU8YMpqFCW7GirfOIu/wJbrPoOy3 DuNuiMvGmsKlphD88qXxp6B817MMhq8Q1U4fQ5FvkXt8uLllBk6JL3utZwxNEpWGPOb2 0/rtG3EIT9NHqF5QOfqWg0mjpaVZHz2Vj7MNbu7NQbrw8Ert0NipZU2BWYgNvTizFuYV uokydnFNSmcHgqa5Kst8tYsHDs3H9sPKd2cDNPMutmBiOtgz57RpiqWb0oGzu/Mqhr6H L6Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=BDCqxgX5; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id kx3-20020a170902f94300b001bdf225d158si9822212plb.284.2023.10.09.13.33.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 13:33:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=BDCqxgX5; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id E722980BB505; Mon, 9 Oct 2023 13:33:17 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377876AbjJIUdQ (ORCPT + 52 others); Mon, 9 Oct 2023 16:33:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377730AbjJIUdP (ORCPT ); Mon, 9 Oct 2023 16:33:15 -0400 Received: from omta34.uswest2.a.cloudfilter.net (omta34.uswest2.a.cloudfilter.net [35.89.44.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E514AA7 for ; Mon, 9 Oct 2023 13:33:13 -0700 (PDT) Received: from eig-obgw-6004a.ext.cloudfilter.net ([10.0.30.197]) by cmsmtp with ESMTP id pvyXqi0ANnGhUpwwDqhWX1; Mon, 09 Oct 2023 20:33:13 +0000 Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with ESMTPS id pwwCq7GNgEMIFpwwCqv77q; Mon, 09 Oct 2023 20:33:13 +0000 X-Authority-Analysis: v=2.4 cv=KY3BDCUD c=1 sm=1 tr=0 ts=65246389 a=1YbLdUo/zbTtOZ3uB5T3HA==:117 a=WzbPXH4gqzPVN0x6HrNMNA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=bhdUkHdE2iEA:10 a=wYkD_t78qR0A:10 a=VwQbUJbxAAAA:8 a=_Wotqz80AAAA:8 a=ChtT1rbVDKAm23ceNSMA:9 a=QEXdDO2ut3YA:10 a=AjGcO6oz07-iQ99wixmX:22 a=buJP51TR1BpY-zbLSsyS:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=kxVhA3iC5cF5Bpjygso+wLdoa0I8qR+aXtKisYTFkO4=; b=BDCqxgX5mHTlxmoSawnMTQPioU x9gE69dpbf0AoFnqb2FawoK+ktCWQuSYHRJ/2153sjUeTW7sy/+e985SeviIrRNc51IX2U9Qw8ZiP QEmTnerYBSWt3XBaLFEpJnEqZ0kuRYBSnxIsO76fKJ67WNxZR/8H8TfeMP+IE1WYzxiEz8XddM1wx tO4h1cds4iwHygj9stQw0HPfbasaSOGLVwMxA6CD0y0ot1dl+XXtSya1suWmesPIgGrwALQshpBmR 5A4AO149tqY4yiJG13smvQBxEykXjXM3LvoUZfDgKiEbpDzVqw+FMFAM3cJD+M6KMHhlYXhy/4jfi NuueI7xg==; Received: from 187-162-21-192.static.axtel.net ([187.162.21.192]:46948 helo=[192.168.15.7]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96.1) (envelope-from ) id 1qpwwB-000iUk-1l; Mon, 09 Oct 2023 15:33:12 -0500 Message-ID: <169f782e-9cc4-49bc-9618-ca6acc526e37@embeddedor.com> Date: Mon, 9 Oct 2023 14:33:01 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH][next] hostap: Add __counted_by for struct prism2_download_data and use struct_size() Content-Language: en-US To: Kees Cook , "Gustavo A. R. Silva" Cc: Kalle Valo , linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <202310091253.665A9C9@keescook> From: "Gustavo A. R. Silva" In-Reply-To: <202310091253.665A9C9@keescook> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 187.162.21.192 X-Source-L: No X-Exim-ID: 1qpwwB-000iUk-1l X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 187-162-21-192.static.axtel.net ([192.168.15.7]) [187.162.21.192]:46948 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 3 X-Org: HG=hgshared;ORG=hostgator; X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfDJN9W/mFM2QDm+Bo+0xVQoZVzg9C34Wp5HnvC23J43VojVRUmTh153mY3l+v7JbAAEyT2VPajJZSeGTjZGKPy2+F8eGBtMh82QqIdoFAB5ctGWu1mCC vB7zd4RBmLef770ZosNbtL16B1M+QXVB6O4EAcKtOrXVa3GXi3YdoHHYFg7JGiakOO9S4qYi51+mPIZXuYEYLDm2m6Yv8b1RNwNm7ggjayaIs9XTz7KVhRH3 X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 09 Oct 2023 13:33:18 -0700 (PDT) X-Spam-Level: *** On 10/9/23 21:54, Kees Cook wrote: > On Mon, Oct 09, 2023 at 01:41:18PM -0600, Gustavo A. R. Silva wrote: >> Prepare for the coming implementation by GCC and Clang of the __counted_by >> attribute. Flexible array members annotated with __counted_by can have >> their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for >> array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family >> functions). >> >> While there, use struct_size() helper, instead of the open-coded >> version, to calculate the size for the allocation of the whole >> flexible structure, including of course, the flexible-array member. >> >> This code was found with the help of Coccinelle, and audited and >> fixed manually. >> >> Signed-off-by: Gustavo A. R. Silva >> --- >> drivers/net/wireless/intersil/hostap/hostap_download.c | 3 +-- >> drivers/net/wireless/intersil/hostap/hostap_wlan.h | 2 +- >> 2 files changed, 2 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/net/wireless/intersil/hostap/hostap_download.c b/drivers/net/wireless/intersil/hostap/hostap_download.c >> index 3672291ced5c..5e5bada28b5b 100644 >> --- a/drivers/net/wireless/intersil/hostap/hostap_download.c >> +++ b/drivers/net/wireless/intersil/hostap/hostap_download.c >> @@ -732,8 +732,7 @@ static int prism2_download(local_info_t *local, >> goto out; >> } >> >> - dl = kzalloc(sizeof(*dl) + param->num_areas * >> - sizeof(struct prism2_download_data_area), GFP_KERNEL); >> + dl = kzalloc(struct_size(dl, data, param->num_areas), GFP_KERNEL); >> if (dl == NULL) { >> ret = -ENOMEM; >> goto out; >> diff --git a/drivers/net/wireless/intersil/hostap/hostap_wlan.h b/drivers/net/wireless/intersil/hostap/hostap_wlan.h >> index c25cd21d18bd..f71c0545c0be 100644 >> --- a/drivers/net/wireless/intersil/hostap/hostap_wlan.h >> +++ b/drivers/net/wireless/intersil/hostap/hostap_wlan.h >> @@ -617,7 +617,7 @@ struct prism2_download_data { >> u32 addr; /* wlan card address */ >> u32 len; >> u8 *data; /* allocated data */ >> - } data[]; >> + } data[] __counted_by(num_areas); >> }; > > Should this be considered a v2 of: > https://lore.kernel.org/linux-hardening/94848cc3-6f5c-46d7-8cc7-98a4f10865b3@embeddedor.com/ > > ? Oops... sorry, I forgot I had reviewed this patch of yours. > > Yours is more complete since it includes the struct_size() change... > Should I resend this explicitly marking it as a v2? -- Gustavo