Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2104734rdb; Mon, 9 Oct 2023 12:41:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF0pnFELnWxjKzg3EdqxyJ1RJQq27hlHFfer+MA1HvxgP3msw6lJCsfLBE+rKzTX1eawzRL X-Received: by 2002:a17:902:c20c:b0:1c5:f5a9:4ad6 with SMTP id 12-20020a170902c20c00b001c5f5a94ad6mr12978833pll.1.1696880499228; Mon, 09 Oct 2023 12:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696880499; cv=none; d=google.com; s=arc-20160816; b=T+0ckxzheWxVTnbB2eLLZVB1OvF+ZX+NbgzjDUCamIm/sPpfJF3RHOSTj2d4/gLiUB H60Ew17SyHVpS/bxky2pToOrHLMomYGb4oeMCvkWrLWUehbNA73HvZyMW4eNDGZ9Q+ZX Y2MQJjyBXbrvToTGXI4IR8vi0paw9DOcHKcgVXneHLS80817VfquNJ0u+8nG4b6hAs12 to9A5Gn1Rj2modN/2/I8AdQQsLY+7z9lbxnDByAtyXkKcqkGuUJ73SW82ExamFJyjANy zHj9UBHXflhxJhxdIheMP7EIr4rdj02CU7ataR2YbTIFTsY6KFIJaTSUWYPEeDLEOUQu vLDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=pi378Wr/cbhjQzGUziB8omxSpuf1Y/bdgaG1EwVHo9I=; fh=Kxi+pXmXusNl3GFSAfoeZ4biV4zdvCvLwD6n/Wb6lA4=; b=As+nuMv17u27mxW/eUIoBfuQ2VCA1d6Q7MHNd1KKWH5j+NYk+KSIwE5YMoeC/Uh0Y0 hjf21Oppgg06ray/K5FDRfMhjvX67bOJN9wMZ+Kj00WD89jBBUHMYV4TFXz5uuvY/f4O JlLNiozHlqy1OeGBB2+Q33+OqC4uzKE1A0yyz97pduzQ8s2yavK6yicqeS1qtxXCn0A1 3P8Z24Zua6+s4NvSWwarkiXKc4/6LnxKImE72wD0hYniyl4eMvSRhkp+X3TMDOk2VqSF 8lS+K4q4cS7fkN3qNg8+/HJfpL59r13qnqEvJhL1DAGSHfxBcjhRg463FWYHjLhxZj4M KNvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uhC6t7VJ; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id j8-20020a170903024800b001c07bac13d0si10426440plh.383.2023.10.09.12.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 12:41:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uhC6t7VJ; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id E529F8074512; Mon, 9 Oct 2023 12:41:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378433AbjJITlX (ORCPT + 52 others); Mon, 9 Oct 2023 15:41:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346674AbjJITlX (ORCPT ); Mon, 9 Oct 2023 15:41:23 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B6D793; Mon, 9 Oct 2023 12:41:22 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01C09C433C7; Mon, 9 Oct 2023 19:41:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696880481; bh=3m8vfJotEQ3gbSMgx24f32JgP5HmYW7wJZrzxltQSBs=; h=Date:From:To:Cc:Subject:From; b=uhC6t7VJO+HL06uaAHUWAJUdKbYI1U0I4lHAaKZd4bTG5TO0SzI4JO02sEqNYsuDE ZT5ovm+BxxZ/PabeZEwHa5iWpZ7qTf0S7GezI4mDDGLsZ8KxhENtVfi7xXIMiXj9yu NB5aARhXR239GMlhoDAunPLa/kPwWmrjOfGUiQ1xW1nHrAv1j445CAlIYuhhHMTwub TmgB3wSrGsv/yyDQyCgjpfJ9+CNla5nIkaRna/JnEnLkt9+Ezyy2DK6wNr4KxU36fS /3xkom5ZGapfi75jW1iWdXlGkjIkss4HPI92i5JKnWHM/Fstt0+Hv1y0qcIQV64cvV qmnl8EpzozcQw== Date: Mon, 9 Oct 2023 13:41:18 -0600 From: "Gustavo A. R. Silva" To: Kalle Valo Cc: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] hostap: Add __counted_by for struct prism2_download_data and use struct_size() Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 howler.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 (howler.vger.email [0.0.0.0]); Mon, 09 Oct 2023 12:41:36 -0700 (PDT) X-Spam-Level: ** 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); }; -- 2.34.1