From patchwork Sat Oct 7 14:32:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 149593 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp959765vqo; Sat, 7 Oct 2023 07:34:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHFoe1FltNoDKvI0xh5ztNgeWdtMgrXwitGuWy043+6nNTFxsfxvpSLlYzsdCEVZVb8e7Wx X-Received: by 2002:a17:902:ceca:b0:1c8:90bf:4239 with SMTP id d10-20020a170902ceca00b001c890bf4239mr4719999plg.42.1696689283531; Sat, 07 Oct 2023 07:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696689283; cv=none; d=google.com; s=arc-20160816; b=zGoA6fODQVD5cgb/ZcYQO3YY5zXj8wMpgQUmpyrVJD6C+jZ7oEi/ex8QZcnvChhU1b 9Hv/2+zsc0IIQc+IB6nBzfUBCHZx86rzo3rlVyk4PHLalAu6qCOsjTiyxqMHcDD957Iw sZMOA3f+nZU98abQ2ub9cZCS3yzLvVJp7KuA5QFdn1f2Ug+wLn0joyduRsT+YaYfwkzN 0CJplYSXwsnE4TZnZOS9ShVsOn846ZHS51/kKVRRE1GGZDF94x/2SykmmxbIbLWM/bSR xCBMxRORw7pZrZCT3HzirOybVIjv+LPkATdhsuM8uZm1FuqIvuxJYs7YR+H2gEaAcbXf uNrw== 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=MjiCcPHgIztJA3fnnekG+6x6iUsfkXWEmL8zOsP0oyA=; fh=hl6wn4RpYz//prpT+q5DsHjav4qytMqv98zxFlIrLj0=; b=xOsZtglNznVRdEhIW58W0rqmIxVbLx8cgOJ2PP0h+4IQ5TkFlpSQ1TCr4ykGqsbbpT GCuseou507XKWgghTJpFtqM+A0Xptxx4KtzbKxEV+ZPsxyWSiDSeEQWOyDJOXi9ATrT4 T771WZ9iscdfqN+Wa4O7j9PA2v/oF56NjpOxNDhVLf9B+mxGOeW+I7a66OQZZse0bK4h muZnfvapZeXmTOj2iPl90CkLojuF5je1tw2NvimtG6dF1385O34we9S4IqoHyR1+T3T/ khvtjdeDGbvxW0cdEwOAz6D2uw9bEU4WW68gkqEXTrjXRgSOHulNazbZPMLi8K6qhCg3 p2vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=aaTGehvo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id u10-20020a17090282ca00b001c71f14ba7fsi5754995plz.247.2023.10.07.07.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 07:34:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=aaTGehvo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 46ECD80A8B96; Sat, 7 Oct 2023 07:34:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343934AbjJGOcm (ORCPT + 17 others); Sat, 7 Oct 2023 10:32:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231310AbjJGOcl (ORCPT ); Sat, 7 Oct 2023 10:32:41 -0400 Received: from smtp.smtpout.orange.fr (smtp-26.smtpout.orange.fr [80.12.242.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69620BA for ; Sat, 7 Oct 2023 07:32:39 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id p8M7q9ALBzRICp8M7qMa0a; Sat, 07 Oct 2023 16:32:36 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1696689156; bh=MjiCcPHgIztJA3fnnekG+6x6iUsfkXWEmL8zOsP0oyA=; h=From:To:Cc:Subject:Date; b=aaTGehvocX9wx7mzR++6IjvE/DnvOr1TK37GENxTG7UcuGGj71s15N9fuweFAnxxI ESKXegYY0HxgSvoQRDsUPvuPSW94PdhLG0UFGRucogB/jIThA0DThR8TbAWUEhnqIl 26R7DE6KcGns2SgqBf9EnJQky6wt4TVQnHPjiSiRPCBw5yI0xWJ6jnblqxZwpIn0Qt FOWsYidbppIjC6EYKl+1Hkda0hbZqfdw0FgIVGY/Dzwt7D4JpP6DCAGUPFxSUmlFAI AhAlenwT1BDhFtdxtXbNTiZUZ2RB8kvdPktkfqSoBnmQL+Q8GANy/OroO97bNapOIh RC2t7Cv91bz3Q== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 07 Oct 2023 16:32:36 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Bryan Tan , Vishnu Dasa , VMware PV-Drivers Reviewers , Arnd Bergmann , Greg Kroah-Hartman , 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] VMCI: Annotate struct vmci_handle_arr with __counted_by Date: Sat, 7 Oct 2023 16:32:34 +0200 Message-Id: <56bef519d982218176b59bbba64a3a308d8733d5.1696689091.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Sat, 07 Oct 2023 07:34:41 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779107661820888701 X-GMAIL-MSGID: 1779107661820888701 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 --- 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, something similar to struct_size() is implemented in handle_arr_calc_size(). Note that I'm slightly unsure on how things will behave in regards to the krealloc() in vmci_handle_arr_append_entry(). [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci --- drivers/misc/vmw_vmci/vmci_handle_array.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/misc/vmw_vmci/vmci_handle_array.h b/drivers/misc/vmw_vmci/vmci_handle_array.h index 96193f85be5b..b0e6b1956014 100644 --- a/drivers/misc/vmw_vmci/vmci_handle_array.h +++ b/drivers/misc/vmw_vmci/vmci_handle_array.h @@ -17,7 +17,7 @@ struct vmci_handle_arr { u32 max_capacity; u32 size; u32 pad; - struct vmci_handle entries[]; + struct vmci_handle entries[] __counted_by(capacity); }; #define VMCI_HANDLE_ARRAY_HEADER_SIZE \