From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (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 86C49283FCE for ; Tue, 28 Apr 2026 17:11:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777396283; cv=none; b=RZRAp47ynpYQydkyMHJpF3PbD3WbsLCiBbIMw7OcI7jNdBZ4i3PCfhAz0Q+yJ/VwmO1do81yz/VrfmUn/DkUUhsE9RnCH//VQxfcmgKe2V5UN21dfb2R2iMLrVHJMidsZoIsPzwaRZg7lTc/FImVxYs3EFvJM9Gx1PSQrz9W8+8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777396283; c=relaxed/simple; bh=VzhCQIX+WF6O8N7B7/nriLlzoXg/COyBQ6enwW2r94M=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=AcoSgJU1Ku0Jr3eQl+59Vy2EJhk+u1LXR6V3rNMwxBq2y+hVZiSfLmfHIPQQ0Yux/Pxq9Hru1+JFix6G2TRkpZORY4QM5tvYhWw02H8aLK5JHKQqOz9h1isU/aS+shw+mGNc7c1v4/zoEGsASW+7Ye1oMVw2ImGdj2FqoConWYg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Qr8P794R; arc=none smtp.client-ip=91.218.175.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Qr8P794R" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1777396280; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=KQYtvaVky6oAjcFKUGXH/dKN1krlRoDNZuxw3fuumpI=; b=Qr8P794R5GMT0UD9jDE1OgaBIL/5xYvhVei40CpaWH8NofoANb50dsr0jp7s5k6gLZ8Yrp /gj1i9qt5pZzIcVgtIfjH8jsflU/kL1bTRJmnIXTSoxjCQOxLj9616BASzGz9d8yK2nevo mW6inTMivoXyAvhPnXUN2Vn2PFbsxWk= From: Thorsten Blum To: "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li Cc: Thorsten Blum , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] hv: utils: replace deprecated strcpy with strscpy in kvp_register Date: Tue, 28 Apr 2026 19:11:05 +0200 Message-ID: <20260428171104.591947-2-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1619; i=thorsten.blum@linux.dev; h=from:subject; bh=VzhCQIX+WF6O8N7B7/nriLlzoXg/COyBQ6enwW2r94M=; b=owGbwMvMwCUWt7pQ4caZUj3G02pJDJkfXmloSP7eVXRT1PriW7XaTKYEXtWZtm6CamclZlS97 7BmVDLsKGVhEONikBVTZHkw68cM39Kayk0mETth5rAygQxh4OIUgIkEMzP8j1zufyj127O0yOzJ t/LsXgo8v3Vg4p/pq4tql0y48/viP01GhvvHVM79OspbafC3JP3z2U33D01QD573g/XSzlNTJku aCjAAAA== X-Developer-Key: i=thorsten.blum@linux.dev; a=openpgp; fpr=1D60735E8AEF3BE473B69D84733678FD8DFEEAD4 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT strcpy() has been deprecated [1] because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. While the current code works correctly, replace strcpy() with the safer strscpy() to follow secure coding best practices. Use ->body.kvp_register.version directly as the destination buffer and remove the local variable. [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy Signed-off-by: Thorsten Blum --- Based on my other patch [1] which needs to be applied first. [1] https://lore.kernel.org/lkml/20260414111008.307220-2-thorsten.blum@linux.dev/ --- drivers/hv/hv_kvp.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/hv/hv_kvp.c b/drivers/hv/hv_kvp.c index 6180ebe040ff..336b278b2182 100644 --- a/drivers/hv/hv_kvp.c +++ b/drivers/hv/hv_kvp.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "hyperv_vmbus.h" @@ -130,18 +131,15 @@ static void kvp_register_done(void) static int kvp_register(int reg_value) { - struct hv_kvp_msg *kvp_msg; - char *version; int ret; kvp_msg = kzalloc_obj(*kvp_msg); if (!kvp_msg) return -ENOMEM; - version = kvp_msg->body.kvp_register.version; kvp_msg->kvp_hdr.operation = reg_value; - strcpy(version, HV_DRV_VERSION); + strscpy(kvp_msg->body.kvp_register.version, HV_DRV_VERSION); ret = hvutil_transport_send(hvt, kvp_msg, sizeof(*kvp_msg), kvp_register_done);