Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1246200rdb; Mon, 2 Oct 2023 04:04:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFadzSce9wQNYNS7JGJXuHA2lmtnxsy2+6tW1fVDTqOjo/M8ChwOayZ7OFYIVgVitfwXPm3 X-Received: by 2002:a05:6a20:4286:b0:15d:ec88:356e with SMTP id o6-20020a056a20428600b0015dec88356emr14777069pzj.41.1696244665843; Mon, 02 Oct 2023 04:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696244665; cv=none; d=google.com; s=arc-20160816; b=jraBm0kkKzj7CEHHAVCRo9PHa1GfPoJ5M81X+Pz+GqANU+mXRwaOgzn+m3WCQXETsN l0jtbrzUf+jhBVzdz9IKO2X6aF7SZFA4s1UAhWp0PAJ+RocKgs6iBkVEuZOHFIYbfoEb CWEkYdspGaWZhLh/DBgIOGuBZLj/KrI3XdNLIHLOlBnls2GoG8mwBpI2r0GrWkVlRLKK 9wOnBnalhJ2rkbVjRZkWzQ3NFmx9TOhv7nexyKEK/ri0vxjqPBIInEuLyfmAWZBtvtx6 sGxuHp9sattMYy67HFeU7lSt6ubGPDMOPHohljNQR5kigY/XnH/UJB5zBUvciE6YCwY0 moIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=uOUzmb8ftzbOyFeK0edTqft1MheQUfEIQXgPtEe/8BM=; fh=3WgUpjnVi4o21haRA5UJOWt9yFnPvgwGc+P11fAMuhw=; b=Qtxr5EhwvN/vk1x/9rrykQIBjsSbHh7yfIobKNrmFemwm/b+Rrw9gaUNsuxldLOBKw 6yPIR6GCkMFrDz4KT/ql5Lw6TyZk4zBvM4Jk5BWBp/2eyeZCI1A8h0wvvK5AD3tqluvv iQKn7Yfjdiqi66ZYzPhWYQAIlIa4G0DcI/mdmyPv66nIzNa4c8Q6EhisUflVgzTqg7qI 1gUKfx9jj/+ktxHWfLCt4FiT4doTLPYwRlGGTsT3B9pxrbf7xQW/+87s4+9GBpE5h1AK 8cacyp/j/eJXC4yYiRTM1IimKskRYDlZ5gOWYfDYZi3L7nSyDtsLyDQN1KYrB1EvHHEN LgjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=Hd8NbBKs; 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=NONE sp=NONE dis=NONE) header.from=inria.fr Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id l24-20020a637018000000b005891f64e424si750619pgc.785.2023.10.02.04.04.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 04:04:25 -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=@inria.fr header.s=dc header.b=Hd8NbBKs; 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=NONE sp=NONE dis=NONE) header.from=inria.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 7965A8024A28; Sun, 1 Oct 2023 22:38:56 -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 S235443AbjJBFit (ORCPT + 99 others); Mon, 2 Oct 2023 01:38:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230309AbjJBFis (ORCPT ); Mon, 2 Oct 2023 01:38:48 -0400 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BEE59F; Sun, 1 Oct 2023 22:38:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=uOUzmb8ftzbOyFeK0edTqft1MheQUfEIQXgPtEe/8BM=; b=Hd8NbBKsVd0zs1p7J5JnV+4cB+382/OjJB/78nDnuyqCucAQsl6Nk0H2 fy6HM5EWGeeK2/gAFUSUB1wpfOsGxEFpu2tBRjL4k02Bgv5uEi/dH+oo7 ozD+ml33TF3cf43UZFaTWgXzclPYV+SccLRPMrVqkzn/GbSCp7Dc7yqLI I=; Authentication-Results: mail3-relais-sop.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=julia.lawall@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.03,193,1694728800"; d="scan'208";a="67469029" Received: from 231.85.89.92.rev.sfr.net (HELO hadrien) ([92.89.85.231]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Oct 2023 07:38:42 +0200 Date: Mon, 2 Oct 2023 07:38:42 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Kees Cook cc: Julia Lawall , Kees Cook , 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 In-Reply-To: <202310011515.D4C9184@keescook> Message-ID: References: <5c3b7459b820e22e2ac6ce892d4aadcc119cc919.1696065263.git.christophe.jaillet@wanadoo.fr> <202309301342.5B5BED40A1@keescook> <90E2BBA5-8A2D-42DE-B36A-CD37BABBB433@kernel.org> <202310011405.7599BA9@keescook> <202310011421.C4F19D45@keescook> <202310011515.D4C9184@keescook> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 (howler.vger.email [0.0.0.0]); Sun, 01 Oct 2023 22:38:56 -0700 (PDT) On Sun, 1 Oct 2023, Kees Cook wrote: > On Sun, Oct 01, 2023 at 02:22:17PM -0700, Kees Cook wrote: > > On Sun, Oct 01, 2023 at 02:05:46PM -0700, Kees Cook wrote: > > > On Sun, Oct 01, 2023 at 09:14:02PM +0200, Julia Lawall wrote: > > > > Kees, > > > > > > > > You can try the following. > > > > > > Cool! Yeah, this finds the example: > > > > > > drivers/comedi/drivers/rti800.c:74: struct comedi_lrange: field at offset 0 is the counter for the flex array > > > drivers/comedi/drivers/rti800.c:83: struct comedi_lrange: field at offset 0 is the counter for the flex array > > > drivers/comedi/drivers/rti800.c:92: struct comedi_lrange: field at offset 0 is the counter for the flex array > > > > > > I'll run it on the whole codebase... > > > > It found only the struct comedi_lrange instances, but that's good to > > know. :) > > On a related note, why doesn't this work? > > @allocated@ > identifier STRUCT, ARRAY; > expression COUNT; > struct STRUCT *PTR; > identifier ALLOC; > type ELEMENT_TYPE; > @@ > > PTR = ALLOC(..., sizeof(\(*PTR\|struct STRUCT\)) + > COUNT * sizeof(\(*PTR->ARRAY\|PTR->ARRAY[0]\|ELEMENT_TYPE\)), ...); > > > minus: parse error: > File "alloc.cocci", line 15, column 34, charpos = 485 > around = 'struct', > whole content = PTR = ALLOC(..., sizeof(\(*PTR\|struct STRUCT\)) + > > if I drop "struct", then it complains about ELEMENT_TYPE... The sizeof with an expression argument is treated differently than the sizeof with a type argument. So you need to write: @allocated@ identifier STRUCT, ARRAY; expression COUNT; struct STRUCT *PTR; identifier ALLOC; type ELEMENT_TYPE; @@ PTR = ALLOC(..., \(sizeof(*PTR)\|sizeof(struct STRUCT)\) + COUNT * \(sizeof(*PTR->ARRAY)\|sizeof(PTR->ARRAY[0])\|sizeof(ELEMENT_TYPE)\), ...); julia