Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1517299rwb; Tue, 27 Sep 2022 14:28:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4dACtXj4gu96USJ1N5yKQvFghjCCiVXpEn8spzSvgJC+izbdxmw6V1m2sgLwXAPZRJyY6u X-Received: by 2002:a17:90b:3ec9:b0:203:246e:4370 with SMTP id rm9-20020a17090b3ec900b00203246e4370mr6501269pjb.221.1664314121437; Tue, 27 Sep 2022 14:28:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664314121; cv=none; d=google.com; s=arc-20160816; b=YUwrJQZC2tMChJjEer5HdR/+RoTvLKehtM3zm/1h6lFeP/B4P53VXzqd4PluxBFJ96 GdbLzDeH3amrI8+NYaHyn0Ds+Hwl1yWfRtKFNnIAzBMXCoQBLNNp88XbFXStVsTgywVk dpvGvbGD3VVAJJQmJlB9BHVGURy/1ZPlrONH+4RZfh02Ox1If5vZK94QEStgC0xVxE1I iPDXby5gXrbM0/zZjjPDzJPvg1Rtb/89wQeTGXCDJjWSm47EwEViv8xUKhR0GEJv5mm+ pDsRdcbWZxjNQEAkSq7QKYn18RSLOFEDXhOuld3g6holpundD1hsjFQUjFX0+RtEvQPg Wu/w== 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=cydRrAXNrnz2QJt3HhI/oDQUhvWbTptDnL6JHpq2qQc=; b=nCmSyxf/ObjfGo7n6gH/JDNqUGP34OgS/rBU84pO2u5EQALrmn1d/S6OegXBlnOYE8 G8X+Za5B4QovDNheI88lFxorRTUCU9QBwfwVq5EVFSna3lhFFXsOI7+XcniHhqlOZhJb 4Fq4lPpQmunsWYtySSNSxbb3ayg6k4J/EiyKXtMR8jT+n4WOq5Y1Cegu3/eODhJuUyYe 875QtMi7jE/YXNo3hOS9T/cSl5Qa4nhdn2nKH12m9uLqiTDBFZipfTc4JScQDSVFKdwN LzR36Ap3X1q5xZcO66v/YuP1yiY/kt3HJndp5V9BBfEnb/t3jalRi/Ya2GfJTq4cLtvD wTbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ia988LVu; 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 l19-20020a056a0016d300b00544e05c04e4si644182pfc.309.2022.09.27.14.28.29; Tue, 27 Sep 2022 14:28:41 -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=ia988LVu; 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 S231431AbiI0VRm (ORCPT + 99 others); Tue, 27 Sep 2022 17:17:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229610AbiI0VRk (ORCPT ); Tue, 27 Sep 2022 17:17:40 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 326F7EC55F for ; Tue, 27 Sep 2022 14:17:39 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id 9so10754049pfz.12 for ; Tue, 27 Sep 2022 14:17:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=cydRrAXNrnz2QJt3HhI/oDQUhvWbTptDnL6JHpq2qQc=; b=ia988LVuGHoaQOtrO3JTaarvPES0PVZQjF+yQ0nipRZxbfbJTvS2jxkCM0uJRn8tse AWhfuK6TaHGGqhM3FAR+1X1SUdV2RZu9KrbGFgepq4nqS9AITiMA5bj1DWqnEkHoZx8U Cj/lsQb1q/QCjS2znmx56BNCoxBs60er3f7ZE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=cydRrAXNrnz2QJt3HhI/oDQUhvWbTptDnL6JHpq2qQc=; b=fY+FOfMRW7vl0hZTz3SqtncOu559YZ5+r8Wk+aR4NznyQwukGUF5+iWhHJTbAvu0Q4 cu0CdgyiOBVTCxyR4GKhLqEt9X+XRaSoQ/FPU0QqglvfPNL1mgDTKNwbUVToWaJLjucd P6RW77CG4yH2J5GgCiPvu47TBZyLtTSYaU0DyZwGjWO6Ts096Rj8bnr8FszjnivoVA1H ii9lFSegJma6ojp5rfK1cfKY3+bgsbrsA9S28GlwmKaxg220gthVzGYDj7i2QbCILyFb 6TiK7FM6OlkDfM1JLIAXPBPiCaZJCsUJaUSTq/IGdLifBsTic//5De7YtnH9zf2NJO2x urlA== X-Gm-Message-State: ACrzQf2Z1R//pKm+U13db6IdwX/VaMNZpY2+BvIfKOJF2y5Y8Dy6vozV 17cRzw7IBbgHIiZwazASjP7//g== X-Received: by 2002:a63:fd41:0:b0:438:7670:589a with SMTP id m1-20020a63fd41000000b004387670589amr25879313pgj.148.1664313458698; Tue, 27 Sep 2022 14:17:38 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q13-20020a170902dacd00b001782580ce9csm1983194plx.249.2022.09.27.14.17.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 14:17:38 -0700 (PDT) From: Kees Cook To: "K. Y. Srinivasan" Cc: Kees Cook , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , linux-hyperv@vger.kernel.org, Nathan Chancellor , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH v2] Drivers: hv: vmbus: Split memcpy of flex-array Date: Tue, 27 Sep 2022 14:17:36 -0700 Message-Id: <20220927211736.3241175-1-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2152; h=from:subject; bh=XiqD42BdKyYFPsQFvFZgiN4gYsXqcM5zpVjMzTZBEGw=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBjM2hvQmM6bsQ+jbJ33l/yJApmN3Z4lyCdAL8/RqG6 TtquvhqJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYzNobwAKCRCJcvTf3G3AJtW1D/ 43JvAeQ5s9E1h+J9RViO3kPVtz/NCuYZdH/+J81jrc2/5zhmshQDgYYYhr7G9/KORTKAN5d3sm+77V BbMU9kLgdyBKQdmSwajxah8jCQii28sDcMqXTPA3HWUf6/Z20m1JFvH4BY7szJgBy7qpOmwwFhlPs5 7cAkt1+u/2vz00NUZhUDY5uPS+Ane1qWS5OKDAvN59kJBVjxmlmB3xDUDIakJ7DGhA2UF6TKjlhbwg gTtpbFjHsAyjkL/hiWFM0OXr8uM+OQXGUbO3Yh9i2Na6U5YaxUsVdP7rMu8ctGztG2jFhXtV4fhCzS BRab8/In/tmLZBqJRODltAVxuUBzMHv20lR3h0P58zG4dlPHkFrnfuZ/m1nzIl8DqERgs6/QJGI6LC YKkLz6HeYlmSfX1BOK4+RXFwU3Tio3XUtvFX/M76RvFkYaRyIiC/X6jKbau8yTg8PRlzb4JvklRR+F JHx9mz06A1VlP5O+0DAjR01n33fPrARIYCIJSVv0urfp4O3TxU2Z72kgrCpAD38/ghYeHFQY2IiTRY ihlxCoAWRx4Qvk3sDy3Bts7ObIr/uipTCDjPQW+9kBZexc9+9bbaVhJKXGzp3dPfGu7W5USpjNetNr Qvgs7TIquSl/3q0c8FDzaD83BI9/muflLEx53YAfnXitnHrOPbf9wVWhDCgQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 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 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 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. This results in the already inlined memcpy getting unrolled a little more, which very slightly increases text size: $ size drivers/hv/vmbus_drv.o.before drivers/hv/vmbus_drv.o text data bss dec hex filename 22968 5239 232 28439 6f17 drivers/hv/vmbus_drv.o.before 23032 5239 232 28503 6f57 drivers/hv/vmbus_drv.o Avoids the run-time false-positive warning: memcpy: detected field-spanning write (size 212) of single field "&ctx->msg" at drivers/hv/vmbus_drv.c:1133 (size 16) [1] https://lore.kernel.org/linux-hardening/20220901065914.1417829-2-keescook@chromium.org/ Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Stephen Hemminger Cc: Wei Liu Cc: Dexuan Cui Cc: linux-hyperv@vger.kernel.org Reported-by: Nathan Chancellor Reported-by: "Gustavo A. R. Silva" Tested-by: Nathan Chancellor Signed-off-by: Kees Cook --- v2: - fix commit log, add tags and exact warning test from Nathan v1: https://lore.kernel.org/lkml/20220924030741.3345349-1-keescook@chromium.org --- drivers/hv/vmbus_drv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 23c680d1a0f5..9b111a8262e3 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -1131,7 +1131,8 @@ void vmbus_on_msg_dpc(unsigned long data) return; INIT_WORK(&ctx->work, vmbus_onmessage_work); - memcpy(&ctx->msg, &msg_copy, sizeof(msg->header) + payload_size); + ctx->msg.header = msg_copy.header; + memcpy(&ctx->msg.payload, msg_copy.u.payload, payload_size); /* * The host can generate a rescind message while we -- 2.34.1