Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1824279rwb; Fri, 23 Sep 2022 20:23:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5w3wZMUFYXZs+606ZnzRIGlCNLYzVNiUEziDJi4ogfAMGG8jvad2s5gol3u1SplX9O/15y X-Received: by 2002:a17:907:983:b0:77b:6e40:8435 with SMTP id bf3-20020a170907098300b0077b6e408435mr9236578ejc.570.1663989832733; Fri, 23 Sep 2022 20:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663989832; cv=none; d=google.com; s=arc-20160816; b=NhV9l2MR3YVy5DREPLJzi3L/JukYUS2mMcoUWM2Lk6jyfU9tMPfBuh0lrK7vVMQvnF ps4M1fOGvErGt8g31kr/pBFbknevsHC94mzf75UIqC+Mecq+ENoQ0Cr7cDzVFsbztTK6 zCeRcWVcxR+sY+VMllcJOs0Dt+L/N26n4MI6/3FN21eOq6jGoUAX0loquw6sAMKn6GGN OsJ/gSLPcd41lD16z6s3WvUgJAVXYPTzoaWy5AOducprYTrrYurXUnAZ1VK54GSuCEdN lcnPggLBgQh3RGEWifkhPerQ/SFsBahxZsFpv9xln5vri7RRnZU9DqfnZLnLvE6hjAqb VSTw== 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=IKtN884SGIzThZ/mZCoo1s2thpv1mLuefxTzikoO46k=; b=UT83LapG+376fd9w/18dcGXyr6lI2NsU6Q2oflnDEpErPS+UHzTdIXL+3mHEL0+H0R uURXBVzY7KLBw3pOhIQ8TvdbEdYS4wekH2cKlsbzbFVs88J/UQwgYOIXF/+4R8u8Fih3 0lPFx85Ik3WpIeOQ74+uL2WXSBbWxj7Cqq8Aa41NddV0WyDE0sLPZQrFatx3coh2UWnP 1k9X/zVZGKJLOy6tgiJO11fFvJ6lwM+dFV9KnW+htjybUm3tF5AigOSWviI0epYd2OMY WV3rofIRfkq9P9IgZlzVWOYuKCCn+Z8HrB6YIpx+L++nTd0b7ZQ08Hpe8FJnfs/3cM72 rS5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FlAbE9MZ; 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 cw12-20020a170906478c00b00782b24c1ed8si2853376ejc.368.2022.09.23.20.23.27; Fri, 23 Sep 2022 20:23:52 -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=FlAbE9MZ; 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 S233072AbiIXDH5 (ORCPT + 99 others); Fri, 23 Sep 2022 23:07:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232968AbiIXDHq (ORCPT ); Fri, 23 Sep 2022 23:07:46 -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 2CE1214DAC4 for ; Fri, 23 Sep 2022 20:07:45 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id rt12so1657871pjb.1 for ; Fri, 23 Sep 2022 20:07:45 -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=IKtN884SGIzThZ/mZCoo1s2thpv1mLuefxTzikoO46k=; b=FlAbE9MZWxzGPuu+k1MJIaxHAf5yVuJ3T/UpZFi8DcgSIlQfZbf6V190IbrtVsRrPL 8sMlEZLhwaFVqHellbBnkUGoZn7u5oJzHePipXuNhquffKhskmvVCfIuTvIsth8aHXoB O+9ydyZw79rKs1+rdHr0JmyeJXX/cQLpr7LFc= 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=IKtN884SGIzThZ/mZCoo1s2thpv1mLuefxTzikoO46k=; b=dKjlko9Vx1M6yZaN3azd828ln+PvwWtu7UXmGKCW8Jb5HE0nKCmvZ2Oe0MqxK8ncFX 1tzJVM8EmnQDF0D0+hVoYUWOw6HQ5EihMkB1PdKiA6kQ4tPbM3gDWtvLVWSXYRUTLeT8 ZCx6d3nRnlTonagPid/x2b7bJgnmZeswaoictIDYUO8TAUgKxPVHxEnibLIolIIicUHl f0QipImawIiEBACfdZdCl2viHb0Q9bQirLDl3xVuA6Sbyo+ehi2pas0OqMzkzf/Gr0Di fQXmliOlGmEiNlkvvHpBDfFUobeR3f6dnWCiBL/uYxhJZg9UZyDEFb7uokrIrlkXgVRn OuJQ== X-Gm-Message-State: ACrzQf0O2Zt1VrIgNt+lrX0Dz+yaBbbLWv7OEhU+iJ7cOVzaMhAMRLA9 me6FjXyBhFdVlb2k6MpjWD9bsQ== X-Received: by 2002:a17:90a:64c8:b0:202:6d4a:90f8 with SMTP id i8-20020a17090a64c800b002026d4a90f8mr13260584pjm.11.1663988864687; Fri, 23 Sep 2022 20:07:44 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id q19-20020aa79833000000b00540c3b6f32fsm7128298pfl.49.2022.09.23.20.07.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Sep 2022 20:07:43 -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] Drivers: hv: vmbus: Split memcpy of flex-array Date: Fri, 23 Sep 2022 20:07:41 -0700 Message-Id: <20220924030741.3345349-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=1726; h=from:subject; bh=7+JpelBNpq5Fw7aAx9OdfzO7liLVsPVR9WciMS4r/NU=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBjLnR9wwp6bolWrhQnItcWX3Mum1QtC8G4uZsAS92B C8WkhqaJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYy50fQAKCRCJcvTf3G3AJpIbD/ 4o9CL5W3GD7T8nYy9vURy0GTTRdPcnwfkEBkvSaBS+6Z047JJXm6JqxYu/4Lj0AMUpOilsKpZIcNXl R6Fro9YcKKMxsPodqIQAc/OFDFje/l3feGhMAHiETi/a5uErOeUJ2MjdCNa5AHSbiaEcB/Es7qj83K DRp14VcgSN5krKbp/6hzYptKDoOt1B0Tf6pGwecGCVT+x/Hphs5UT6pqGhlCsmArMSAI4peTWppE17 fhKWhEmQQDcPquyhachSwTqTdXtCd1XaluRb3veUn6hRKIjC90NamtF8DTyNPMo7LAbnpHj4ydrRR2 FzP5KnEnTTd1xPt3KZ9aAIkZluItICRn/hqfNPCgv5ZsZ0Ynqwn3b9/JWOCOJNxvUwavjeLswrCgmS Lw6nffnf55NJCKMDWgptuaynCK1RMelbVckcZTasi88pRe0zhsRnC5LNad/z8SzY44y7ry5r9Lha5o LFlw3gW16kUMMgUamMJh8SPz+P4JhPTQUUY/yVC6jSsaNbvHicYHFsLBn2XCLveCpBZAYOyNWfYaj4 uYgO8LgNb1aedi4QQ3qaCyVBrjmlPqWqH336vwOA3yaxn8WiippB5r+wH+inl4MwIsG2Dj78qimr1T U4yM40JKYUupXDXYiB5ZUNYZnEV9aC9dcpEQA3ibZ+WuJOfIwgCZjnFc7pCw== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 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. As it turns out, this appears to actually reduce the 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 [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" Signed-off-by: Kees Cook --- 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