Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3433110pxp; Mon, 14 Mar 2022 20:09:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOvzgDvW9vgdKz51yTQy/c0FRwipfpVgp2bNQoa9q2FRvOFNTnr+1Zkn8EbnyDEV4vZxi+ X-Received: by 2002:a17:906:60c6:b0:6c2:85e1:4d52 with SMTP id f6-20020a17090660c600b006c285e14d52mr19870050ejk.477.1647313788581; Mon, 14 Mar 2022 20:09:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647313788; cv=none; d=google.com; s=arc-20160816; b=oB09+vnlvKy6u+f++/eI0QDpi5pqG5YO7S5YKp6snwGWA22rN5iSAIlH0op5Oy5WVr J1YFpyovTH5p1/X/8PMdtlNP/6Klst5lVXmauDs6h19x4qrmthL3qNWo9ccHWCOOOQvo GrzEj1QnzuG5nlchjz0uYiGxv5tK6W7HOHlGNoR2VXRiWglk5xbsut1Zauod7Auhu/s7 H9NUR4TkUrR9KTWm80eyLxGZzOP8R9VfEUIzUYGkq84FC73K1qTea2bx5vSCxEwjpwJm IvhX+lrJpUh9mllNcfLxHllWqKzMIyy6CdKANtuRAnkHukJ2FRXOSAFyAEJ1LiC1D4WQ VBwA== 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=MyoOenRp9yOL1eZeUiUR+AVmOlCo5qc7nzjLDvTSP4s=; b=kY9YsqbGCqcE60ed7d8840jHmuXFIustYtX1g7rTJSHd6gDGZ6QBpF3uEEOWc6hX7v l5i7Quge2yLZyfcgkrudHUR/rjw62ppINtpfkbr/Kujffcr79UC8/OKXg0kTLKXJGu5h 91LPmAj88RjXvwLuTC7IUxIluqMm1cx1xJQ4bHwZ4NGu9IG6LnVJfRJJzn14FFQi7N2I XEk15vcusreotT/CxSrRPKX3YcXspKUBkcp1tBspJ0Kh8bwrM5VQSBMiu3m4ScNozAB2 GnVluyQF/5KcCfpi6VQ9kKn9fIOmirv8ONh/l8NipgmYyiQrYh2wEYmotfAIVcntAWS+ /knw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=a9Pc61W1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 1-20020a170906318100b006ae720209a5si9332975ejy.969.2022.03.14.20.09.23; Mon, 14 Mar 2022 20:09:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=a9Pc61W1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S240887AbiCNMOp (ORCPT + 99 others); Mon, 14 Mar 2022 08:14:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241208AbiCNMI0 (ORCPT ); Mon, 14 Mar 2022 08:08:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78D7F14004; Mon, 14 Mar 2022 05:04:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E758F612FF; Mon, 14 Mar 2022 12:04:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4F88C340E9; Mon, 14 Mar 2022 12:04:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1647259483; bh=mcY++hQwosQrmS4VOSstT2y3t/sUeBOpElGTIFDRSu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a9Pc61W10Tlb2KjwfSRa3ZjSlHiLu9LK/PasSGlo4WzmDo1cMZUldcl05Irm3Xinh tzw6QawjG7rgIs+Hyylsy9MdhJZct+AHZISnMeM266ONAlG+yQlItWjfMODaftWviO +LmlD24hrUzHpziMoAg6ppGCpt+BOYipJazzJEi8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhang Min , Yi Wang , "Michael S. Tsirkin" , Stefano Garzarella , Sasha Levin Subject: [PATCH 5.15 017/110] vdpa: fix use-after-free on vp_vdpa_remove Date: Mon, 14 Mar 2022 12:53:19 +0100 Message-Id: <20220314112743.516445465@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220314112743.029192918@linuxfoundation.org> References: <20220314112743.029192918@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhang Min [ Upstream commit eb057b44dbe35ae14527830236a92f51de8f9184 ] When vp_vdpa driver is unbind, vp_vdpa is freed in vdpa_unregister_device and then vp_vdpa->mdev.pci_dev is dereferenced in vp_modern_remove, triggering use-after-free. Call Trace of unbinding driver free vp_vdpa : do_syscall_64 vfs_write kernfs_fop_write_iter device_release_driver_internal pci_device_remove vp_vdpa_remove vdpa_unregister_device kobject_release device_release kfree Call Trace of dereference vp_vdpa->mdev.pci_dev: vp_modern_remove pci_release_selected_regions pci_release_region pci_resource_len pci_resource_end (dev)->resource[(bar)].end Signed-off-by: Zhang Min Signed-off-by: Yi Wang Link: https://lore.kernel.org/r/20220301091059.46869-1-wang.yi59@zte.com.cn Signed-off-by: Michael S. Tsirkin Fixes: 64b9f64f80a6 ("vdpa: introduce virtio pci driver") Reviewed-by: Stefano Garzarella Signed-off-by: Sasha Levin --- drivers/vdpa/virtio_pci/vp_vdpa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c index 5bcd00246d2e..dead832b4571 100644 --- a/drivers/vdpa/virtio_pci/vp_vdpa.c +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c @@ -513,8 +513,8 @@ static void vp_vdpa_remove(struct pci_dev *pdev) { struct vp_vdpa *vp_vdpa = pci_get_drvdata(pdev); - vdpa_unregister_device(&vp_vdpa->vdpa); vp_modern_remove(&vp_vdpa->mdev); + vdpa_unregister_device(&vp_vdpa->vdpa); } static struct pci_driver vp_vdpa_driver = { -- 2.34.1