Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp18886lqz; Fri, 29 Mar 2024 07:19:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUb+lW70js8uQifcFuWQJ8LiDdVutWQIu3QYDCitrekL1zo9Akrkw7OaVUBDcYCI4Xt1Mx12f+pCLcabreByC8zoLr/rjdTh9ZYDGOFiA== X-Google-Smtp-Source: AGHT+IEoJDCmd4VM5fo59mgq8TrbucIhj7IS6axHpcopil+Ec2XqPYUdOVGtMSXlw2JKqyVEqxGf X-Received: by 2002:a05:6358:7e13:b0:183:4817:3ed1 with SMTP id o19-20020a0563587e1300b0018348173ed1mr3062161rwm.4.1711721998935; Fri, 29 Mar 2024 07:19:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711721998; cv=pass; d=google.com; s=arc-20160816; b=FTVL/PPNXagVU/QWd35V9F2sAhQ6qPC9nmZl/G7L85nEADbFgu40o6k2gmc7mMHrib yMYKGKQc23k7ApP3jPnoa7u0tD1cEUV5uoghKZ2vR+Jr9yItkB4OBtYHn0lws3TR0kg7 xTcwaDZ+l3np1RgpZON2o3vbIYkxyY0vmQPRV7e402iBeys8J/r/lluxkUGDlywj1J+P arBJyFDUlsTo6a7xybXXTy+ppshdJvu3vjWa0nN+Q8VXQUrNDa27oKBYX2e1niyhTst7 vN0SclDK+pyDlvISQWBR4i85Jf7u11rcAOg2TC7PWTo7whDs1MANs4O9iKZULnOgYY33 aJcg== ARC-Message-Signature: i=2; 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:dkim-signature; bh=DRqeFS+3LOpa8fbC0I4KVJ/ogjRo9gDFvbwA3QkQNFs=; fh=mwT4EgXr4VfptM7/rLpinfjY+7KK5PeY16z0beZhzdE=; b=zT5FBE5kCouTqAX6zMbGlhBuzrCTXsjNj4TojCHFsIk/ss6jo3s6xk4KNXeyYFKaUB FSMxM3Seq9gCLZfQxxa3cPYIA2ZOhnu+EnBR2ShSOgXuURJvBE+qtekDAMQp7O33j/xy OKiEWJ7jXuF/2Er+l/ni9H4pC/1aV//4QO8SKnpmC2jL0ukSAPicG3SXfx3JhZQ+gjRz 5aM3ool3QoD1lNVlPNzzMe1fgPR6K/n2h4/29c7nSlH0Rvs2AeiXWZfYhpv4frh1kwH7 yakMJrVs6htl2BC9u25iijZ2/MsJ9Go1A0SC/OfGY7oH5ABinFvy3cudbZD7Ayc8nTGS IkOQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J6HsL5e8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124891-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124891-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id jc30-20020a056a006c9e00b006eadf6ae098si2933152pfb.321.2024.03.29.07.19.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 07:19:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124891-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=J6HsL5e8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124891-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124891-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2347B28492D for ; Fri, 29 Mar 2024 14:19:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DCCA12319D3; Fri, 29 Mar 2024 12:46:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="J6HsL5e8" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0DFDA2319C2; Fri, 29 Mar 2024 12:46:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716377; cv=none; b=dgCfIfWex9cdTMtcGjOpwLitKpI2mZMEeCtx9ueir4aWuW5fTEJqL+jbg+hXupw53ZtTrwB5l0NCz7tsNNE+TVbCi4VZDM/jp/AsqQ2EghgJO1EvhNZt8E4Swk8MF4jzsoLeWd5efuo3AWCvaSFzJtCqFf0iD2CDLHk6zsYGmXQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716377; c=relaxed/simple; bh=AZ0mB1d3R+H64t4ZWNRanPwr3ab/60b2LiI4buc8VcU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lj6Z1/0UkeNFVWMQJUQGPsOTBFFoZqj+CsNntm7SjWvby8T8lca1vZALHjd9sluUZZMS1YtGzhFi25NxKmP5TQ39fl87Jd1mpBGWNoO+qhKUJgy4sZ6bAldMix1zZI3PW65V9BWcTn5Ube4pTLBCksD3DBCW4YKL8P2N4xEvvdU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J6HsL5e8; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50E27C433C7; Fri, 29 Mar 2024 12:46:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716376; bh=AZ0mB1d3R+H64t4ZWNRanPwr3ab/60b2LiI4buc8VcU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J6HsL5e8vW8K6WOmhupYPbzyC2fB1wSTDcA+6mbRF3S6Qjtt52VhVJx+RwVWW+YOY vnAh/YahLrTiTs95Ih8BSXJYnH4Q6Dl+L5NdYUPnABl5SrpmkzlerXqEnnLVg5kmB1 aGfdFOOyKjmlfRJTIpzMjtIKMsJIrfUXTVZOUUV8y9eEBWzLE+nUEYQarIT94WrUMm iu7AvlovuYyYPgCIUH8L/WatEl7OjQnTfEXF8iubDfDfjL5NtC1JloLwZ17R1S46ml zW0FqejwuiJh/aSq4ZDQQZCnG0xoM/w1slPmuR8osclOFsv5EeX0EAlraXvKVFNqMA gcgi9l/8eumUg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Harshit Mogalapalli , syzkaller , Vegard Nossum , "Gustavo A . R . Silva" , Kees Cook , Dan Carpenter , Sasha Levin , bryantan@vmware.com, vdasa@vmware.com, gregkh@linuxfoundation.org Subject: [PATCH AUTOSEL 6.1 07/52] VMCI: Fix memcpy() run-time warning in dg_dispatch_as_host() Date: Fri, 29 Mar 2024 08:45:01 -0400 Message-ID: <20240329124605.3091273-7-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329124605.3091273-1-sashal@kernel.org> References: <20240329124605.3091273-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.83 Content-Transfer-Encoding: 8bit From: Harshit Mogalapalli [ Upstream commit 19b070fefd0d024af3daa7329cbc0d00de5302ec ] Syzkaller hit 'WARNING in dg_dispatch_as_host' bug. memcpy: detected field-spanning write (size 56) of single field "&dg_info->msg" at drivers/misc/vmw_vmci/vmci_datagram.c:237 (size 24) WARNING: CPU: 0 PID: 1555 at drivers/misc/vmw_vmci/vmci_datagram.c:237 dg_dispatch_as_host+0x88e/0xa60 drivers/misc/vmw_vmci/vmci_datagram.c:237 Some code commentry, based on my understanding: 544 #define VMCI_DG_SIZE(_dg) (VMCI_DG_HEADERSIZE + (size_t)(_dg)->payload_size) /// This is 24 + payload_size memcpy(&dg_info->msg, dg, dg_size); Destination = dg_info->msg ---> this is a 24 byte structure(struct vmci_datagram) Source = dg --> this is a 24 byte structure (struct vmci_datagram) Size = dg_size = 24 + payload_size {payload_size = 56-24 =32} -- Syzkaller managed to set payload_size to 32. 35 struct delayed_datagram_info { 36 struct datagram_entry *entry; 37 struct work_struct work; 38 bool in_dg_host_queue; 39 /* msg and msg_payload must be together. */ 40 struct vmci_datagram msg; 41 u8 msg_payload[]; 42 }; So those extra bytes of payload are copied into msg_payload[], a run time warning is seen while fuzzing with Syzkaller. One possible way to fix the warning is to split the memcpy() into two parts -- one -- direct assignment of msg and second taking care of payload. Gustavo quoted: "Under FORTIFY_SOURCE we should not copy data across multiple members in a structure." Reported-by: syzkaller Suggested-by: Vegard Nossum Suggested-by: Gustavo A. R. Silva Signed-off-by: Harshit Mogalapalli Reviewed-by: Gustavo A. R. Silva Reviewed-by: Kees Cook Reviewed-by: Dan Carpenter Link: https://lore.kernel.org/r/20240105164001.2129796-2-harshit.m.mogalapalli@oracle.com Signed-off-by: Kees Cook Signed-off-by: Sasha Levin --- drivers/misc/vmw_vmci/vmci_datagram.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/misc/vmw_vmci/vmci_datagram.c b/drivers/misc/vmw_vmci/vmci_datagram.c index f50d22882476f..d1d8224c8800c 100644 --- a/drivers/misc/vmw_vmci/vmci_datagram.c +++ b/drivers/misc/vmw_vmci/vmci_datagram.c @@ -234,7 +234,8 @@ 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); + dg_info->msg = *dg; + memcpy(&dg_info->msg_payload, dg + 1, dg->payload_size); INIT_WORK(&dg_info->work, dg_delayed_dispatch); schedule_work(&dg_info->work); -- 2.43.0