Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1390981rdg; Fri, 13 Oct 2023 23:35:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEoI1+D3ltjqWCChXggScz+YGcdf9pyUJDAODF162/ImqZYNpHZE/mslUgSHF0Tm+YkynBL X-Received: by 2002:a05:6a20:938b:b0:15a:2c0b:6c73 with SMTP id x11-20020a056a20938b00b0015a2c0b6c73mr36061102pzh.12.1697265325415; Fri, 13 Oct 2023 23:35:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697265325; cv=none; d=google.com; s=arc-20160816; b=dF6DKu80PGMa5IQ5RC7D60etV3y5jdGFiheGptRJu8Oa7z8WjVXw/4pEqWuzo99NZw 5CalY1ylHMGpDIIft2ffKluEd4PYatZU7stBmAViujc4PtAAP7UfuRW7DoI/iLC4kKoG 1qF9JsQuX1qFUD0U5WNnd6lF1pmfpAIAOpeyYKSe/OXqVoQjQeCUwplJcHaby7IOOTOh wMb9+4Y8WtkwBP98GcspcjMrljyRnIydWcfZxnTeQ8aGfyw7l0ClI5MT9FPoNr3yF1Tm ZMf9XLCiEGcvgVd8fJnGuYyk7aIpg8HWD22EzodR3IyOyIWcjbLYvnkwtxqg12xvLq5G +Dyg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=il89cLsUPoSfIl2uIujuHP4uRIM1OQ8+x9zRodfnRok=; fh=9f2O41dF/TFCRuO5jv6hcpAYGB/GIkxDZ3LjRHbLiuE=; b=pduFCVXqCnyl4d89vkdXalhi+jcLet5pq6dNHvDZgzvlsf725GI7WeejLcOP/Yjne2 li8AmfxxMUVhoN9mmiXzhG0X+8PPYWRkPwlusFpL2iJwVz450443iM6n3KdYLUZ/nbrA PTKwGwxeOkc9lEgON8FkV2px2/6blYKb9l2gP/wbDzUJzfKNjz6cypSB2E4xuUO4+cur tFUAM47s9bRp+srNwRsCsHcj7Y5+bD73QiRXw6V7/2blOsnScjzovP0ssKYSrXYsGtAt uW1IOxsWvoiS5CpNIvGWpPSqwFZf4ml0aOH+afU6rHM/BLTYEcVDMEjxKVNMyovoeUp/ WroQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=Bo+61VSX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id a13-20020a17090abe0d00b002631e44f48csi1674923pjs.179.2023.10.13.23.35.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 23:35:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=Bo+61VSX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 8D08880C5939; Fri, 13 Oct 2023 23:35:24 -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 S232870AbjJNGfQ (ORCPT + 99 others); Sat, 14 Oct 2023 02:35:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232840AbjJNGfO (ORCPT ); Sat, 14 Oct 2023 02:35:14 -0400 Received: from smtp.smtpout.orange.fr (smtp-14.smtpout.orange.fr [80.12.242.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58C9283 for ; Fri, 13 Oct 2023 23:35:09 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id rYEiqpnupvhM3rYEtqYMoq; Sat, 14 Oct 2023 08:35:08 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1697265308; bh=il89cLsUPoSfIl2uIujuHP4uRIM1OQ8+x9zRodfnRok=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Bo+61VSX/YyYHCKiYBpJL1M4zOyIazFJEkWMUYYuOZqqleYlxrRVIWb5m9/g/i2fk /mQgtot4aePqBFtElrsXiGMGf5KEJ4gObLlcrOg2AT7E8FiuLIIy8w9LlFI5aikPrA WEpS8BipFODvU5kvBv0CRASebxqMW9PzIhLsTjuYoW5kMujbLL2jeuQFVJD6XNLPz6 QRELQx1T+AF5t8a4aMQxgdNyOYAkg2CkE5AtMEZWBLHPaFs7yYPB0Q9ebCjXDTqe5g Fwi4uo3NH/U9hS6shMji3XkK8YyMNjJjJ9XxaHF65GbJRWwoi3n57YNfnv8yG1/vNJ C5YpJmAFysrEg== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sat, 14 Oct 2023 08:35:08 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Pravin B Shelar , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , 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 , netdev@vger.kernel.org, dev@openvswitch.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH v2 2/2] net: openvswitch: Annotate struct mask_array with __counted_by Date: Sat, 14 Oct 2023 08:34:53 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_PASS autolearn=no 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]); Fri, 13 Oct 2023 23:35:24 -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 --- v2: Fix the subject [Ilya Maximets] fix the field name used with __counted_by [Ilya Maximets] v1: https://lore.kernel.org/all/f66ddcf1ef9328f10292ea75a17b584359b6cde3.1696156198.git.christophe.jaillet@wanadoo.fr/ 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, in tbl_mask_array_alloc(), several things are allocated with a single allocation. Then, some pointer arithmetic computes the address of the memory after the flex-array. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci --- net/openvswitch/flow_table.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/openvswitch/flow_table.h b/net/openvswitch/flow_table.h index 9e659db78c05..f524dc3e4862 100644 --- a/net/openvswitch/flow_table.h +++ b/net/openvswitch/flow_table.h @@ -48,7 +48,7 @@ struct mask_array { int count, max; struct mask_array_stats __percpu *masks_usage_stats; u64 *masks_usage_zero_cntr; - struct sw_flow_mask __rcu *masks[]; + struct sw_flow_mask __rcu *masks[] __counted_by(max); }; struct table_instance { -- 2.34.1