From patchwork Wed Jan 10 10:40:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasiliy Kovalev X-Patchwork-Id: 186782 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp705939dyi; Wed, 10 Jan 2024 02:42:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGcoR9YjPo7OQYKTqwFpXfhKdCuh+/3SZREH/lRqycUp3fW401Je5dJ27xbrsouVF7Rxfj X-Received: by 2002:a05:6214:f28:b0:67f:628e:35bf with SMTP id iw8-20020a0562140f2800b0067f628e35bfmr1231022qvb.36.1704883335957; Wed, 10 Jan 2024 02:42:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704883335; cv=none; d=google.com; s=arc-20160816; b=h7554v0jCPdrNjh1jgNwcOPiz+s9dX28tQUQ8S29/ZmbheP+ubHNLjg5OkwWz906HI mZyk/YNTYUlUqQUOp0jOtIwRI+Jx0GLLzndtEG0fb4DIIrTHGRV/62Gye1SDFEHtrsJr l5iilOd01qUWwwhDUYEjXQ9XGSMzfL/6v8ceZZYGIudbx+4PJCkrAtw76YxQH1dPvj5w AnKfZonpeQ1WGNbeRLsv0ROsaFUhsSk/5B9nwe1lNWS47FEak2O+A/sK9LM8lDCwcyS1 OII/5Ngr3qsV6qDa8SU8CEBHVRxUYp0JqV8zbatDR6LbJRF+H3dxv4HiT3+wIUJy+pSA HH8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=B/HJtdV4Zgf1lqEJz0fu0BoZFeVbemKxKmqrnsU6dkc=; fh=AWJyr76I9iddV14rCPpiXUkE22U3OQl3re+ZYbviBqA=; b=feYwiN0rf3SHZTeLv+hNhgCVbd9A9dwBlErFh3+p63/WPaYY4ih9oXH442FYxjz8Q4 LlmNhPsi6ov/5I79+gN18Tuon7x+6nRqNHCnjFcZwzZWW/6uwrcvj3iPuWpeUN0RQtvU VS2jf3eBhFK6Y4LVAKKe9rrgPbyJGgWi8TO8Dw9Qz7GZPeMFDh3TUmkB42IJt7ZzNmtS R5jfzOofJwg/rkEkofLJkua1d7f0LVkHltnOOVJ6KrobLnuppM2sk7VdGYi/dn+JpODc fT39KTfqT9a7Dv5zpqlIUJcn7kFcTg4M9mg9Bn6Y1JyZMFJLyWAebRCjBW2ZMSTm5S2o BTXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-22004-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22004-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s2-20020a0ce302000000b0067f962d07bcsi4194031qvl.56.2024.01.10.02.42.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 02:42:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22004-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-22004-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22004-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id BFDB11C21AD0 for ; Wed, 10 Jan 2024 10:42:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 647EA4176B; Wed, 10 Jan 2024 10:42:01 +0000 (UTC) Received: from air.basealt.ru (air.basealt.ru [194.107.17.39]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E52F40C0E for ; Wed, 10 Jan 2024 10:41:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=altlinux.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=altlinux.org Received: by air.basealt.ru (Postfix, from userid 490) id D6F4F2F2027D; Wed, 10 Jan 2024 10:41:53 +0000 (UTC) X-Spam-Level: Received: from altlinux.malta.altlinux.ru (obninsk.basealt.ru [217.15.195.17]) by air.basealt.ru (Postfix) with ESMTPSA id E1B262F20249; Wed, 10 Jan 2024 10:41:31 +0000 (UTC) From: kovalev@altlinux.org To: bryantan@vmware.com, vdasa@vmware.com, pv-drivers@vmware.com, arnd@arndb.de, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org Cc: kovalev@altlinux.org, nickel@altlinux.org, oficerovas@altlinux.org, dutyrok@altlinux.org Subject: [PATCH 1/1] misc/vmw_vmci: fix filling of the msg and msg_payload in dg_info struct Date: Wed, 10 Jan 2024 13:40:42 +0300 Message-Id: <20240110104042.31865-2-kovalev@altlinux.org> X-Mailer: git-send-email 2.33.8 In-Reply-To: <20240110104042.31865-1-kovalev@altlinux.org> References: <20240110104042.31865-1-kovalev@altlinux.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787699748669770104 X-GMAIL-MSGID: 1787699748669770104 From: Vasiliy Kovalev Fix "detected field-spanning write" of memcpy warning that is issued by the tracking mechanism __fortify_memcpy_chk, added 2021-04-20 (f68f2ff91512c199ec24883001245912afc17873 fortify: Detect struct member overflows in memcpy() at compile-time) Fixes: a110b7ebb9c674 ("VMCI: datagram implementation.") Signed-off-by: Vasiliy Kovalev --- drivers/misc/vmw_vmci/vmci_datagram.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/misc/vmw_vmci/vmci_datagram.c b/drivers/misc/vmw_vmci/vmci_datagram.c index f50d22882476f9..27853b31e288b1 100644 --- a/drivers/misc/vmw_vmci/vmci_datagram.c +++ b/drivers/misc/vmw_vmci/vmci_datagram.c @@ -234,7 +234,10 @@ static int dg_dispatch_as_host(u32 context_id, struct vmci_datagram *dg) dg_info->in_dg_host_queue = true; dg_info->entry = dst_entry; - memcpy(&dg_info->msg, dg, dg_size); + memcpy(&dg_info->msg, dg, VMCI_DG_HEADERSIZE); + if (dg->payload_size) { + memcpy(dg_info->msg_payload, VMCI_DG_PAYLOAD(dg), dg->payload_size); + } INIT_WORK(&dg_info->work, dg_delayed_dispatch); schedule_work(&dg_info->work); @@ -377,7 +380,10 @@ int vmci_datagram_invoke_guest_handler(struct vmci_datagram *dg) dg_info->in_dg_host_queue = false; dg_info->entry = dst_entry; - memcpy(&dg_info->msg, dg, VMCI_DG_SIZE(dg)); + memcpy(&dg_info->msg, dg, VMCI_DG_HEADERSIZE); + if (dg->payload_size) { + memcpy(dg_info->msg_payload, VMCI_DG_PAYLOAD(dg), dg->payload_size); + } INIT_WORK(&dg_info->work, dg_delayed_dispatch); schedule_work(&dg_info->work);