Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp361315rdb; Sat, 30 Sep 2023 07:20:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7veqknunDx7WsC1damiFuyh1vv+rJGrxwbdMye7llArtw7UNANlcoNXPs6L89uqHgPnxE X-Received: by 2002:a17:903:485:b0:1c6:de7:add9 with SMTP id jj5-20020a170903048500b001c60de7add9mr9981886plb.19.1696083614210; Sat, 30 Sep 2023 07:20:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696083614; cv=none; d=google.com; s=arc-20160816; b=fbBFWR71wChfJAB8kJG1bIMVdutVox5V29NvuHAKD81VLDWvtpoLSpWbQup8+iYXJm 43ONb90KaW0p+xE+XA9zQ7YFjv2HTr6hhobIy2BUepKppRUkt6mofFVO7mnrWJaWHNLR Xhuf/Wt1TCe4rbOBPYa/1BycAoAroMV7YdHoAE8BTlVdtkIlxsgWQIpSosCyIOnLpp5Y rauAIgi2KaOTulIYsqAimdnR4dtr5CD6Cd7Vhrj+dUCjniWyLqXlHkHDF24OzMu9X0BD eCz0iZTNjtOfCb+pcY4YvVpwe9VBJ5ncTBQICAkQGTFHoUig/W83S7eFL1BnGPexGOpB bW6A== 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:date:subject:cc:to:from:dkim-signature; bh=HqO0OJ0xpYTouMij+n4RJh5b8XJeCUxxVmU/L5T7xtU=; fh=htcDEAxhw/vxfwAtSQYEOhUKWajuzulmhoNFgL9sXck=; b=xTNXI7bPazOeoLkrLqR4/hWUdHgPgI772P7g2lgqNyhAB4kpdwQUk1LaYPhlb/dhA1 nwJZAUXzewPFqsTVMUtJxwRyYwTdaTZfB9ea9RPdeKx/LIv0IwusqKG0oFgN0NBa6uIq 9KVQNnNY5IFg5FCLjXy6yQPhGRer/SlcF49LCNqncdS3qepMXNIAI9ddjPcjiPo3RdSV +qC/8qHpmlFKyfCkxNu7eEjzs0IsrtjkIUvkTP0JJ9GUEyZOUY1rsv7Tc6iYhCD1SKte 3bPHApzS4plpI6kELSU01y9VFxZ6FWlVDdfgaOu54zTBbj4/QQ/JSiWE+wa0dUnez5ip GaRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=EpHIjI+H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id c4-20020a170903234400b001bb3406a5f7si6866858plh.11.2023.09.30.07.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 07:20:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=EpHIjI+H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 878838048C11; Sat, 30 Sep 2023 02:17:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229645AbjI3JRE (ORCPT + 99 others); Sat, 30 Sep 2023 05:17:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229588AbjI3JRC (ORCPT ); Sat, 30 Sep 2023 05:17:02 -0400 Received: from smtp.smtpout.orange.fr (smtp-21.smtpout.orange.fr [80.12.242.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 058B7195 for ; Sat, 30 Sep 2023 02:16:56 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id mW5lqciwUlLhemW5mqgUyK; Sat, 30 Sep 2023 11:16:55 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1696065415; bh=HqO0OJ0xpYTouMij+n4RJh5b8XJeCUxxVmU/L5T7xtU=; h=From:To:Cc:Subject:Date; b=EpHIjI+HuMMZ8HK0f8SwmZJ28a0d+04wdYHD9bRONTstCAVZiuB6avxQIos6ZEItc nVbK0FhaDctKX08sYwo+8tmAJEnv6ltQgDnG9fYwZpZoBVUgsKFrz+BMHupi59MPeM lgimnXmj+nnzQTAeRwa0bWoRLIp/jaeZ1pwjp3cFsxAdixy+FaKMD6mojz70CMqFDW MqyCIxpgCkZeOjHqiuGZYZcPItC1BeAai4TnekU0s1DSIfshfJMrRT8p3JZGtV0XHt MrFDwIJTX7PV+l0ZqFNDsYVj+zmnJRpnzwhfzLuVIWS231jkCTFUOwZBBvYjegsqtY 7l1TLWdCU9YMw== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 30 Sep 2023 11:16:55 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Ian Abbott , H Hartley Sweeten , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Tom Rix Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] comedi: Annotate struct comedi_lrange with __counted_by Date: Sat, 30 Sep 2023 11:14:47 +0200 Message-Id: <5c3b7459b820e22e2ac6ce892d4aadcc119cc919.1696065263.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Sat, 30 Sep 2023 02:17:14 -0700 (PDT) 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 checking via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). Signed-off-by: Christophe JAILLET --- This patch is part of a work done in parallel of what is currently worked on by Kees Cook. My patches are only related to corner cases that do NOT match the semantic of his Coccinelle script[1]. In this case, it is been spotted because of comedi_alloc_spriv(). All other usages of struct comedi_lrange seem to be static definition of the structure that explicitly set the .length field. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci --- include/linux/comedi/comedidev.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/comedi/comedidev.h b/include/linux/comedi/comedidev.h index 0a1150900ef3..c08416a7364b 100644 --- a/include/linux/comedi/comedidev.h +++ b/include/linux/comedi/comedidev.h @@ -633,7 +633,7 @@ extern const struct comedi_lrange range_unknown; */ struct comedi_lrange { int length; - struct comedi_krange range[]; + struct comedi_krange range[] __counted_by(length); }; /** -- 2.34.1