Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp13753rdb; Thu, 5 Oct 2023 14:57:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpdUYFhME3QGj78AykP3bTgaglkC6n23FljiKuBFhE8WOo/HqDizbHM62AkNzauYpBpgBS X-Received: by 2002:a17:902:cec4:b0:1bb:ce4a:5893 with SMTP id d4-20020a170902cec400b001bbce4a5893mr7512444plg.30.1696543057747; Thu, 05 Oct 2023 14:57:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696543057; cv=none; d=google.com; s=arc-20160816; b=gyJU5Y0XdJRBBmZh0vP2xObJRCnthHnpiU6fYrp+NxXrNm0GEyrIRJk4FU9Tx55OtE KiYRKot8NSyPtZXRXPLawl7CHHIr6ryg+U2h6WqpSLHHG1vumEdRPupUFwXf5hvItZlG ueOfrpOIt9xUxg4OJXZUoRjfd6QSIk5WlwQzwGmmr02KATUA35HTrU4prycpOPgtEnuM MAjlg1jC9isEUFJZ07TMKJtojDqsOOXGbYpGifK2uhwtleeh7CHcuIG8szwD7o7TOsgt nKXAsHm/q+Tg7IUU9YSiPAIZnxsnDqbJxcC7Awk+AE5rqKF1ow35H37W7tPIIZkMCVFo v0Jw== 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=CAYKChfRdgudPucMl+HqonIt/5AX5oN5CCdBSnTYy0c=; fh=L4TUf1rdG/CUf4bUl58LNu/ga50dwRHC1Qm23IY//dc=; b=kGtjiNflnB0JFRp0nRsklhl+Km1yY/FgNq6puXsdkhXucqMAcYxahPvosyU1tnqG15 qs9UmhtR0syJQtuKrVX8u58vZCtitA6f7ptFrrvWfDwz4dJCE7FypBZbV2Ryr3WpW42a fK61JJocVY6MjjioLF4bWUaQq6UDOiQCcw0NG952Dr9QG0N0z0y24Iy5BJqseYCq8VIZ J5UCVx4vX/1lKL4DFBMW7ILMGwAEG4iH8mcBnifzeidEPlCfx4NAVRktzofGobkVVi7J Vc5/6dROcRTUHBA5zHJ3TPMco1pvPh2JS9VPbeRqfFTWb0lSQNzn0E9P8VNeBD3beeyz SYHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bjvf6wpq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id kx8-20020a170902f94800b001c61bd7cee0si2254916plb.211.2023.10.05.14.57.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 14:57:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=bjvf6wpq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id D7BC9844AB85; Thu, 5 Oct 2023 14:57:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229880AbjJEV5N (ORCPT + 99 others); Thu, 5 Oct 2023 17:57:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbjJEV5M (ORCPT ); Thu, 5 Oct 2023 17:57:12 -0400 Received: from mail-oa1-x32.google.com (mail-oa1-x32.google.com [IPv6:2001:4860:4864:20::32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8141295; Thu, 5 Oct 2023 14:57:11 -0700 (PDT) Received: by mail-oa1-x32.google.com with SMTP id 586e51a60fabf-1e1b1b96746so924252fac.2; Thu, 05 Oct 2023 14:57:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696543031; x=1697147831; 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=CAYKChfRdgudPucMl+HqonIt/5AX5oN5CCdBSnTYy0c=; b=bjvf6wpq7yI0gGDm3xsQPU5ihcI64ca8P+cCefKl7l2C1eQ9bwadTkaCcUXZyLwriM F8zOh7onMzlhIQSVncOO/pAqnSn4Yg8uA10Txgud2GTdiMVrXlcN+lRYE5msk9BeNAHH lwCLArOJJGxOooO+J8d/jluLezoFvQJ37OgIKC/ryDDih7OkQsdq8ED7f3La4DiRXQT/ ur0gl7kRr1Bxz3DfA297mW0LRtmLLIoiarOzHHx2yZbvLaive7nS3AN8nFtsZgKormWf MGBi1nHnaCGR5gYoRpkKajtZwHHcOMHbkPhDjcuzbFqoTrfUN08PXyyWUfVWhp/Pe25N HAJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696543031; x=1697147831; 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=CAYKChfRdgudPucMl+HqonIt/5AX5oN5CCdBSnTYy0c=; b=thXIZyq8mEbhYh1WkD9K7heTex7ySuBGLetsl2FMeYcvF8OvLueXoxmCfBTLflS3qD 45Adh7KiJ+RqC9Zv7OccYAdzIGwPiUflY2SRnKqL19Bu8lwA9LnWA93xqh+u9PTn9PfF QO1BRK1ZIUemmLXMIw8rOZn7o9HWJ/VMfbzGsQeUGuStQAClvM9M7GPu1uF3g/wFzrB2 4saGccx87ee7C4JX6jiTD8q90I8vELmeOYPl0nI23/YLQbHqWZCuurbarR+iAyc9i139 yPFpiUK2NeiAYLPy7TpWPLy1GJTdWjvpSDynXkIr+c42q6iHNN29bTvdcIozkosy8G+n lBDw== X-Gm-Message-State: AOJu0YynAkhr+QPMWQ2ndRrVU6z2bhS/ntaHZKXLTv1Sr1yjMFpr2WR+ 25k60EB0qOF7F1cEvLq6pTgummwhdTU6OGZF6yM= X-Received: by 2002:a05:6870:888b:b0:1bb:8842:7b5c with SMTP id m11-20020a056870888b00b001bb88427b5cmr7517247oam.43.1696543030835; Thu, 05 Oct 2023 14:57:10 -0700 (PDT) MIME-Version: 1.0 References: <20231003232952.work.158-kees@kernel.org> In-Reply-To: From: Alex Deucher Date: Thu, 5 Oct 2023 17:56:59 -0400 Message-ID: Subject: Re: [PATCH] drm/amdgpu: Annotate struct amdgpu_bo_list with __counted_by To: =?UTF-8?Q?Christian_K=C3=B6nig?= Cc: Kees Cook , Alex Deucher , "Pan, Xinhui" , Arunpravin Paneer Selvam , Tom Rix , Felix Kuehling , llvm@lists.linux.dev, Nick Desaulniers , "Gustavo A. R. Silva" , amd-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Luben Tuikov , Christophe JAILLET , dri-devel@lists.freedesktop.org, Daniel Vetter , David Airlie , =?UTF-8?Q?Christian_K=C3=B6nig?= , linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Thu, 05 Oct 2023 14:57:28 -0700 (PDT) Applied. Thanks! Alex On Thu, Oct 5, 2023 at 10:32=E2=80=AFAM Christian K=C3=B6nig wrote: > > Am 04.10.23 um 01:29 schrieb Kees Cook: > > 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). > > > > As found with Coccinelle[1], add __counted_by for struct amdgpu_bo_list= . > > Additionally, since the element count member must be set before accessi= ng > > the annotated flexible array member, move its initialization earlier. > > > > Cc: Alex Deucher > > Cc: "Christian K=C3=B6nig" > > Cc: "Pan, Xinhui" > > Cc: David Airlie > > Cc: Daniel Vetter > > Cc: "Gustavo A. R. Silva" > > Cc: Luben Tuikov > > Cc: Christophe JAILLET > > Cc: Felix Kuehling > > Cc: amd-gfx@lists.freedesktop.org > > Cc: dri-devel@lists.freedesktop.org > > Cc: linux-hardening@vger.kernel.org > > Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/exampl= es/counted_by.cocci [1] > > Signed-off-by: Kees Cook > > Reviewed-by: Christian K=C3=B6nig > > > --- > > drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 2 +- > > drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h | 2 +- > > 2 files changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/= drm/amd/amdgpu/amdgpu_bo_list.c > > index 6f5b641b631e..781e5c5ce04d 100644 > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c > > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c > > @@ -84,6 +84,7 @@ int amdgpu_bo_list_create(struct amdgpu_device *adev,= struct drm_file *filp, > > > > kref_init(&list->refcount); > > > > + list->num_entries =3D num_entries; > > array =3D list->entries; > > > > for (i =3D 0; i < num_entries; ++i) { > > @@ -129,7 +130,6 @@ int amdgpu_bo_list_create(struct amdgpu_device *ade= v, struct drm_file *filp, > > } > > > > list->first_userptr =3D first_userptr; > > - list->num_entries =3D num_entries; > > sort(array, last_entry, sizeof(struct amdgpu_bo_list_entry), > > amdgpu_bo_list_entry_cmp, NULL); > > > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h b/drivers/gpu/= drm/amd/amdgpu/amdgpu_bo_list.h > > index 6a703be45d04..555cd6d877c3 100644 > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h > > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.h > > @@ -56,7 +56,7 @@ struct amdgpu_bo_list { > > */ > > struct mutex bo_list_mutex; > > > > - struct amdgpu_bo_list_entry entries[]; > > + struct amdgpu_bo_list_entry entries[] __counted_by(num_entries); > > }; > > > > int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id, >