From patchwork Wed Dec 7 12:08:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nanyong Sun X-Patchwork-Id: 30786 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp122658wrr; Wed, 7 Dec 2022 03:28:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf4OgC0K/jq0x+gdWpu7UVlU85t5g1vv05+rrtcGQbfvE2YE6dibdfpfK2VfSBmZTxYy5HUv X-Received: by 2002:a63:5910:0:b0:477:2793:f821 with SMTP id n16-20020a635910000000b004772793f821mr82300259pgb.150.1670412515138; Wed, 07 Dec 2022 03:28:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670412515; cv=none; d=google.com; s=arc-20160816; b=UX4W1F9odfrHIdJJ6fCG/FSN3DlsDjtA7VNmKhaXcesxt/ySRvnoHp3zr8cwfM9AUW I5dd1o2qKQTOP2TM8pDuEE6KtOmaASAiCtqCfcP8h96WXzb8Zra+nLBdlMB/appMOOO/ 3M47hXUMIrKU0RPN/l7r9L31SlcogIUlSYDLGS8j7g9GdPRTPgFyWvoito6Sk5/jxvwn TXBO4xEhWMPb7ZksmuAto0nYMVMCVNLgrcRIOYKvlpRoET/8zALW8oMShmg9hqn41Xdp XMwMo+BpX1iSjtR3+z/36sCNCe22EmZBTXcJhm2CCL4e+feQ+mQZ3aCRi87Bqfrv2MOF iCgw== 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 :message-id:date:subject:cc:to:from; bh=rcrHlmCeWRgpgVaUYSxzHZRRxuyGO4BeqqaoNnUcM94=; b=EAPhMXoHt//mIFM7uvtSUj9q+8/bEJP+FJGF6DsCiDBTi29BdkQhKZOMnba6SKxUUG kLk2W/rRDghHJsiPsPn3EH/+mODATqtBJ3VLIDLkcSPfq3JCSVHxrEkARXJ+HNzXbVYP g2nc/9Sx8aeAhXDSAJCHGlHKY6vf7JLQyw0zUg92b6Ac+8OYFGYpfzhRAxhCf1GezY81 dmKPyOWTRXL7v9MKdlm7adJ0PzCH05mkQTM3XTjUiC30nSyl7WcmB95RI6uCYP5KLP3n 4V5kRcbDL0Q/voF0qWdixgPjVG/+iM05ab17P42/O+ngsZFuaGy9s/XP9wCSHVUwsUki +zRw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m8-20020a056a00080800b005779f520683si34161pfk.200.2022.12.07.03.28.21; Wed, 07 Dec 2022 03:28:35 -0800 (PST) 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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229651AbiLGLVw (ORCPT + 99 others); Wed, 7 Dec 2022 06:21:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229853AbiLGLVb (ORCPT ); Wed, 7 Dec 2022 06:21:31 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FB3F3F048 for ; Wed, 7 Dec 2022 03:21:27 -0800 (PST) Received: from kwepemm600003.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NRvwL41h5zRpjR; Wed, 7 Dec 2022 19:20:34 +0800 (CST) Received: from huawei.com (10.175.113.32) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 7 Dec 2022 19:21:24 +0800 From: Nanyong Sun To: , , , , CC: , , , , , , Subject: [PATCH] vdpa/vp_vdpa: fix kfree a wrong pointer in vp_vdpa_remove Date: Wed, 7 Dec 2022 20:08:13 +0800 Message-ID: <20221207120813.2837529-1-sunnanyong@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600003.china.huawei.com (7.193.23.202) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751554473423726545?= X-GMAIL-MSGID: =?utf-8?q?1751554473423726545?= From: Rong Wang In vp_vdpa_remove(), the code kfree(&vp_vdpa_mgtdev->mgtdev.id_table) uses a reference of pointer as the argument of kfree, which is the wrong pointer and then may hit crash like this: Unable to handle kernel paging request at virtual address 00ffff003363e30c Internal error: Oops: 96000004 [#1] SMP Call trace: rb_next+0x20/0x5c ext4_readdir+0x494/0x5c4 [ext4] iterate_dir+0x168/0x1b4 __se_sys_getdents64+0x68/0x170 __arm64_sys_getdents64+0x24/0x30 el0_svc_common.constprop.0+0x7c/0x1bc do_el0_svc+0x2c/0x94 el0_svc+0x20/0x30 el0_sync_handler+0xb0/0xb4 el0_sync+0x160/0x180 Code: 54000220 f9400441 b4000161 aa0103e0 (f9400821) SMP: stopping secondary CPUs Starting crashdump kernel... Fixes: ffbda8e9df10 ("vdpa/vp_vdpa : add vdpa tool support in vp_vdpa") Signed-off-by: Rong Wang Signed-off-by: Nanyong Sun Reviewed-by: Cindy Lu Acked-by: Jason Wang --- 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 d448db0c4de3..8fe267ca3e76 100644 --- a/drivers/vdpa/virtio_pci/vp_vdpa.c +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c @@ -647,7 +647,7 @@ static void vp_vdpa_remove(struct pci_dev *pdev) mdev = vp_vdpa_mgtdev->mdev; vp_modern_remove(mdev); vdpa_mgmtdev_unregister(&vp_vdpa_mgtdev->mgtdev); - kfree(&vp_vdpa_mgtdev->mgtdev.id_table); + kfree(vp_vdpa_mgtdev->mgtdev.id_table); kfree(mdev); kfree(vp_vdpa_mgtdev); }