Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2387342lqp; Sun, 24 Mar 2024 17:10:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV0QVbFrZnrRCpJtmta40/zJjxapfSU9DeGO5PUiJqrlZxLFRrCcp2fZeAf7Y4VAwtYb4kG0jxjE8mFuTTRpDUiY3Qc1tG4Fon0NlE6Og== X-Google-Smtp-Source: AGHT+IGq5gAcgo/TmFs2X3FmlgJ+2q43ufWKvj+rmKMZCQQDyPncclsWz+/MvflmYpeRLsc0bltB X-Received: by 2002:a05:6512:3d06:b0:515:a755:9e93 with SMTP id d6-20020a0565123d0600b00515a7559e93mr2646156lfv.35.1711325444492; Sun, 24 Mar 2024 17:10:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711325444; cv=pass; d=google.com; s=arc-20160816; b=wevQV2zCJUHbTVHzYEj+S1wOrD+BLiiPBppaFu4bUJzY2KaLHt4NPEFMenhNWOKES4 jR4p3ehPr/eEG53MyKn//huw3vIxam0vw1PTYJg3fAK0CwCQMm+bT8QVjeWL0YOO3sYX +UNTfyFTyuh6A2i+viuJBFxdNzMUt/6KvmAWQYJflGnHFG72dmX2TZlke1vIFN/0rzLS 9rLfMzMn/qMHht1eWexQQ2xWV8a22e4LGXkzjgj0OU8DXuVcFQEdIzZWOoyfrqpF9Q3B 020j1e6XCGsO7hLyiUSSCOCkkojhcwW5/D0M7ORFJaD61cpBnK9Az+JPV9Mcjfk6UkYs 0XyQ== ARC-Message-Signature: i=2; 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=wfFDz0OVEZ6Y9uYQViqjlptoubw+NPc1/B5ZQx862Ak=; fh=Bs7fHfThBdIoEvSkdN2U8hTMx13eS+irHjtTdvS3cm4=; b=s11icxYjf8G2RCjwcT029/ZwKIQjNSebE7+FWVt/p6q/5VnAeaCOtKevHj3n5YocII wbuCv2xAicKInYL7IhAIRyWNAUuVA9qQyYnM7E9E9Ussdk7jDzONQFl3RU5nrnnWU/iM jdpvU+1Xuu3k8PP/EPXrUrsgC7A1Qunzrz0ItpQp2kRI3QMhb/yYEu3JMWer14bqKhon 8n8cGeihvQCvGetpikYyIgs6ZoyE4oBXzcwyQDw+XquphrU0bFDJc882D+71/Hf3u5Tp 4uW8XxyAoW2TMvtCq1nH0obWNg+5vMCPv/wYLnPfu5zCzv7ez/KVY33K0NuybHkjGVZS 9YSg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="AxnNwu0/"; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-113323-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113323-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 w11-20020a056402128b00b0056ba785da85si2076001edv.595.2024.03.24.17.10.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 17:10:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113323-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="AxnNwu0/"; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-113323-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113323-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 E54271F22E6C for ; Mon, 25 Mar 2024 00:09:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4246C19466A; Sun, 24 Mar 2024 22:42:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AxnNwu0/" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3119A194C84; Sun, 24 Mar 2024 22:42:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320125; cv=none; b=LqC3HEZ+1hNllF8vUzyhrzx0WEVLRb06jzp+/KMcn++0/VfGZbD48cnN4npSoOcyyIjVgBWZL7r/NpXWOylpLIhNB8ouyyHWQcMegd6rAy3mialRHzm/cjMHzpYgKufEkS3bnWwoEUQ6/mBPW+U6rZmDp5+6bvxlXssaVGO8sdM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320125; c=relaxed/simple; bh=IDMABsbKodk7Jluai+Wa3cMHJI+CkDyCinjyT2vhD84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XZtFkapJQZDU/VarGJBmQV8q0GH7V0FYMw2GMKlQAp2ZtDIhUCNNARbmd0HJ+f/QU3pa7ND5Elj34GjC5Xyw3gUGjNj4mCCpO0tWr4GNS0jsMmxibd5iVKocma6AmyilnWjUieP/DiQRel5ADKMaHWbGL9KB3XLPyLiPOWHeui8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=fail (0-bit key) header.d=kernel.org header.i=@kernel.org header.b=AxnNwu0/ reason="key not found in DNS"; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A105C433A6; Sun, 24 Mar 2024 22:42:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320125; bh=IDMABsbKodk7Jluai+Wa3cMHJI+CkDyCinjyT2vhD84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AxnNwu0/9Ymd5p27lPfdBWCfT2fGTZiv4hmMwv1RN+OVDnMLMxd+eEJdq2SLMFNve oT3tX83Oz8pBQv9e5iNC0YEPGvHtBqP4rslNdZaZI7cDm8T73LA6H0WCZnJyKUYAxx 7ka9pI5c8VsS7agu4hZ3YVaVGK9KHgunZVUDwMNFyebKYVoMO6mpDD3bLyUab/RWAK RXMVdkrGaD7W80MNRCTGCBUht8xiGkWBIoSd6Rtnmy5UsaGBBSZwyaAju+qyLgkrCx AQJISW2s5GBieUPnEfm/KeDMqrBHSZl2sDGgALx03L5e4HhKpO5OHc1S0KNK8/GHbD RlxaScZbVEHhA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yang Yingliang , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Manivannan Sadhasivam , Dave Jiang , Sasha Levin Subject: [PATCH 6.8 432/715] NTB: fix possible name leak in ntb_register_device() Date: Sun, 24 Mar 2024 18:30:11 -0400 Message-ID: <20240324223455.1342824-433-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Yang Yingliang [ Upstream commit aebfdfe39b9327a3077d0df8db3beb3160c9bdd0 ] If device_register() fails in ntb_register_device(), the device name allocated by dev_set_name() should be freed. As per the comment in device_register(), callers should use put_device() to give up the reference in the error path. So fix this by calling put_device() in the error path so that the name can be freed in kobject_cleanup(). As a result of this, put_device() in the error path of ntb_register_device() is removed and the actual error is returned. Fixes: a1bd3baeb2f1 ("NTB: Add NTB hardware abstraction layer") Signed-off-by: Yang Yingliang Reviewed-by: Ilpo Järvinen Reviewed-by: Manivannan Sadhasivam Reviewed-by: Dave Jiang Link: https://lore.kernel.org/r/20231201033057.1399131-1-yangyingliang@huaweicloud.com [mani: reworded commit message] Signed-off-by: Manivannan Sadhasivam Signed-off-by: Sasha Levin --- drivers/ntb/core.c | 8 +++++++- drivers/pci/endpoint/functions/pci-epf-vntb.c | 6 +----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/ntb/core.c b/drivers/ntb/core.c index 27dd93deff6e5..d702bee780826 100644 --- a/drivers/ntb/core.c +++ b/drivers/ntb/core.c @@ -100,6 +100,8 @@ EXPORT_SYMBOL(ntb_unregister_client); int ntb_register_device(struct ntb_dev *ntb) { + int ret; + if (!ntb) return -EINVAL; if (!ntb->pdev) @@ -120,7 +122,11 @@ int ntb_register_device(struct ntb_dev *ntb) ntb->ctx_ops = NULL; spin_lock_init(&ntb->ctx_lock); - return device_register(&ntb->dev); + ret = device_register(&ntb->dev); + if (ret) + put_device(&ntb->dev); + + return ret; } EXPORT_SYMBOL(ntb_register_device); diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c index e75a2af77328e..5b84821c0d602 100644 --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c @@ -1275,15 +1275,11 @@ static int pci_vntb_probe(struct pci_dev *pdev, const struct pci_device_id *id) ret = ntb_register_device(&ndev->ntb); if (ret) { dev_err(dev, "Failed to register NTB device\n"); - goto err_register_dev; + return ret; } dev_dbg(dev, "PCI Virtual NTB driver loaded\n"); return 0; - -err_register_dev: - put_device(&ndev->ntb.dev); - return -EINVAL; } static struct pci_device_id pci_vntb_table[] = { -- 2.43.0