public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
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	[thread overview]
Message-ID: <20240110104042.31865-2-kovalev@altlinux.org> (raw)
In-Reply-To: <20240110104042.31865-1-kovalev@altlinux.org>

From: Vasiliy Kovalev <kovalev@altlinux.org>

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 <kovalev@altlinux.org>
---
 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);
-- 
2.33.8


  reply	other threads:[~2024-01-10 10:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-10 10:40 [PATCH 0/1] misc/vmw_vmci: fix filling of the msg and msg_payload in dg_info struct kovalev
2024-01-10 10:40 ` kovalev [this message]
2024-01-10 10:52   ` [PATCH 1/1] " Greg KH
2024-01-10 10:54   ` Greg KH
2024-01-10 10:53 ` [PATCH 0/1] " Greg KH
2024-01-10 11:47   ` kovalev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240110104042.31865-2-kovalev@altlinux.org \
    --to=kovalev@altlinux.org \
    --cc=arnd@arndb.de \
    --cc=bryantan@vmware.com \
    --cc=dutyrok@altlinux.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nickel@altlinux.org \
    --cc=oficerovas@altlinux.org \
    --cc=pv-drivers@vmware.com \
    --cc=vdasa@vmware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox