Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp1073274lqh; Fri, 29 Mar 2024 06:35:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXD9GlomWXsy+dVMDVDBkGMktm+EK7h8GspNrWHEGwYbUfi4BMeaNE9uvDad12dD23EGwoYUSYA0QASl2QKpQMt9JipEj+9MASfDaMFpQ== X-Google-Smtp-Source: AGHT+IF7iXXkzFI1MsC9c7u3hR1t8ZYq+E2ywZxX7Omo8xd9v3ObFE6JHwUMee5XBUyu5V98SY5F X-Received: by 2002:a17:906:64b:b0:a4e:2887:f1ca with SMTP id t11-20020a170906064b00b00a4e2887f1camr1424309ejb.58.1711719310663; Fri, 29 Mar 2024 06:35:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711719310; cv=pass; d=google.com; s=arc-20160816; b=a2MHNG8g5kaJ9APqUoDu/CmUNBIBQDFhUd+f/JYr09aFKg0Ps2Qv3jR6CDaQgk75Pg 8h4lK63HJHgneNKHcjF8c6X4YY26KW1/AVzHU1o5h9bLdhxH1ys+hxGgrS3K0dbD46n1 kG6BqE1NaMQXvsernfrFbwdhz29UcuychIODSTeKXIaUNAzIqxW0TuZ36cHt2UBQpXhu ywbggF7bb+PdSmgyvoXMAzWu2YukngABs8w6l8IunjLqioiS2uzvH7z5BRafyRwlFkA/ whCbI6GZX46LmJpMjE+BZc+6B0PEShrEKlRNWcfOAmNAyT8hvmlu0N1Z+YJoe5s1ZwlR XM2A== 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=FeYhmqARgIiprdc9QnBQf9qmXiAve3l6loczFEx8Jiz+SQ/zwN0YqgR+C2QrJIlIPc TkpJXNqIt3dvoqhYldm12JkdaqH7YWnmL507d5oSU/BoQuCDHY+82b9ONLl3aqs6f7S6 nDND4bZCG5jQFmIeO04cyRReQwpm5hJukczmqEXy2Y7HqkonDNSA/dO/PazrmK8jXy79 YWWcb1p93FZadH8LYmh8KOYTWeCoXN3JNUisHC7YjUIOmB+V3gICkflGB9LlLqcpopJQ yUUSim3TRYNdvT+uSlWqKaGL2TEia1n95UhoX5V6YV2fyW2VT+j+CURVqcHod9JkPZ5/ klMw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NX70r12R; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124724-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cm27-20020a170906f59b00b00a4711e41ab8si1849061ejd.40.2024.03.29.06.35.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 06:35:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NX70r12R; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124724-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124724-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 48D491F261BF for ; Fri, 29 Mar 2024 13:34:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C917146D45; Fri, 29 Mar 2024 12:40:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NX70r12R" 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 38A811779AB; Fri, 29 Mar 2024 12:40:15 +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=1711716015; cv=none; b=pFajzt+HgVy9w/W7OU9mXhz+zQn84jsiKvKjFVLKNJuCayYNQT3tpl1pPz0+gD6+ErEa0AmpKwXQ8plqAFbcwjYVL4y5Kg1wBVnW6QFx3EeWQ+4qVIcTwmv+EElDgeixCO/Fl5lEkyz7Ii4EyW4fAI9Bd1CDvUWHk7LjW+/7FEo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716015; c=relaxed/simple; bh=AZ0mB1d3R+H64t4ZWNRanPwr3ab/60b2LiI4buc8VcU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OnG7NGKIujRzTIkGPU9OTMiuAqRgJsY3/sxBl01ub87UF1aUz8z0tiYyqBzusMCz6rw1JLMjW2Z/ryA2nVVhoCRL1ZG7/8bl7IgggWL8acXG1sBBiy50vEDfrYatwjg8LiOHcuOlVCPkDj5K89P3firn6rMK+ly7DxVIpCMHexI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NX70r12R; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D52AEC433F1; Fri, 29 Mar 2024 12:40:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716015; bh=AZ0mB1d3R+H64t4ZWNRanPwr3ab/60b2LiI4buc8VcU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NX70r12RKfXZxRKXmxPxtZadIyVoWGNNxaQxsLuzSCIcrVkl42T0URSY8Gb/OCErP /bchY8FdX+JR9k4Itm1Y019UPHkDbbaUFacz2CCJMxFt9m7y5/TPT2jZoeSrsB/JtL x2IQ0aHQZhbzKX70grgz6lkYrFAjvPvs6P8WKanankL7J8TO376lMOUHeWbIyl+S0F P6LMl1dn7UpV7R6Vtp57G7O8kNX+VRoFdcQmhG9fT1D8TgyzrP7uDyD3WYnJGJDOoD wT59TD7kz5WEvw3/fZG6kIrWw4mheygA15kXTQGhcnCNvRiqztuRpT7Io/ZRGw1bAh FdAyDLOGcx6BA== 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.8 15/98] VMCI: Fix memcpy() run-time warning in dg_dispatch_as_host() Date: Fri, 29 Mar 2024 08:36:46 -0400 Message-ID: <20240329123919.3087149-15-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329123919.3087149-1-sashal@kernel.org> References: <20240329123919.3087149-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.8.2 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