Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2197888rdb; Mon, 9 Oct 2023 16:47:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFmwYwFoE+Z4XXvrtCyFmtMt4NySnuTRvwQQ5lfXRVo0CTrFCx1yItrBXzsMwLB/cc9zWy5 X-Received: by 2002:aa7:8889:0:b0:691:1eb:7dda with SMTP id z9-20020aa78889000000b0069101eb7ddamr16381978pfe.7.1696895223347; Mon, 09 Oct 2023 16:47:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696895223; cv=none; d=google.com; s=arc-20160816; b=pfeyD8BF2RF32LIarYcjC32PIYYfDMZwphqHRRQDMhuZB1oDmZKYfuNkgSG14iFk8j 6hHRO5rWsFbkIXURsboWsTjTnup4kL4JCMqxh0VmLzDdcTH5TWP1m7V5xVGaZTCjTYsO OrwxATGztMy+ArYMf6UNy/PKXWlNnHM/vQwPJySLfnJEJAW6GUpe0U1e5u/hol2x5MAO F8nHwRx6lfPL1d4QcTig0wT8UmBqLddNF2wmv+NQr4MSX17Spxob6GGZObP3GsYrQoi1 wtq/8LiHAvMuq96yQzPnmavTsbO3WYX7tSeumXAhQ7ITMWQLPi2F0AyTJvcRCaNoug/I hrYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=yXbLKS+MxtD32e7DqErJ9Y3Mh+T6J/t2QZRdubLMtiQ=; fh=+aFewZeWr9ASG91PqjiIWfSWYq4IrX5FP1IvjhMQL6o=; b=tRec1VnFy1oJzMNhss5cbS+jN44IgtrocbowNjb9cgtnKhSLk6faMm1fh3n2UR3Zmt C/I/uB3RQCDTWgAGba9FcVKHfGVuUZ2wV6+1/UP5m/CnKA4c3et6ZWX8DxbVzDo/uC/v y8xdo4YukfiPcR+hm0F05F6kThdRSLitu23UH7gq80RhfpybaEFZnAVtnMiEKep2xRud LcNiG1WqjciiO70Il9uB7oVQL+rzGitR8XL6gewGN2PSUBsA4lqn+gBp9+z/gFTQRTGE Q61B2rZNrSxJx31Uh7Lea0TOCvOsl37UK9WubN1WgGz4gyRhYOPP54PSTIJiCHR+hPtP hh3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=p2MFTdg4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id u21-20020a63b555000000b005897bfc2ecbsi9725275pgo.205.2023.10.09.16.47.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 16:47:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@google.com header.s=20230601 header.b=p2MFTdg4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id B548F809AFA7; Mon, 9 Oct 2023 16:47:00 -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 S1378992AbjJIXqw (ORCPT + 99 others); Mon, 9 Oct 2023 19:46:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379014AbjJIXqv (ORCPT ); Mon, 9 Oct 2023 19:46:51 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7090A3 for ; Mon, 9 Oct 2023 16:46:50 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-533d31a8523so9047251a12.1 for ; Mon, 09 Oct 2023 16:46:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696895209; x=1697500009; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=yXbLKS+MxtD32e7DqErJ9Y3Mh+T6J/t2QZRdubLMtiQ=; b=p2MFTdg4Ku/ED/0Lw9LyVc8RZ6mH6QdHG18FcltKEMRFZUp6mvDe+bDHa0khBH0f52 lyVpSrMTmqA8zRsmYmhQ8S6hGilZn9MAlHR35bIXNoxrntxtUAFYcYxg9M2Bd4nu6j3C 0vavPkpRs6vDfye8asGPZA2STFmW3WyI8JBojpwz6ZeHOSP6Hv7twlawnZDpmWPQ3YnF WRNWWSCFO+QNM/yBR1PxiHRthqcslsnTHOJ2RaTsxAKAkJ6unqJchN0ZOWgjxoZet6xC ztm9MBVq5yFHB7WM45lJBK+FMVf0d+cyh1wS2nbdhYi2GBW+ZTnN2M9ElG5wnqWt6AcT iD7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696895209; x=1697500009; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yXbLKS+MxtD32e7DqErJ9Y3Mh+T6J/t2QZRdubLMtiQ=; b=Fra3ojWxnj5uTsACnv9V+YKu0D7piwfsKa+RJZrLLYDHAPP17sYcNfnJuSj/CtWXfI bLs4qet9DXeWtfXyaAfIxlYMoCJF76KDZsmhE//gTl2uxmcKgPJ7xAGaTklxGIBFGk7A 1wUCgG+C6UaFcVZqFPUOSVFi/4gc8FLOAqPC4HS0wSIHEWu/B+6Cb8VeP8b5Kh6oEF5/ S1dBoRxB0+zbo59cL4q8FtuKTPEZepx3+Wt/tCU/kHc7Q0+I9dWWPNAFMdf1FR1JWttS DTqHnALSoLVJENapbo0vV86bNIX/ciOnBfvZXXcwhIwownY61FQ3+A7bzNLlML6DJadI Q9ag== X-Gm-Message-State: AOJu0Yx6U9LOWdtMsX6XXaEXiOaTseoMnTjciiKZxk49kvaA7i1tXKJe 5que7O/LgbBYNuz5pGf0+vjJ1riv5rqQlZ4c/SBZkg== X-Received: by 2002:aa7:c541:0:b0:534:2fd8:a9e1 with SMTP id s1-20020aa7c541000000b005342fd8a9e1mr14401271edr.22.1696895209185; Mon, 09 Oct 2023 16:46:49 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Justin Stitt Date: Mon, 9 Oct 2023 16:46:36 -0700 Message-ID: Subject: Re: [PATCH][next] soc: qcom: apr: Add __counted_by for struct apr_rx_buf and use struct_size() To: "Gustavo A. R. Silva" Cc: Srinivas Kandagatla , Banajit Goswami , Andy Gross , Bjorn Andersson , Konrad Dybcio , alsa-devel@alsa-project.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL 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-kernel@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 16:47:00 -0700 (PDT) On Mon, Oct 9, 2023 at 2:30=E2=80=AFPM Gustavo A. R. Silva wrote: > > Prepare for the coming implementation by GCC and Clang of the __counted_b= y > 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 Excited for __counted_by to land! This looks right. Reviewed-by: Justin Stitt > --- > 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, v= oid *buf, > return -EINVAL; > } > > - abuf =3D kzalloc(sizeof(*abuf) + len, GFP_ATOMIC); > + abuf =3D kzalloc(struct_size(abuf, buf, len), GFP_ATOMIC); > if (!abuf) > return -ENOMEM; > > -- > 2.34.1 > >