From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 3280D53976D; Wed, 23 Sep 2026 14:48:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790174940; cv=none; b=eWPe3vr+2atgW7LG64t9AcdpEMrn53tpqzASGhIeq9dGmX0eYdfKWHZVbeMuBaintAPCMmUd/vGgO46U2bSwrpQ9cashFA1osTvsbvikJOB+rmZngRDO+7VMQdPrcii7/hV6yP8ZeW5HAEAx6yZ2rPFvqAEPY/6hCuRWbbheTPY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790174940; c=relaxed/simple; bh=TmmnACM6p+mYAkcDwZCxdO7KI3mxmGDaCAKe6DIAfsc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DP2QPlkLqIU6KCCq4K9oq0ilMEJ277DElMU0xCkO9hEiJW/0Ga2pDhIieKnDUj31FI+9GTu/mMVUtO4ExX2YOUQHUTAxUS0oqreGO7VJisosrOUR1xnBYzKatBQbcVMWefG+yNbJ0wrDN6V8FMjzmGDsH4VgKVD/vPsXlWGSPTc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=lcyzDRei; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="lcyzDRei" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A17E21F000FF; Wed, 23 Sep 2026 14:48:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790174939; bh=k5/2teR+JwPvwvtON7fHUcR2KzGX1qIv3ykM84PqRcI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lcyzDReiF1vmUu729/sS+P7BGZCCMjrCTp40cQpBRniO4ns5ratdR9WFR1COZBDX5 wkyl2F4ICvY9KdX8gTJvblHzVVn4Jf1cUoKO+W2KwoPrswAw4lho4vlrZOaQSTeIII YQ9yc0ztI5TJ/5GDqBqGE3Zmm0iy6r8/eubDBXZY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shuangpeng Bai , Leon Romanovsky Subject: [PATCH 6.18 271/398] IB/mlx4: Fix use-after-free on pkey sysfs registration failure Date: Wed, 23 Sep 2026 16:05:45 +0200 Message-ID: <20260923140650.441820945@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260923140643.441954610@linuxfoundation.org> References: <20260923140643.441954610@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shuangpeng Bai commit 1af874e9f4ce22ccf8b10ab5462f32c70d3be21a upstream. register_pkey_tree() ignores errors from register_one_pkey_tree() and continues registering the remaining slaves. The per-slave error path has already released the pkey parent kobjects, but their pointers remain stored in the device. A later device cleanup therefore passes the stale pointers to kobject_put(), causing a use-after-free. Clear the parent pointers after releasing a failed slave tree and skip unregistered trees during device cleanup. This preserves the existing best-effort registration behavior while preventing a second cleanup of the failed tree. Fixes: c1e7e466120b ("IB/mlx4: Add iov directory in sysfs under the ib device") Cc: stable@vger.kernel.org Signed-off-by: Shuangpeng Bai Link: https://patch.msgid.link/20260816044510.3848996-1-shuangpeng.kernel@gmail.com Signed-off-by: Leon Romanovsky Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/hw/mlx4/sysfs.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/infiniband/hw/mlx4/sysfs.c +++ b/drivers/infiniband/hw/mlx4/sysfs.c @@ -753,11 +753,13 @@ err_add: kobject_put(p); } kobject_put(dev->dev_ports_parent[slave]); + dev->dev_ports_parent[slave] = NULL; err_ports: kobject_put(dev->pkeys.device_parent[slave]); /* extra put for the device_parent create_and_add */ kobject_put(dev->pkeys.device_parent[slave]); + dev->pkeys.device_parent[slave] = NULL; fail_dev: kobject_put(dev->iov_parent); @@ -787,6 +789,8 @@ static void unregister_pkey_tree(struct return; for (slave = device->dev->persist->num_vfs; slave >= 0; --slave) { + if (!device->pkeys.device_parent[slave]) + continue; list_for_each_entry_safe(p, t, &device->pkeys.pkey_port_list[slave], entry) {