Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2521100pxb; Mon, 19 Apr 2021 07:39:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzuc8eW05tOcgzFdm3x9cZpUtME5LLrdlrcTzLslAscIQ6e8Fs5fiQFsOIkkwpJmAmI8LUo X-Received: by 2002:a17:90a:540b:: with SMTP id z11mr17635206pjh.133.1618843159436; Mon, 19 Apr 2021 07:39:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618843159; cv=none; d=google.com; s=arc-20160816; b=vZo/ZzO8h/n0j2im0XUjA6hjkzDRlmYGbhC+CGC0fuJUYwZRl2gfUnil5y7+RCPu6Z Gkj7Yzi14Qw8kyMxh51ktXx56D7SqzSGx4Ku3Ve8xl2dOpUmI+q8lo6q6iWfibR7l76H 7SWOD/s9aHleRrNFW2C9bN2agSldjjwqoagsdfR4OF9fVodl+WHkq9xGVnXjpPFEZzti gCR4t7ZJOjTB8C7lO1ohO/wumJedFK+93W9Kebh+dORAw4NbmL3xnu8d1bgMxUBaW8oG EaJSGV3csPnOkrYLs5L+V//1oZkBxbo7yW2G4dIRaxS87y1vT6rEZKCqb7qC6E7eTtch i6hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fm+BEWjgiEsq5QmQ9wDrq/amBjoKDpaqNpgkNzkVBlw=; b=P1H051TO8r4P/uB1K1aVeeHhG/cEopUTK20A4BSBiec76ZfDox+FHGcUlCGHfi+tbW d7JIYm/HRXHA2A5XGid9xMPu3K+HoyV+skUW11b55WpCfK5/CtdiynLRgQfLyXBCW34n vsieW/pgbtxlZrOR6HXDKsytcWMwpeUNjrNcNJTY//3/R2iKvVIfwNouj84Rn+6bXtfa ugNNv3gbCsOKHN5ZVF+54Xqn5NLdQGnT26B0rfybwF1n80wuPt7a4CbratOpvWyb/ZHU jGARLAxYK3QsGgg9BM0T0la9m0on6ja6xRXFq3Y2ZEcOQ0dyBvkLb1pfGfGbF7YKhl4Z MwwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sfRlCA58; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k12si17978305pgp.381.2021.04.19.07.39.07; Mon, 19 Apr 2021 07:39:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sfRlCA58; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240176AbhDSNVO (ORCPT + 99 others); Mon, 19 Apr 2021 09:21:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:54752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240715AbhDSNQn (ORCPT ); Mon, 19 Apr 2021 09:16:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 35575613AB; Mon, 19 Apr 2021 13:14:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618838043; bh=/9IyQacGTGb/SudmTn/8o4W+MLVXiEg2d8hWfT5mr3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sfRlCA58WddmPWGNiFfXKD1POoBQEbmkja1yRkRbi9PeyJDA/VQhDRdMAlm2XmftV rrwrDehYmhOda6F8yfTjDQgHY9/FYl+FK+Kz3NGEyEuHbu5ktrW/lyauQyLDuOG3ud 8rAM3/tYbYhBwPVD6U9pncPh6ZJnVq7AM4khgwJ0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lv Yunlong , Oleksandr Andrushchenko , Sasha Levin Subject: [PATCH 5.10 022/103] gpu/xen: Fix a use after free in xen_drm_drv_init Date: Mon, 19 Apr 2021 15:05:33 +0200 Message-Id: <20210419130528.554526710@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210419130527.791982064@linuxfoundation.org> References: <20210419130527.791982064@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lv Yunlong [ Upstream commit 52762efa2b256ed1c5274e5177cbd52ee11a2f6a ] In function displback_changed, has the call chain displback_connect(front_info)->xen_drm_drv_init(front_info). We can see that drm_info is assigned to front_info->drm_info and drm_info is freed in fail branch in xen_drm_drv_init(). Later displback_disconnect(front_info) is called and it calls xen_drm_drv_fini(front_info) cause a use after free by drm_info = front_info->drm_info statement. My patch has done two things. First fixes the fail label which drm_info = kzalloc() failed and still free the drm_info. Second sets front_info->drm_info to NULL to avoid uaf. Signed-off-by: Lv Yunlong Reviewed-by: Oleksandr Andrushchenko Signed-off-by: Oleksandr Andrushchenko Link: https://patchwork.freedesktop.org/patch/msgid/20210323014656.10068-1-lyl2019@mail.ustc.edu.cn Signed-off-by: Sasha Levin --- drivers/gpu/drm/xen/xen_drm_front.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/xen/xen_drm_front.c b/drivers/gpu/drm/xen/xen_drm_front.c index cc93a8c9547b..8ea91542b567 100644 --- a/drivers/gpu/drm/xen/xen_drm_front.c +++ b/drivers/gpu/drm/xen/xen_drm_front.c @@ -531,7 +531,7 @@ static int xen_drm_drv_init(struct xen_drm_front_info *front_info) drm_dev = drm_dev_alloc(&xen_drm_driver, dev); if (IS_ERR(drm_dev)) { ret = PTR_ERR(drm_dev); - goto fail; + goto fail_dev; } drm_info->drm_dev = drm_dev; @@ -561,8 +561,10 @@ fail_modeset: drm_kms_helper_poll_fini(drm_dev); drm_mode_config_cleanup(drm_dev); drm_dev_put(drm_dev); -fail: +fail_dev: kfree(drm_info); + front_info->drm_info = NULL; +fail: return ret; } -- 2.30.2