Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2129715rdb; Mon, 9 Oct 2023 13:42:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHDNy5mRulW+l1YJLgBIM7uCstkeJn9U/FFTKsksnjN+HGpi0L8YLYYSRNwPIWV7Ytuwz5A X-Received: by 2002:a17:90a:5205:b0:268:5575:93d9 with SMTP id v5-20020a17090a520500b00268557593d9mr12878073pjh.10.1696884144585; Mon, 09 Oct 2023 13:42:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696884144; cv=none; d=google.com; s=arc-20160816; b=BXj3KUU1yXJumu1dZl1wJEjoNxkAdI0tvtBgbrhXywoYeotWc4YWcV+uVHN4o490JM p/CtW4+DCcca2bt2VhPlSxFt/MGopiADA0JLAJ8xUwTwhrcWYshtaUTxiUbJHBbwMIb5 kDg+OYOfGQ+N8Ffuoe0i6WMDb8bPI+VtxrVyYv1uynqK5Aw1QGcwjIYCKmxc+JCO1BGk JZDyCA0w7W0ZcpbUwczIRw5mANm75jfxbEf8aStwwuxnxuNnzkB/pzkgxkPQz8RUqDYF ezOfwro7G/MOx1ao/semlucJEhwkkNZEuzwO86KoojeNVdYtFge/uoJcHHSONRnpCZ3e 9fEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=jQQInxgsjBt8w5xcxIPIHbM5AYNFsiZIBl4w68pdIx8=; fh=T6qrOKULLgIOUYXoKAgdAb0tRZawiT5C0PwEputzY3M=; b=UZRzvJlb3veeRla4VlxfggFjdQeGC0t59I0OA1EsGBmAx8TnfdsiVJF6wqAGmDiJou NxLZWA+bBNasDCs3DxlcWx6/fE9whj6yzu1XnuNWf6a4b2cw/XFV06dvoB4u45ncJmIp hFLr7HlSzZCYybhx56RumzGC1Opj/YCd7aRjTJwTEn7xuYkMyuC4qbIDNnV8/72sI7H9 rXw8SeCB8OJhvMjMLuKOPJ8a1dAHix3dRBHrfDRWF8FRZJH8y5Of1dhcXdN/gHZ/9hPX sxFEzj4OeQ77FYGupi4d/aeBlSsaengqJZKVh1AmIzUMIArh2xeByXvI5a9mx4GvQYQ8 OoFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Wu+000MO; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id g9-20020a17090a714900b00274274bf0ecsi7519496pjs.61.2023.10.09.13.42.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 13:42:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Wu+000MO; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 3B3F98032ED8; Mon, 9 Oct 2023 13:42:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377942AbjJIUmR (ORCPT + 52 others); Mon, 9 Oct 2023 16:42:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234506AbjJIUmR (ORCPT ); Mon, 9 Oct 2023 16:42:17 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E10C5A3 for ; Mon, 9 Oct 2023 13:42:15 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1c5bf7871dcso35838695ad.1 for ; Mon, 09 Oct 2023 13:42:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696884135; x=1697488935; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=jQQInxgsjBt8w5xcxIPIHbM5AYNFsiZIBl4w68pdIx8=; b=Wu+000MO5t3eBFYqm22mZBbmq8jg7gvPF00LNVrW5E0kJlsEJL3c18fdwsSNzRehm9 kAO/9ugiSIt6CTMutB999b+SOmUl8BEpvRLAxv4esa0OfQaHbgboDsckZ0ToUCk3jimg C7zE/Its3EVqTcbDo8+wel28Z66Mpk14wKyoU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696884135; x=1697488935; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jQQInxgsjBt8w5xcxIPIHbM5AYNFsiZIBl4w68pdIx8=; b=YWQyJQ+yq8nvDcmiIU4qCNYPoWu2Lu0KysAWevRmuZpmNIW2aS/QBPsHsSJoZi2sYT Vjy9fufcxgePU4ksb9gVZDYZ/HujuLiOcE3fnWlZX/pnkO5n9hFZd4+JsXfgWNVEBtK3 rlfdURyfao9C9Jg5k9QDDS56DbO/zGhR1C8STcR/FEX8OVeCdlfNbbDgjh6k/1fQIob5 6rtbSyLQpg1lo8A4qk36Vb4fRJaNx4i66QFY7Je2LmI6dbd36fZKroLLfwEucOI3oH7J QK90dm0VsIlfrPvKPlyaid9SoUmdWsTp53JnrpPwmCxODkEk39QLp3qgW2I3KBX2Qzyt L29w== X-Gm-Message-State: AOJu0YwESsEzZCm87sVwHQgmAkuJG/D0RynKgYL/Awuh8/YnDoyMeEOi r95h220ckKcTTgQH/kpayzXC+w== X-Received: by 2002:a17:902:e883:b0:1c6:19da:b29f with SMTP id w3-20020a170902e88300b001c619dab29fmr16439549plg.26.1696884135372; Mon, 09 Oct 2023 13:42:15 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id t10-20020a1709027fca00b001c465bedaccsm10286698plb.83.2023.10.09.13.42.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 13:42:14 -0700 (PDT) Date: Mon, 9 Oct 2023 13:42:12 -0700 From: Kees Cook To: "Gustavo A. R. Silva" Cc: "Gustavo A. R. Silva" , Kalle Valo , linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH][next] hostap: Add __counted_by for struct prism2_download_data and use struct_size() Message-ID: <202310091341.74A2D82BB@keescook> References: <202310091253.665A9C9@keescook> <169f782e-9cc4-49bc-9618-ca6acc526e37@embeddedor.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <169f782e-9cc4-49bc-9618-ca6acc526e37@embeddedor.com> X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 09 Oct 2023 13:42:19 -0700 (PDT) X-Spam-Level: ** On Mon, Oct 09, 2023 at 02:33:01PM -0600, Gustavo A. R. Silva wrote: > > > 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? I defer to Kalle -- your Subject is more accurate, so perhaps let's just let this stand? -- Kees Cook