Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp251142rwb; Mon, 26 Sep 2022 18:17:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM72SnRnzByVInr5LbSYFRu578lP4fqXbAFvJ2PsLoP/p3Hl7nyVK2CnnaBE8azLs+iaybYz X-Received: by 2002:a63:50e:0:b0:438:d16d:e8c1 with SMTP id 14-20020a63050e000000b00438d16de8c1mr20993087pgf.505.1664241426785; Mon, 26 Sep 2022 18:17:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664241426; cv=none; d=google.com; s=arc-20160816; b=wRUUDuTW7/NQRIpRAGOAHqdAU5RwlOuvg44HNXii7Xl2vQIVTxN3Gkb5zIzufem1BV J+o8Y1TQGmnT6LZ7PjeKFAkoY0WY9dZQNNLCNJvLsPAYAzunf/iKrKHbxFVoOYeidWGk AXAyEi6U7Ej/xDrnh76txLd+Hvx/SloOGxuiN9gm/XXwf1QAULYYbYkp/sM8O0OKOqjM QZmExaMjNM3Kc6W61Kr5gndIGhG91O63chx1TKfp2bgKfUISwOAjeTHJn0j9HiME/9bV gu5y3q+SbbMaGP6d6Ej10Ya11wu7KAL/KpCr1l9UTodKn/QDofNzimExN2FhSq00l/fN DxTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1GxBbSR4yqwJwjBA8bT8/69+K6WYMr51niImq21qYAw=; b=mowl3eJbe8Yvq3TiIm64imol66I08Wl40EjnowVN3zowrzLIGKEugL3Lgz6HWDspDx FgBVuciOtM9PSz4NnMQrlNlGL3n89EJ29GAaMMHjOljPdQnF6sI0NVzcJtZ0ZZIiGWLq NkTOxMoS+G91fWLvCretmqcxXDXREMlV+KnGOrYA05m2UmXidHl8haJjNfdD/j8EvySD DDlfSv6QLB83I4m7ySbPdLQLe6z+aOXxNMWl58tnpx863kPF4U+Y/l7yi3x1Yzr9OgfJ /zAMMzzEcElxWoduoVyg6Oy4Zxr+y2JXl4QwoQjPDmWszfW0LJrPGPhAZGSi6nKg5gxd nB9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CRuS58M9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h10-20020aa796ca000000b00557e99763d3si411729pfq.93.2022.09.26.18.16.54; Mon, 26 Sep 2022 18:17:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CRuS58M9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229705AbiI0BKY (ORCPT + 99 others); Mon, 26 Sep 2022 21:10:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229488AbiI0BKW (ORCPT ); Mon, 26 Sep 2022 21:10:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34C94895FC; Mon, 26 Sep 2022 18:10:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 782C5614AE; Tue, 27 Sep 2022 01:10:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 338EAC433D6; Tue, 27 Sep 2022 01:10:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664241019; bh=j62kZQvZjX2MamKzJ/+2NC/9HEZsfcjCjPmXppmw/ak=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=CRuS58M9M+FfroV0sQPqfmHUUVvXOqFwVGgzs32D9um7RsRmxhFQ7Nv82cFf+4sY1 1gjxMKqjMZ2snLZfN6iuHQm4ZBS8aiS7Yie8dghI4kv6BMe+da/eVcasQTwMVIBNYh 4n1+N9/vsEuehVP17xTUkJZLMVffj+rlYZudbfp3DJAZWrswhbZLmYHAKaTe3eedTo NeyqB3EKIzH4QjQmCg5SVxPGDWUe8uSKetVJ/bNUnCzrjxJm++JsgeW+EXsk784w4m t+z1nEO+ciQVGm8N9W8mG+Rwaa06WrYBfmrXnYncQTGuCQW9558/CHH0+cdYFgIgVl 60AGILne4eOcQ== Date: Mon, 26 Sep 2022 20:10:11 -0500 From: "Gustavo A. R. Silva" To: Kees Cook Cc: Ido Schimmel , Petr Machata , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] mlxsw: core_acl_flex_actions: Split memcpy() of struct flow_action_cookie flexible array Message-ID: References: <20220927004033.1942992-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220927004033.1942992-1-keescook@chromium.org> X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 On Mon, Sep 26, 2022 at 05:40:33PM -0700, Kees Cook wrote: > To work around a misbehavior of the compiler's ability to see into > composite flexible array structs (as detailed in the coming memcpy() > hardening series[1]), split the memcpy() of the header and the payload > so no false positive run-time overflow warning will be generated. > > [1] https://lore.kernel.org/linux-hardening/20220901065914.1417829-2-keescook@chromium.org > > Cc: Ido Schimmel > Cc: Petr Machata > Cc: "David S. Miller" > Cc: Eric Dumazet > Cc: Jakub Kicinski > Cc: Paolo Abeni > Cc: netdev@vger.kernel.org > Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Thanks! -- Gustavo > --- > drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c > index 636db9a87457..9dfe7148199f 100644 > --- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c > +++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c > @@ -737,8 +737,9 @@ mlxsw_afa_cookie_create(struct mlxsw_afa *mlxsw_afa, > if (!cookie) > return ERR_PTR(-ENOMEM); > refcount_set(&cookie->ref_count, 1); > - memcpy(&cookie->fa_cookie, fa_cookie, > - sizeof(*fa_cookie) + fa_cookie->cookie_len); > + cookie->fa_cookie = *fa_cookie; > + memcpy(cookie->fa_cookie.cookie, fa_cookie->cookie, > + fa_cookie->cookie_len); > > err = rhashtable_insert_fast(&mlxsw_afa->cookie_ht, &cookie->ht_node, > mlxsw_afa_cookie_ht_params); > -- > 2.34.1 >