From patchwork Sat Sep 30 09:14:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 146905 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp299903vqb; Sat, 30 Sep 2023 03:11:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELkkxfLtMuhT5H8jCqNQQ8re+2Bw607AvH0qKwq3hOo3S3ZxZFnR7OhqVWqzzNwbmtIUkQ X-Received: by 2002:a17:902:c409:b0:1c1:e818:1e76 with SMTP id k9-20020a170902c40900b001c1e8181e76mr9921644plk.6.1696068684248; Sat, 30 Sep 2023 03:11:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696068684; cv=none; d=google.com; s=arc-20160816; b=IY9BlK1xbOKbluryo8DsjtZERwnGYHTmxQ5QjR9Xn4PXffAIR9kaYg9wIxLTzKun+S adXZsIIYz58opuwoTQ00rKtkj53rUd92jzsE9+yrGcirgM6UTCvPl90vo6dzkTqUqQEl fpIXtIORtMr6iTlz55z4sqSaPGPofCM5t0drAUDguUW/qnGWTmLiXcQseqdPv4k54oUn fxJbQcXsG6yMXDqsCwa6ck1DAJVzY3bbhIL8Z0PPUr696f9lsers8pqdv7Ko0gDlQV+E t6PNzMEfYfFjRWC3mcxckcVGvdm1E1C3io03wJoXLFBJrLI72ZmFSDQCGWa44ttgLUR5 kNcw== 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.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id kn11-20020a170903078b00b001c74d844254si2121475plb.101.2023.09.30.03.11.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 03:11:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; 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.37 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 snail.vger.email (Postfix) with ESMTP id 37BE480236EB; Sat, 30 Sep 2023 02:17:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233945AbjI3JRF (ORCPT + 20 others); Sat, 30 Sep 2023 05:17:05 -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 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_PASS,SPF_PASS autolearn=unavailable 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 (snail.vger.email [0.0.0.0]); Sat, 30 Sep 2023 02:17:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778456916450940366 X-GMAIL-MSGID: 1778456916450940366 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 Reviewed-by: Kees Cook Reviewed-by: Gustavo A. R. Silva --- 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); }; /**