Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1132698iog; Wed, 15 Jun 2022 22:38:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v12qOhK/mH4Y2bFkXOMxN0Zp1zaG7E6Nvt4EtIoKv7C4ZACZsS1WWChL6kw5gM+JNi5o8x X-Received: by 2002:a17:907:908b:b0:703:9e42:3d07 with SMTP id ge11-20020a170907908b00b007039e423d07mr2948037ejb.748.1655357887114; Wed, 15 Jun 2022 22:38:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655357887; cv=none; d=google.com; s=arc-20160816; b=OecnnpIuq7jxmaHkO4KGNqqMDy9ndJnHqxnKeB+eS6KtwV4rzxh3H+9SXsd9Y3Gphb yfZMyMsqF7GTZLd+H1eteeOuGmytsojxzttM3uL0mGL3nJydhjKHpW68k6uuGLy6HN2Q qJO7bS8tDAwa6nz+q5cpsYewBrSEmVp6K7oV9DRdk8UbGA/9XwZyk26mNbSUj3yQ2j7w msyhBR/nYLHlhD+t6SBzJchi6ZT5vkrbjGbsJIDsc5zy+USumJr15vrdfKecD2AYA7GZ NgPjNF6ZO8fjZuVsoEC4JjdB009AA4a7Q4j5khrqHLEiKkmk1KggLqq/NdmaxGrLw3cT K0pA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=gLwzCgeGjXvkAY0tAtafYy0s/ZAsW8+7L0BV4I3ZRUg=; b=ahpjR/DW5Yet7takTIukC3jTFoHFBSn/xJN8qWwc42IYCSvclQGKTxwGf4WnXKIaXK S+4ZFQ6e1x7s3Rioju7fDFJ6MjRpPF/f+RP31ti1wPWuOVJhuX9Z/QbRaYIJFI4a6k3X LzDra7l4adtmcudFsnQBBRjkJKk4ms2S862Z7uljgp6MjPFi9TGadSY372m69x1UkXwh AhYgsW7NHKgUqJMKC3Bb+4DfL5h/k3qUOeeRnelvsypbAN2dWilvbrHGG6fCcObMyHyB pS5IX6R3SbMZEdQ3Buqy/A6z0CAULn5jfEfdMd6tnXXjtEPB9qx+E3+pUGq0tNSIKk35 7lew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=i8Jw1IH6; 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=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f18-20020a0564021e9200b0042dcf5f5921si1532360edf.597.2022.06.15.22.37.38; Wed, 15 Jun 2022 22:38:07 -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=@chromium.org header.s=google header.b=i8Jw1IH6; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358245AbiFPFXU (ORCPT + 99 others); Thu, 16 Jun 2022 01:23:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349270AbiFPFXT (ORCPT ); Thu, 16 Jun 2022 01:23:19 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 071765AECE for ; Wed, 15 Jun 2022 22:23:19 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id cx11so513875pjb.1 for ; Wed, 15 Jun 2022 22:23:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gLwzCgeGjXvkAY0tAtafYy0s/ZAsW8+7L0BV4I3ZRUg=; b=i8Jw1IH6VUEi8KQMpX04rBSHs+I/nRw4wm3Y2NqpACnSuZNIikRM1Va65bIlL0dXu5 hPGvIKf2gWhtIzEglKPEDUPuCcORIewZlFTs62THn8BbuOVDWvIvOHzHL6UdnJpOpOhX lFK8gemR1etOaZjQJqzbACo7h0BEZyxqhDlIg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=gLwzCgeGjXvkAY0tAtafYy0s/ZAsW8+7L0BV4I3ZRUg=; b=jKcqh6H60miFRI3d6d/JSKgSml8d0YFioK4raEuFPrOsLaRwu5s2TKN324ds7GuNTm /kgjMv1NUG1DrmH47WDmOQGG+VHR16tHof0wC/ytPBYsNyT7C0C0dVhR8teaJNf/Lxyv 5nELMLoh3Gpf6+YpH9bgXhQ2PvKcDDJ6UX9D03lCTZvBmcDnZV3gu4QNQJuxDM9zu45p Vq1a3lAAs97o0KJ/3SA1tYkBh3kj2jbr18fL+w83LUudtpGfpwuBiqYNeSgRmKyMxKRr vHK+JItp/bPOmRUK/TkWQLZpJHV8lWAragiALc3HnJ/ITSFccjoSww/kdz2615ImeQi/ 77dw== X-Gm-Message-State: AJIora92oVrHKybzyQvH6NtDGdSiFeNfJqjNIZTy5nll4YIgCDs56JBg aNSpFER9CvtDD856S036FJe0vw== X-Received: by 2002:a17:902:f54b:b0:163:e2fd:10a5 with SMTP id h11-20020a170902f54b00b00163e2fd10a5mr3317916plf.28.1655356998486; Wed, 15 Jun 2022 22:23:18 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id s14-20020a63770e000000b003fad46ceb85sm613610pgc.7.2022.06.15.22.23.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jun 2022 22:23:18 -0700 (PDT) From: Kees Cook To: "David S. Miller" Cc: Kees Cook , 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 Subject: [PATCH] hinic: Replace memcpy() with direct assignment Date: Wed, 15 Jun 2022 22:23:12 -0700 Message-Id: <20220616052312.292861-1-keescook@chromium.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1983; h=from:subject; bh=SFrVIRGfudjdjGzJlB2y9b2KbLEnr4pxj5hyTzo45+4=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBiqr5Ay+2HIbpwfOaEAdDeSsHsSYKH5Yf2peVuxbq1 ongVj06JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYqq+QAAKCRCJcvTf3G3AJlYcEA CxKwinqR9MKXCNs89GwL0DczM0vxhxtlpxJ91FuWhUzXCCDngALRjsFZmNj4UsT8EVD9KeyU/PRuwW RRn2ZvPm89zA5CRFtMbUR1C6rNEPw/yG4Q7c4+l3CqyBWnIVJIrF1cz5rzSzCwY+skVXETXdMiO58C DPJ8XWhLMmkMQKppoF8Htq42LVOvMCBXfPsA7JhbN7RpvfCzA3ExqGn5ha0eVsSRQV7JXhD4Hq5stU 3lkF3vre65Zqjcr40cQPtnqfSMIequXKQf59NX6njrWQY8Kh0Qs7xHTS1zxgY/1dIjTw662hodqLws okaJq42NFPtYTIbMwtTsNNECZH+nusLJhekyUw2eyJOy3bDl2g3GF4FVABz/3ZuB/jdi+RydACGzk2 IKjVBH2yBqS57w4sSoQTHGsGnCpADXapnlEgzQJWcW67qNc1zQLHVjJxIUYyIwll5sRbBp1qPm6YFL WSVb9islI6pDx6gVRhxohuNuZ1OlEC5b77AYL4hvopvrRlhk/kRt51AXEPfCsBC9LxRL+S6GRs3fJ9 I6cJGAiHZss2fKNH2Imjv65YnVPQIP1wLOBoIW820V6YAyQ7Md+v76lblglrlrwHWfm8SMwrH3yTxe U2f/TK9NDBYAXO/MEXq1VUJF+cyTnD42t0ZE3KHoUwd3jxLCUKC4V/JtiNJQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,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 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. 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 --- 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 || -- 2.32.0