Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1867650rdg; Sun, 15 Oct 2023 00:21:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0JsE7+ULfjKotx7yamdoq9IFiwWBVS4GKF9maPY1ZsmuXLk8EAywnCCfqyMKuGa/pu5/j X-Received: by 2002:a05:6a20:7fa8:b0:159:c2d0:9fc6 with SMTP id d40-20020a056a207fa800b00159c2d09fc6mr40271564pzj.8.1697354479354; Sun, 15 Oct 2023 00:21:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697354479; cv=none; d=google.com; s=arc-20160816; b=lF0hSnYIQR06zAzphffufYWWVwhUthi3+bDWT9/eWO41231lbmj6n2nIhIQAQG8AVN yKY+u6xBze5LNZ1hVV/tpI+iQQb5dYH5VkjCxuKUrJYH6ruDDxw/yFAt1DYhyQ8vh29k budOLoBAVNdpITS12WrMy4Ut7QIm07WzWQZxKsDURItfLEN9VFSNEsIw0YhSl2SdKulO nZLVwX1Sl09UzHKDaBTXxyfErhkduGIX3bp87K/qefmaY8ho6ekJHkbMvICI8vqvasf6 YXb/m2LBN5WngWxN+89v48QN2a2eMj1u6kS4YLoO9fYVbfz97BSIk7EvDR2ylK2gXkAi WkqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=CkMEGgZwHRms+QfdcCyXBzqoAD058xSJsj4PCuedEAQ=; fh=6VFkPtf4ZsVEMQRCc8KPWuoKanpEWZezvMfvgAikQxw=; b=NW2BF4LcnkzooTlyXTBj2Y0zTRPAggA4uNTx4YyjPeZA49a6XNuyrIT6LAJZCM8LPH b3cHbsXF6iI7INNWhrWGLi9Gkx6Dy6OYG9SVxzHUfejGGGLZDCKraDeIIrtBJj9zXGAu 4MH4De/HAEmzyqzvR6VSCCiNk6KWpb6S4TBQ90CRfv4kT3mPJL1WLTN+AmNbXgx8ZxHg gFcfH4fHHJgzApRPTZ0wAHREiLWHxXsZOlELtC+d5HfsMVUMrsy7Rpg+dsCZ7n+qjj75 6nti62tLvenWpL/NEqWNYkk/p+yZg4xCqIHfTes4RN8ZuwlAdjjHAg3g/oRvlliFqcqY lYXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=ZVOR5zlD; 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 Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id e193-20020a6369ca000000b005859aa3da1esi8117243pgc.492.2023.10.15.00.21.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 00:21:19 -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=ZVOR5zlD; 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 2F995804DD94; Sun, 15 Oct 2023 00:21: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 S233218AbjJOHVJ (ORCPT + 99 others); Sun, 15 Oct 2023 03:21:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229872AbjJOHVI (ORCPT ); Sun, 15 Oct 2023 03:21:08 -0400 Received: from smtp.smtpout.orange.fr (smtp-23.smtpout.orange.fr [80.12.242.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A0E9DC for ; Sun, 15 Oct 2023 00:21:03 -0700 (PDT) Received: from [192.168.1.18] ([86.243.2.178]) by smtp.orange.fr with ESMTPA id rvQlqlOldkfHLrvQlqgQkx; Sun, 15 Oct 2023 09:21:01 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1697354461; bh=CkMEGgZwHRms+QfdcCyXBzqoAD058xSJsj4PCuedEAQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=ZVOR5zlDJkFJ22EOrV+ZfsTbTSzjgzsqCxZxSnUVlguN6lErURSadOdj2w+Mk9uMx P99tBfga5DvYePOn/p3vjsbXzzwiTwWxDdHHY2SZdDgBVfLhtoJr8FE3oN9qND4K1a V/mQzgQDkyiPUEMuEJf9b4Zfi8fSx3PIyQbQ0Lj1e30loOmLyyS9k1js+3Zampf6mF sMCb8DNq+oVm40lKiPE72jZwKBpMKIQdpQOPQLbYgiFWbk770aK9qoXXVcv+X6EVKP QT51jR2XXBLHV3wfVg4bMLChtItL1pC4otPGwlfDCi3fItU8IqDQ5KcnEM7qZJjjyM WSgiA063ZpkHw== X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 15 Oct 2023 09:21:01 +0200 X-ME-IP: 86.243.2.178 Message-ID: <61b78f8e-98be-4392-9d3b-f1d211adb384@wanadoo.fr> Date: Sun, 15 Oct 2023 09:20:54 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/2] net: openvswitch: Annotate struct mask_array with __counted_by To: Julia Lawall , Kees Cook Cc: Pravin B Shelar , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, netdev@vger.kernel.org, dev@openvswitch.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev References: <202310141928.23985F1CA@keescook> Content-Language: fr From: Christophe JAILLET In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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_NONE, 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, 15 Oct 2023 00:21:18 -0700 (PDT) Le 15/10/2023 à 06:53, Julia Lawall a écrit : > > > On Sat, 14 Oct 2023, Kees Cook wrote: > >> On Sat, Oct 14, 2023 at 08:34:53AM +0200, Christophe JAILLET wrote: >>> 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]. > > What was the problem with the semantic patch in this case? The allocation in tbl_mask_array_alloc() looks like: new = kzalloc(sizeof(struct mask_array) + sizeof(struct sw_flow_mask *) * size + sizeof(u64) * size, GFP_KERNEL); We allocated the struct, the ending flex aray *and* some more memory at the same time. IIUC the cocci script, this extra space is not taken into account with the current script and it won't match. CJ > > thanks, > julia > > >>> >>> 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); >>> }; >> >> Yup, this looks correct to me. Thanks! >> >> Reviewed-by: Kees Cook >> >> -- >> Kees Cook >> >