From patchwork Fri Jan 12 06:22:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kunwu Chan X-Patchwork-Id: 187583 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1937306dyi; Thu, 11 Jan 2024 22:23:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IF4sKNc0ljztoPw9pnviv2S0/93MyAa2ulGGtM+72poZpLP0SrbqaRidKR55hK+cAL9zqvT X-Received: by 2002:ac2:4d04:0:b0:50e:dbfe:df2 with SMTP id r4-20020ac24d04000000b0050edbfe0df2mr298141lfi.109.1705040586680; Thu, 11 Jan 2024 22:23:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705040586; cv=none; d=google.com; s=arc-20160816; b=EHdaM3L5nlLd7I35DMCasT1OLDGxmi4u6n2B42r3PUZXHeDEc4wtYz3AKNM5md+MX/ Ygstgnqs4t881VEJJdUWyFlx6VkwcflGfa9l07cqYxIpn7ZOx52ynciyTqMeeFRy/TQ7 7v3AQdLFfzd6D7WJ1xN0YW8uC7Sl+mVIzak35/W1pEPMsIDVJVi0OVYz1NsnguNI6cMv v/KrL4gfTCDyB0gNtDA5p8F6yLIAovP64Nx00nbRI0eO05a7AEeFG7ypdbl9KV3Lols3 6ZCGX99CCo0c6K3E06sCgo1AlFWdzPJI0vkV6d+9PNShoc1kkz9AW9iHnGYpTtev8Stx PzZg== ARC-Message-Signature: i=1; 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:message-id:date:subject:cc:to :from; bh=9OKEc+wcJcJmgbzkDZtGb1C7IvO1jB58Ul10b3h4gYQ=; fh=iubXruiasBqlL8CXS753YoZ4K4fVzYiGYiT5DHt4Vn8=; b=AfcAUOxeSxooQBouSqBtc3hKKPjWXDQGJc7Hh8xNxRYd6R8GnS7os6cqSfwMimXRHu exL5/0vGW650VuDDwzjQYqwEs1ThLqywnHncBzefaMNciQrd3ykt5S+rY/4OaS0PPANv pvxHvR7UvHiIV8fEN56byHinl8BbsPNWtj4c3+vBnwLeiOZihSSaNXp0Qy7aGa534KH+ EMmCltkuZ+O/gtsdb1daG7AcbIVQdycc5x6A3G1m30CyECAT51tjFhiO41qFeeuGPPD4 WaMBOFiyufq4itIrrqWGj4Hmxx+Fwdl4tH3ow40TPb58vVxEPL0Nbu3++daBKWdDu2AY renA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-24335-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24335-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ez18-20020a056402451200b005583687088bsi1172925edb.152.2024.01.11.22.23.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 22:23:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24335-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-24335-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24335-ouuuleilei=gmail.com@vger.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 4B72D1F2675C for ; Fri, 12 Jan 2024 06:23:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8713A5C90C; Fri, 12 Jan 2024 06:22:44 +0000 (UTC) Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 0E5855B20C; Fri, 12 Jan 2024 06:22:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: a89a8a12cdc64435aa6ae0cb02410969-20240112 X-CID-O-RULE: Release_Ham X-CID-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.35,REQID:122c95b5-1e1f-4d6f-8be8-0704ac461ae0,IP:10, URL:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:-5 X-CID-INFO: VERSION:1.1.35,REQID:122c95b5-1e1f-4d6f-8be8-0704ac461ae0,IP:10,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:5d391d7,CLOUDID:d549c582-8d4f-477b-89d2-1e3bdbef96d1,B ulkID:240112142232FV8Y7QSS,BulkQuantity:0,Recheck:0,SF:44|66|24|17|19|102, TC:nil,Content:0,EDM:-3,IP:-2,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 ,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD,TF_CID_SPAM_FSI X-UUID: a89a8a12cdc64435aa6ae0cb02410969-20240112 X-User: chentao@kylinos.cn Received: from kernel.. [(116.128.244.171)] by mailgw (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1163207083; Fri, 12 Jan 2024 14:22:30 +0800 From: Kunwu Chan To: alex.williamson@redhat.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kunwu Chan Subject: [PATCH] vfio: Fix NULL pointer dereference in vfio_pci_bus_notifier Date: Fri, 12 Jan 2024 14:22:21 +0800 Message-Id: <20240112062221.135681-1-chentao@kylinos.cn> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787864637861159235 X-GMAIL-MSGID: 1787864637861159235 kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure. Ensure the allocation was successful by checking the pointer validity. Signed-off-by: Kunwu Chan --- drivers/vfio/pci/vfio_pci_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 1cbc990d42e0..74e5b89a3a0c 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -2047,6 +2047,8 @@ static int vfio_pci_bus_notifier(struct notifier_block *nb, pci_name(pdev)); pdev->driver_override = kasprintf(GFP_KERNEL, "%s", vdev->vdev.ops->name); + if (!pdev->driver_override) + return -ENOMEM; } else if (action == BUS_NOTIFY_BOUND_DRIVER && pdev->is_virtfn && physfn == vdev->pdev) { struct pci_driver *drv = pci_dev_driver(pdev);