From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E10A0E748ED for ; Sun, 1 Oct 2023 15:27:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235152AbjJAP1E (ORCPT ); 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 Precedence: bulk List-ID: X-Mailing-List: kernel-janitors@vger.kernel.org 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