Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp860057rdb; Sun, 1 Oct 2023 08:27:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGqXPksB+ofxkB1kuwGhZPp5UX4gH4OHLQVlglDOBs0t5FGfjYiY8LDJtuoQgUET3SnOtgM X-Received: by 2002:a17:90b:e09:b0:274:922d:4b35 with SMTP id ge9-20020a17090b0e0900b00274922d4b35mr7207865pjb.1.1696174043528; Sun, 01 Oct 2023 08:27:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696174043; cv=none; d=google.com; s=arc-20160816; b=WOeUxyDXbVTetOItawXWSyf2okJRn2darM0x9HCEFPmeEU1PaqwmMVYU7FRV1AWecl J7A6g+/MIHgr6LNQmVngsrVpqh0y98Dskv7bZ4tQZbsrPDIN3OxOieUy1msxyjwB2Gbo reRZB7NdydKoTWiLtb0PXkREgC8fAO4DaAuiXwbs5ZyFsLC6atrYNDdkKnLG7A3v9EMv TQZT/+q1iaRVeOwxtUNnrPRI4QDv5Btc6MvbRDrFUY9+n6EY4bBlzrPdravX7cha/0rk RGZYi2ntL3+Zmaw/qRvd7zrRLI36qKxPH3NWqKjN9sYFD/tBiWWEINmkbwHW3nqQvMuh JG0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:references:in-reply-to:user-agent:subject:cc:to:from :date:dkim-signature; bh=rM4mzEJ+oFhxV/Wd0ICcPhI2xFmIKzxv8vIH09MUQx4=; fh=8e4t0voDL2miQTQay8b/dL8YXi91C5mkUELyhKBEAqo=; b=zzkGKD92DapMFYdm2ynNctMITajF6Pp/D6wwOIQ9uCmfGvAmG134m+ptdVYyVYPM8H 8e6GFLyje+cIuuV4zUsjlUUFocC+RPgljBdO5HJa9Y0VmK+/sRroGVn/5aolCUYbu4l7 JWOXHicy2MYnbyg86lrJtJHMS8mt56U6as8WXc/9X+l1DmXKLz0iVFsE7ww4YaztxwVx wxH+UnN8Z07diaimIczUnAv1wpiZtqUBYciuat+jRMN6ujSB3pYpTqpju6UYfDC8XnuA eauUZp8wppGlxZBl5ul8EHkOzLgGlR+UlEOFQAxk3LfQ4mMV0ZdBTFJCQHePEk/Y6P1D iaCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aUZj+oZx; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id lp4-20020a17090b4a8400b0026800178358si6339282pjb.144.2023.10.01.08.27.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 08:27:23 -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=@kernel.org header.s=k20201202 header.b=aUZj+oZx; 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=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 69E9580239AA; Sun, 1 Oct 2023 08:27:20 -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 S235166AbjJAP1E (ORCPT + 99 others); Sun, 1 Oct 2023 11:27:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235113AbjJAP1D (ORCPT ); Sun, 1 Oct 2023 11:27:03 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2AF499; Sun, 1 Oct 2023 08:27:01 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A124EC433C7; Sun, 1 Oct 2023 15:27:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696174021; bh=OP680lsN8lk0ineFcZVgu79J8KnTHUp5BT9RfTao+vk=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=aUZj+oZx53xM+0Adszz/WePNjpsIy9M65UpjURU/NxSen1aEW+VD0g4cNi4O582tX UdrVpyJrd0PnH8FSU4/PEfoCjVJLUwFMm83B7Ua7uaewX4UNOsO5EngyqnK8FLGyuk Y+RdmiJPNpfVEh0V4Mg4EzU6j+5te3R8+zzqWLXFrswKW0yEntKN2nzWYc2vwW+88x GDzfgx4kadbk+mgqoFA4GsZnG7h1JZdeHKVFv74F1iodxlTaCv1Y1p/P4vIpb4jNGN mSJsW0vdj3syiTjlkdFdIHXGHSYrFPEnkXRLFQteTbYwaaettWQvWoAYA+q4gHrOXc HibQudUhLOPHA== Date: Sun, 01 Oct 2023 08:26:56 -0700 From: Kees Cook To: Julia Lawall , Kees Cook CC: Christophe JAILLET , Ian Abbott , H Hartley Sweeten , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH] comedi: Annotate struct comedi_lrange with __counted_by User-Agent: K-9 Mail for Android In-Reply-To: References: <5c3b7459b820e22e2ac6ce892d4aadcc119cc919.1696065263.git.christophe.jaillet@wanadoo.fr> <202309301342.5B5BED40A1@keescook> Message-ID: <90E2BBA5-8A2D-42DE-B36A-CD37BABBB433@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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]); Sun, 01 Oct 2023 08:27:20 -0700 (PDT) On October 1, 2023 12:45:41 AM PDT, Julia Lawall wrote: > > >On Sat, 30 Sep 2023, Kees Cook wrote: > >> On Sat, Sep 30, 2023 at 11:14:47AM +0200, Christophe JAILLET wrote: >> > Prepare for the coming implementation by GCC and Clang of the __count= ed_by >> > attribute=2E Flexible array members annotated with __counted_by can h= ave >> > their accesses bounds-checked at run-time checking via CONFIG_UBSAN_B= OUNDS >> > (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-fam= ily >> > functions)=2E >> > >> > Signed-off-by: Christophe JAILLET >> > --- >> > This patch is part of a work done in parallel of what is currently wo= rked >> > on by Kees Cook=2E >> > >> > My patches are only related to corner cases that do NOT match the >> > semantic of his Coccinelle script[1]=2E >> >> Nice! >> >> struct comedi_lrange { >> int length; >> struct comedi_krange range[]; >> }; >> =2E=2E=2E >> static const struct comedi_lrange range_rti800_ai_10_bipolar =3D { >> 4, { >> BIP_RANGE(10), >> BIP_RANGE(1), >> BIP_RANGE(0=2E1), >> BIP_RANGE(0=2E02) >> } >> }; >> >> I'm struggling to come up with a way for Coccinelle to find this kind o= f >> thing in other places=2E=2E=2E > >Kees, what exactly are you trying to match? Static allocations? I need to count the number of initialized elements in the flexible array t= hat is the last member and see if it matches a value set in another member= =2E E=2Eg=2E the above sets 4 values for the last array member and then sets a= nother member to 4=2E -Kees --=20 Kees Cook