Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1339398iog; Thu, 16 Jun 2022 04:26:32 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sMJxOGpxsQ8DXKpElU/BklzQw5aSd+tSldJ6aYEw94cczh/Io1KfdTpY+aAm27AyBEDvL4 X-Received: by 2002:a17:90b:3845:b0:1e2:e175:be04 with SMTP id nl5-20020a17090b384500b001e2e175be04mr4603340pjb.50.1655378791899; Thu, 16 Jun 2022 04:26:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655378791; cv=none; d=google.com; s=arc-20160816; b=Ky3eMJ/RAfrFOtI5O3Oy4KxIykGOUMGVgnG1mXn3gf/CFXCKze7mqRd0rJHy0deLGr apD914d4JywyzF7gIh52d0sMHhI63vcMrqVMU+ojDSF4WmUxoVOYFGDRRFLyqDc8+Wl3 RISPSveHpYbqqdcmtc644Ii52sPY8JbXQgjIlFYblKh1VUM3d+lCqWchJc+sT/LSI2a8 QBJ8F+gaE9JpuWflkFXpHCFJH2Q1RPVjsBRSt0vl9Lri4f6hYSiyeWaR/UXc4wmmJJY3 iCoA7Kds4Csix5X7v/4hSMtc6Dht2/4msJYqOK9JtgNNkQ7Z/58nHmkP8b0tZPHcxFbs ow2A== 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 :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=IfNIAqzersyDV8nNIwaREImkJNE8UvYTeYLFrLHtknY=; b=Ct93gttrwy6xynHBcTmytaBlnh7XY/XSjiqV4RgPlCaZTiIE4U0iw7wY5PYP58DRwi JCQOkz9bM9t1Dkuc8qItAZ1yoWaPJWMxo2jy0rydwkixHy+KrBoRbaM+Xha+Zl8GrCDq 5sC4iJ+ZNXEI6MA0Ql9M8FwB3gTQZ1o2a6XPLenLsXwsFiw55/aD43mY1WogSrTjlwfx gFmgxUcszME3N2ZuzqsuJEEYx9onEPsExC3AT8PH7XCpH8SXv6jCnPSMkHBSG0wcnvdF FYTPzmq9Use/pigHisQ2h/WERk5XMPjzueo8w7/B2mZCmTmtzkh93ujJYeWmRblr7vvV Toyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=kPRyWpB9; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e5-20020a17090a280500b001d984c76f9asi2146212pjd.127.2022.06.16.04.26.18; Thu, 16 Jun 2022 04:26:31 -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=fail header.i=@embeddedor.com header.s=default header.b=kPRyWpB9; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376406AbiFPLGW (ORCPT + 99 others); Thu, 16 Jun 2022 07:06:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376387AbiFPLGT (ORCPT ); Thu, 16 Jun 2022 07:06:19 -0400 X-Greylist: delayed 1345 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 16 Jun 2022 04:06:18 PDT Received: from gateway34.websitewelcome.com (gateway34.websitewelcome.com [192.185.149.105]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FE935DE4D for ; Thu, 16 Jun 2022 04:06:18 -0700 (PDT) Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 52F3F19CB68 for ; Thu, 16 Jun 2022 05:43:53 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id 1myfoTO9LdLf51myfoMArA; Thu, 16 Jun 2022 05:43:53 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=IfNIAqzersyDV8nNIwaREImkJNE8UvYTeYLFrLHtknY=; b=kPRyWpB9ZJNGcPo10dGSmxUtl3 QtC/oUlh+uSnB6bKYV44YoyUUKu0+iyk6Sbc7mca4JPVPG4c8b328m/GdqFsGLoYSzYYOWy1iTQQg ZlvgqLcohMKojwvaQh9L1bj4MzPSIS1h+FzenkWHLglyG+RF+SJ6kdPtMzJDTw+wbN4zdMHbHHSeU 9PVbuLdKTULCN5jPZBTCNDOopp5KGX5oVv0YnVaEYM//CEn0LCB/x5b+DTLbcc5KSy4ci1Dwgi27L g8a20UIJaaGrRtrIQS8f+EB08/8HcED8iQ3MsW56XUoFFg3BqzB/cjOKj8NwCAuYS/2hQ6xKUdgqA NCnR1nwQ==; Received: from 193.254.29.93.rev.sfr.net ([93.29.254.193]:43842 helo=[192.168.0.101]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.95) (envelope-from ) id 1o1mye-003dLc-9k; Thu, 16 Jun 2022 05:43:52 -0500 Message-ID: Date: Thu, 16 Jun 2022 12:43:40 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH] hinic: Replace memcpy() with direct assignment Content-Language: en-US To: Kees Cook , "David S. Miller" Cc: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Nathan Chancellor , Nick Desaulniers , Tom Rix , Leon Romanovsky , Jiri Pirko , Vladimir Oltean , Simon Horman , netdev@vger.kernel.org, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <20220616052312.292861-1-keescook@chromium.org> From: "Gustavo A. R. Silva" In-Reply-To: <20220616052312.292861-1-keescook@chromium.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 93.29.254.193 X-Source-L: No X-Exim-ID: 1o1mye-003dLc-9k X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 193.254.29.93.rev.sfr.net ([192.168.0.101]) [93.29.254.193]:43842 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 2 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 6/16/22 07:23, Kees Cook wrote: > Under CONFIG_FORTIFY_SOURCE=y and CONFIG_UBSAN_BOUNDS=y, Clang is bugged > here for calculating the size of the destination buffer (0x10 instead of > 0x14). This copy is a fixed size (sizeof(struct fw_section_info_st)), with > the source and dest being struct fw_section_info_st, so the memcpy should > be safe, assuming the index is within bounds, which is UBSAN_BOUNDS's > responsibility to figure out. Also, there is a sanity check just before the for() loop: 38 if (fw_image->fw_info.fw_section_cnt > MAX_FW_TYPE_NUM) { 39 dev_err(&priv->hwdev->hwif->pdev->dev, "Wrong fw_type_num read from file, fw_type_num: 0x%x\n ", 40 fw_image->fw_info.fw_section_cnt); 41 return false; 42 } so, this should be fine. > > Avoid the whole thing and just do a direct assignment. This results in > no change to the executable code. > > Cc: "David S. Miller" > Cc: Eric Dumazet > Cc: Jakub Kicinski > Cc: Paolo Abeni > Cc: Nathan Chancellor > Cc: Nick Desaulniers > Cc: Tom Rix > Cc: Leon Romanovsky > Cc: Jiri Pirko > Cc: Vladimir Oltean > Cc: Simon Horman > Cc: netdev@vger.kernel.org > Cc: llvm@lists.linux.dev > Link: https://github.com/ClangBuiltLinux/linux/issues/1592 > Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Thanks -- Gustavo > --- > drivers/net/ethernet/huawei/hinic/hinic_devlink.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/drivers/net/ethernet/huawei/hinic/hinic_devlink.c b/drivers/net/ethernet/huawei/hinic/hinic_devlink.c > index 60ae8bfc5f69..1749d26f4bef 100644 > --- a/drivers/net/ethernet/huawei/hinic/hinic_devlink.c > +++ b/drivers/net/ethernet/huawei/hinic/hinic_devlink.c > @@ -43,9 +43,7 @@ static bool check_image_valid(struct hinic_devlink_priv *priv, const u8 *buf, > > for (i = 0; i < fw_image->fw_info.fw_section_cnt; i++) { > len += fw_image->fw_section_info[i].fw_section_len; > - memcpy(&host_image->image_section_info[i], > - &fw_image->fw_section_info[i], > - sizeof(struct fw_section_info_st)); > + host_image->image_section_info[i] = fw_image->fw_section_info[i]; > } > > if (len != fw_image->fw_len ||