From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B526EC433E1 for ; Thu, 20 Aug 2020 13:31:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8BB232072D for ; Thu, 20 Aug 2020 13:31:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597930273; bh=aTkfAVIahRMmhZXljbsWvSDq4bZNkxIkqqnsC9HJsng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=0Z+uLrCh5j7BD1HGkK+Yw41LwDL4mWT+aB4K5NxbQ3x6taIDPXAo6Zx+TVUok3pcs Qr8cr3eDu+bYEggSJN2g01Oh2MqzB24kMexcXV0mwEQrOdPTfFJtDLGy8qBqoR7kTA vQRfeNtWIKUHWMrFP5p3tOS3xw58i7yFIyBjvvlg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728274AbgHTNbJ (ORCPT ); Thu, 20 Aug 2020 09:31:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:45210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727067AbgHTJcp (ORCPT ); Thu, 20 Aug 2020 05:32:45 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8B8F522B3F; Thu, 20 Aug 2020 09:32:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915965; bh=aTkfAVIahRMmhZXljbsWvSDq4bZNkxIkqqnsC9HJsng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XsHq/N6IjQDyobib+0S/OuiriVT6Tf8rwPH5pPhCxV3D8UqWmOVpaDMLjhRKzKYhn 9sjEqllxSnb6vgXfSxwSEJVolPyATHrvwjx1sWK5t34vSO16XBLAB0+uOUknmnNkmk TZROIg6l8z6P1KM9UIPasW/xVBayFVeWqvP2CXOE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , "Michael S. Tsirkin" , Jason Wang , Sasha Levin Subject: [PATCH 5.8 197/232] vdpa: Fix pointer math bug in vdpasim_get_config() Date: Thu, 20 Aug 2020 11:20:48 +0200 Message-Id: <20200820091622.334300890@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Dan Carpenter [ Upstream commit cf16fe9243bfa2863491026fc727618c7c593c84 ] If "offset" is non-zero then we end up copying from beyond the end of the config because of pointer math. We can fix this by casting the struct to a u8 pointer. Fixes: 2c53d0f64c06 ("vdpasim: vDPA device simulator") Signed-off-by: Dan Carpenter Link: https://lore.kernel.org/r/20200406144552.GF68494@mwanda Signed-off-by: Michael S. Tsirkin Acked-by: Jason Wang Signed-off-by: Sasha Levin --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index 412fa85ba3653..67956db75013f 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -522,7 +522,7 @@ static void vdpasim_get_config(struct vdpa_device *vdpa, unsigned int offset, struct vdpasim *vdpasim = vdpa_to_sim(vdpa); if (offset + len < sizeof(struct virtio_net_config)) - memcpy(buf, &vdpasim->config + offset, len); + memcpy(buf, (u8 *)&vdpasim->config + offset, len); } static void vdpasim_set_config(struct vdpa_device *vdpa, unsigned int offset, -- 2.25.1