Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2110934rdd; Thu, 11 Jan 2024 22:22:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQDJfpczY+YlOMF1KD3oxp2bU988eO3qq8M1d4PRxNYEuWhbbUwE+ry/CxuIWhIO93rwG0 X-Received: by 2002:a17:907:707:b0:a2c:1132:6b51 with SMTP id xb7-20020a170907070700b00a2c11326b51mr465639ejb.41.1705040575607; Thu, 11 Jan 2024 22:22:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705040575; cv=none; d=google.com; s=arc-20160816; b=M9PI8GRnPFW2gb+hGzv3NFYsCxexhZEzGWGQZH1xps8R3sgSMlDhkhkvjtgv5y/Cwq pt8YUf9p2Ae9CmbuhCJgIY4lK2oDf86ZixtO3WQ8wGFFRtDFi9Z2zcauYAYVRPcGkbLA Pl/5yw1dDENQVvQbd1GzRBQrYsRfewdzCS6NUtrboeXr8I0uA0z7wVAt9+bl33HLxsnO tCUGPzM4bWWfMdE/Ab3bUf7jpK8PthvzXxFwv4fOfTLA5KTxeiEpV5b5TrjVdtBmWHOn hdA6aK9r3oca7Sdjr42qgKvT+VC8bpJ7GG3hvW7x8xLRlr7Bx6BoyvU+V+EngYRzBEZ5 nDjg== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24335-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u20-20020a17090626d400b00a2c20f5dc30si1087104ejc.907.2024.01.11.22.22.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 22:22:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24335-linux.lists.archive=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-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24335-linux.lists.archive=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 59A9D1F26836 for ; Fri, 12 Jan 2024 06:22:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7FD235C8F5; Fri, 12 Jan 2024 06:22:43 +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 Content-Transfer-Encoding: 8bit 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); -- 2.39.2