Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2697071rdg; Mon, 16 Oct 2023 11:56:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG274AluSWC470rhQgeMCjMdEp1iwea+LRrxPf6kCp68vOx7KYekiCM9KveKW4GI8cecSJr X-Received: by 2002:a17:90a:b10f:b0:27d:4935:8d9a with SMTP id z15-20020a17090ab10f00b0027d49358d9amr12540479pjq.4.1697482599956; Mon, 16 Oct 2023 11:56:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697482599; cv=none; d=google.com; s=arc-20160816; b=G9/+iGqrwzL0QkaNDrRbqGf+nEhjQVCTtKG2k4vD2Wj6uTS54SUCEpuFSFW249tv21 QL/bd+NIb927tM1Fp8o+G678uIxQhrTlP59xLRuEoUFbi2ZC0P1Q3oRqHZdMYsERVhgc 9e/VXOmlIaIJkUUXYzB6aTGGZqe87jPlmOfFvLzaXHxtW9jcNzN+ghTr38f61wdy6S6N YW4k+5q/o6vxWGJKacsYB4056tWgfm/GcWEdwlbfSDXY9JamRBgi+jn2zEOuq0lUe2Ef vhFytyIZInSsE8rgh8Hn7F9up86t7nP7TY9KP1jARs04zLke1Gi77x1e0KcRxdDAStas YNWg== 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=AqmO1rMYqqenzcE6fLpVVaH0MTgbHgDv23yja8haS1Y=; fh=PmNbtbSnDmR5920GXtBLtJ03I3s3XwM3y+wxlKDAZyA=; b=BXaylRCOlaBw33BfmGZ2qlpttczAfq3g+F+jCJNh6UfSa/Z9BvyQ+t5UIqhWFbtAb1 rRzaqJNBRcChtf0EMYE+CdS9QhNDDtuGZJGshWRjJtlwd/eKqafGjtodr5VaUgXpHbHp SxtTLo0uQBsFeaXzpBWJCPoY3I5VVRjsGxdJd3GGkNOHUSMxJVgyyHqBpAp7zDiGI1X0 Q/WEmC0og8SbkLmXt/WL/f0wq/6Ou9zSsnQrnw923lPt0kq1zhGgG+9IerR5pnMTYvo4 E9JwPn6SzmQyHcXb+rbpYwcqEVVO8l105pu/1hsTOSu/EAgn9a8xgp3LRx2khoKEwiDJ Lg5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uq+dK+u9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id oc14-20020a17090b1c0e00b002774c98054csi7396891pjb.116.2023.10.16.11.56.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 11:56:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=uq+dK+u9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-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 snail.vger.email (Postfix) with ESMTP id 194188061392; Mon, 16 Oct 2023 11:56:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233621AbjJPS4H (ORCPT + 99 others); Mon, 16 Oct 2023 14:56:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231569AbjJPS4G (ORCPT ); Mon, 16 Oct 2023 14:56:06 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68C3D95; Mon, 16 Oct 2023 11:56:05 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 621C1C433C8; Mon, 16 Oct 2023 18:56:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697482565; bh=QcyXCskRPbOnWPMhi0EFFGjPvt4mFSLqbM7WXj8RRTk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=uq+dK+u9sQe6i12LxkLFZefC/LT+F/9isgSSyVWofETmERrXFkhy+LsslGY1SPxQV aNRQG0xZYpZ5jC6v9GY7QL8u18a2CRGqIQeCyx/x5cfK82FJAT/K4vFTT6ykOqVrHj BTmOtqrkGGTIw/ICGxhPbbQEM0fD7lZJ1BBaGjpsN1bCnC5HQq6DbRLUtRo1ZYux0I ZFSJ69pSRxIexDVunyOx81Qn45YSlFJ25gPmSVu2bpvMCU7WOoKBI4Uv1sqWVE0zIL oicyw/lhvaWlRK9akRu/yLwe5GlYv1URMtVBfGARefOiL3KaPRvTHfWfUqsOBfK4bb JKL4Bgp1crJmg== Date: Mon, 16 Oct 2023 11:59:52 -0700 From: Bjorn Andersson To: "Gustavo A. R. Silva" Cc: Srinivas Kandagatla , Banajit Goswami , Andy Gross , Konrad Dybcio , alsa-devel@alsa-project.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH][next] soc: qcom: apr: Add __counted_by for struct apr_rx_buf and use struct_size() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 16 Oct 2023 11:56:12 -0700 (PDT) On Mon, Oct 09, 2023 at 03:30:17PM -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 Applied, thanks. > --- > drivers/soc/qcom/apr.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/soc/qcom/apr.c b/drivers/soc/qcom/apr.c > index 30f81d6d9d9d..1f8b315576a4 100644 > --- a/drivers/soc/qcom/apr.c > +++ b/drivers/soc/qcom/apr.c > @@ -41,7 +41,7 @@ struct packet_router { > struct apr_rx_buf { > struct list_head node; > int len; > - uint8_t buf[]; > + uint8_t buf[] __counted_by(len); > }; > > /** > @@ -171,7 +171,7 @@ static int apr_callback(struct rpmsg_device *rpdev, void *buf, > return -EINVAL; > } > > - abuf = kzalloc(sizeof(*abuf) + len, GFP_ATOMIC); > + abuf = kzalloc(struct_size(abuf, buf, len), GFP_ATOMIC); > if (!abuf) > return -ENOMEM; > > -- > 2.34.1 >