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 B33E4511208; Wed, 30 Sep 2026 16:34:24 +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=1790786065; cv=none; b=iwWhucHIDSXszgIjvwDphqDD2rWvF9shnmDrSTzAohBNlkuSCnYj1t3/TcCubvHNX9nAg5bewcveBZz/1oIiSD5rHWtxvw8NzQe1bHC677Ij1RJqlBcdcYo5vWJhuM5GbKsqVQ4p1UvqA+GRVenVz8KErfo5NkOqsVtB3f4hHKc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790786065; c=relaxed/simple; bh=JF/AX43lqb13NF69YCciLjI+Kr4iqUpLlqlSVMK4+gs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MXeBREvTBeWTDEfx68YxKnj2ofC5SelE3MFIc6BkTMe96rDhoUYf49O85jP0n+rtehmnGCmqMdXRCE6SmXVmOEY1PS5VRU5/Y3dZSKyVfl9vk2h+9+i5adDszVY8HIHQK5ei41WWiW/2V4utMBtuhubgvRJhMZpEf8jMu09jR0k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=hFyQ61gY; 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="hFyQ61gY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18F271F000FF; Wed, 30 Sep 2026 16:34:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790786064; bh=6QTbjq3Qi7urQmOjGx49FJaOdlbkOs2yZtaDaQRwM5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hFyQ61gYbRvmb5MaOiqZ2H/isEH84PJp+GqIt8krs/cZT5kJ7ZdlUJ/kyFxsi6ZWr 4n7+DCrk3Au8q92i5yQh+OWuG2bR0RJpiiF3OQf2EDlXW++YZTk6DvqeWrfmjjdKz6 aPeE9AYfPhExJFSYCv/u103oqkMqmXiRIGZaG77U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shuangpeng Bai , Leon Romanovsky Subject: [PATCH 6.1 728/982] IB/mlx4: Fix use-after-free on pkey sysfs registration failure Date: Wed, 30 Sep 2026 17:24:24 +0200 Message-ID: <20260930152432.391155746@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152416.775402466@linuxfoundation.org> References: <20260930152416.775402466@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.1-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) {