From patchwork Sun Oct 1 11:07:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 147135 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp958431vqb; Sun, 1 Oct 2023 09:35:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMSsE4bKg+tZ+SLYaRI5uuiFmgWPual1yjSnJSZ/+jEQeXZFGIqkQYsagQCk9IJyaYstWm X-Received: by 2002:a05:6a21:9995:b0:15a:4c23:870b with SMTP id ve21-20020a056a21999500b0015a4c23870bmr14092299pzb.23.1696178143843; Sun, 01 Oct 2023 09:35:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696178143; cv=none; d=google.com; s=arc-20160816; b=T//SXcm7WVxuo6JXKivT98AJQUCu+fC3i1kq6bQVTVKs9ifns9qwW4xlzPwPC7BPYf JY/IUfrVsfyk8EUSl42fzLfC0H/uGYrNwsVPSjgHosICKlz9zvvm9Oz/aOv3ttvZj507 HG2CDu9eapeWRmxPZSs8I1ApRn0hMrGPm8GsPIPS6aE0Dq2jrsdITNQOl0mJvsWqrWZn faodpvex01Fwsl+DusZX6VEAg/Jnos9g24NIyUqlKf4h9hcR+underjGeFP+ZYF5F8Wi F3kiyKFkrA7hOwf8S+L62JYna5EwoTl/jvf4P8uu2/8V82JiJBOdyJJoO7RqJPg4mu9J gESA== 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=v9P7JS8Eo6gg0JgpQ/a5dnlXc7ZeGy/7g3pcTmVCJ18=; fh=144h59Trx5ef5R0VkTN5OfufadNCskPabTmJJAa01IQ=; b=W3HOZPmCImIm3vvqnCRp1A/D1/Vrh2p30ikLh9RCTb21qHs40mE2i3ShFFdkV1CTLJ gGXS3TaXdNf5wqZTeCPalUpJ3qoXwSsCo63PI7754HDv9BSwdM3Lqxa4JcIohhXEBDxf hDye2VMfqLBzQOJdV+mBL3YbHIer9ILSSUaURtXAmLMfocw8jfsssxQO2aSFZ5MZNB/S JmiGE4raFGHG2G27xkrHOJU6ttAayovCp+yWjSIIt70Rrsb5SSZGHde8jSkHS29oG3Zj 4C6OCJUj+kmKEZsuJpMxNvSb4E9VxWrZtvrS1N+TlAtabVxe0aMiWFmBFDkVzHYa933+ pfqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=OcrHXPEw; 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u23-20020a056a00099700b00687008df88dsi28311717pfg.52.2023.10.01.09.35.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Oct 2023 09:35:43 -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=OcrHXPEw; 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 0D3D7802887A; Sun, 1 Oct 2023 04:11:01 -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 S234886AbjJALHn (ORCPT + 19 others); Sun, 1 Oct 2023 07:07:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234873AbjJALHk (ORCPT ); Sun, 1 Oct 2023 07:07:40 -0400 Received: from smtp.smtpout.orange.fr (smtp-26.smtpout.orange.fr [80.12.242.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A66EDD for ; Sun, 1 Oct 2023 04:07:37 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id muIKqTqNAm6tamuIRq8U3c; Sun, 01 Oct 2023 13:07:36 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1696158456; bh=v9P7JS8Eo6gg0JgpQ/a5dnlXc7ZeGy/7g3pcTmVCJ18=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OcrHXPEwJq5ccOGM2WWXMREYaA5x0o3Tt5f28aR5RqTrPTdP8zPl6Hd6n0mtT99Tv 1KHlmqCZPA7tCaA0QYbYkbQ+SmOJPAc2RDlcL6TtG0gyKE8KZP4+U9/GKRDBW+GCp6 VzWecaU8rn3uaqyZ8qYdCITjFOtAqHPeX3w6zoM+d5R8cWW0FBa1TCFlMIuXAoNNSv yNqQoese2sMY/E4nuu0QocTSjow/jUUN7brb7p0UkkKckCpc7lPXVcsS6Fk3d0bA9m tpBLPy4DIdYTZKJVl6e1HeXg7sdsUnpTyrqCh2IyL22dIUZesYXZbSffSWzSu9wvfM IkgecWhFDL3cQ== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 01 Oct 2023 13:07:36 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: keescook@chromium.org, Pravin B Shelar , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Tom Rix Cc: linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , netdev@vger.kernel.org, dev@openvswitch.org, llvm@lists.linux.dev Subject: [PATCH net-next 2/2] net: openvswitch: Annotate struct mask_array with __counted_byUse struct_size() Date: Sun, 1 Oct 2023 13:07:23 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: <8be59c9e06fca8eff2f264abb4c2f74db0b19a9e.1696156198.git.christophe.jaillet@wanadoo.fr> References: <8be59c9e06fca8eff2f264abb4c2f74db0b19a9e.1696156198.git.christophe.jaillet@wanadoo.fr> 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]); Sun, 01 Oct 2023 04:11:01 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778571693591514396 X-GMAIL-MSGID: 1778571693591514396 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, 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..8d9e83b4d62c 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(size); }; struct table_instance {