From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71AD41E32CF for ; Sat, 25 Apr 2026 01:01:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777078919; cv=none; b=JCJ8oBPR2O+Y09r6iNP0fdgmAE8mwp1+XrUa0yCK9p8KpaurFAYQwNNq2kofBnjRH7GrS07y03N2SL8Wsssh3NP1DFvaACMWq4IjUFGk5pSrOmSeivo7dYifybjvr5r0g6ToklXKaZwfZPN5YiS2AMJBv1Oqylnn4L1Wg+/IUEI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777078919; c=relaxed/simple; bh=pGKwd41KQ8VX0PGv0k92ogSM3xjtZyf2NxufUOzNjD0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=oiJ8o8bd0nbMBs+iPsPAPalSykXVSrSylDn3+gKufES4OIF9jA9VtttJiqOFZbFULkNrsl9qTOsURdr5raIOk4+iVFSxhUGzRxZMcH5aXBfycMhUo776NEqN8HpjrivdOMgP5Ouaz/C0gyBVbiN3DOInSN2rbAh+PMRW3Kn/FEo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZElFdXBr; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZElFdXBr" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-488ab2db91aso115241715e9.3 for ; Fri, 24 Apr 2026 18:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777078916; x=1777683716; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=gkRSJPCvN16HLT6MSy3CwRc7MA4DpomgTY4ehFZ/ow0=; b=ZElFdXBryzfqOpNzONXivzh3xfV0niHeG+PNAtpV1LI8L86D+6UmV552sxeDD8E0Nd jxn+jRHG3dVJxw7hw0s7uu3xQ6EbpzB1xfD6e1p9MQY6Ke8EdSi3NG2A2DvEbax5aLwV 4liEh2mRT0C/zwBihElQtMRTntUen930eYaidwWv2/WylrfD19nMo3d1bryKG6WrIZfq WfgE5cbtVl3bIpz+5HUuTOPdviCPujJAGQEpQC7PLeHAmTO9Z9MEhvO1eKrQIRrPn6VL viE6AZSpB9yMKn4Q7RSA+jyu9QHxhu0pfwS9XHcYI42+Qe8Zv6A5HpOhGiRvoMEfzfd+ 7afQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777078916; x=1777683716; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gkRSJPCvN16HLT6MSy3CwRc7MA4DpomgTY4ehFZ/ow0=; b=TOrWrv5WU6ubb4yB0RZg8woBKGg+xdh6Pv+1GVXniouLsJEUFY51AlKYULoTsNfZ+7 pQRlgFUUtxtc8jn8eKcjy/z1zcnV3YFcmj0C0igJ61wG6cnUVyYf2ZakVCYetSrTLNsY QR8WVd5iXH+OQMI7k7kdN283BIvDcU6/DZYGqnG/50ZU3Fis48LlsxD/rbRBMLm6tPOK CgvTkkCUFEZHjezGLKK9rAbNju3VQtTFAYwDn/GfHYGnoQC8x6QYkqpcXlfrbPiCy/hY BLWDaBi30KW4kQt1K9MMPulf9jCIExI8lU/BppYw4Mv/lZqpJk7Kq4/teh8OP0S8B4c6 yJ3g== X-Forwarded-Encrypted: i=1; AFNElJ9M6hWvJZkb+R4NBHnroCYSB6V9w/E0VwRBTIj4ePc7rDauGjGfOPEEhvGhllVJhLUoGglm2OAtxEQyXBM=@vger.kernel.org X-Gm-Message-State: AOJu0YwM8BFj8fEAUwU3oeFV9QF3FxgXUVXHxc+16asixWHAEzF8Rzka rxmH0s4WN/CjjLomwa+Nt/OKv5m7uKlYoADX0ND0pOnzFOz1hFrvQSQc X-Gm-Gg: AeBDievMsz8pjl7sP2dpqj+DoTi4g6R4siAD6OHcYBQi5dLzN/Z5jQIQnfFXpGxvzP2 swRSSM6qvP00WLdj0XEzqBO0zvdSfjANSVonkniToS4lQhbFvHzDKD1MqLw7Z+vyH19ADpuHdKL VuSnK7IhCapo1bXUzxVG9+mcRw+F9h7c7ifwb3+2OE5Lih6sFZJUpSvStG9psiyY19lVuupq/0U NNsCyQ6Y68Ud2o+SO0ALUu2TIrLbaHp7FmIY7RG0geCs61QjqhRwphKmCfKRwz5t5eRlB2czSJg WiPhE+6ciops7RV04C4sxnbH9tF4W2yYdXVTP2M7szxf0PmZshSI41V5TAcN+pLvtzG9DfP5Lcb W7jqTZajh+vnXfz/8zTZ4kzVjwtWuP+ntfoflGfQvo5GoBgDgNRrM9qkp90hmCdbmSGC7V3UZs9 LWdNCkJUE3x86mVH75RRBMPtVvlOB6ATNa8oB6kfgZVoShjsiG4AjioRbPYJN99PEB+xTrgMflD ua9pXssU3TjV9NhQPsGTlEwoOfWVWQerEqtsoXZq3e7hGhyQAKj X-Received: by 2002:a05:600c:1614:b0:489:1e8a:90b4 with SMTP id 5b1f17b1804b1-4891e8a91e8mr203282145e9.21.1777078915677; Fri, 24 Apr 2026 18:01:55 -0700 (PDT) Received: from SD.localdomain (heme-13-b2-v4wan-167795-cust403.vm32.cable.virginm.net. [81.108.45.148]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a5549f582sm98835785e9.33.2026.04.24.18.01.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2026 18:01:55 -0700 (PDT) From: Prathamesh Deshpande To: jgg@ziepe.ca, leon@kernel.org Cc: yishaih@mellanox.com, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Prathamesh Deshpande Subject: [PATCH rdma v1] RDMA/mlx5: Fix devx subscribe-event unwind NULL dereference Date: Sat, 25 Apr 2026 01:59:15 +0100 Message-ID: <20260425010107.19586-1-prathameshdeshpande7@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit MLX5_IB_METHOD_DEVX_SUBSCRIBE_EVENT() links event_sub into sub_list before initializing the fields used by the shared error path. If eventfd_ctx_fdget() then fails, the unwind path dereferences event_sub->ev_file in uverbs_uobject_put() and calls subscribe_event_xa_dealloc() with event_sub->xa_key_level1 still unset. Also, if kzalloc_obj() for event_sub fails after subscribe_event_xa_alloc() succeeds, the current iteration is not yet tracked in sub_list, so the shared unwind path cannot undo the XA allocation. Initialize the shared-unwind fields before linking event_sub into sub_list and explicitly unwind the XA allocation on event_sub allocation failure. Fixes: 759738537142 ("IB/mlx5: Enable subscription for device events over DEVX") Signed-off-by: Prathamesh Deshpande --- drivers/infiniband/hw/mlx5/devx.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/mlx5/devx.c b/drivers/infiniband/hw/mlx5/devx.c index 645ebcc0832d..3d1528b1c816 100644 --- a/drivers/infiniband/hw/mlx5/devx.c +++ b/drivers/infiniband/hw/mlx5/devx.c @@ -2160,10 +2160,16 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_SUBSCRIBE_EVENT)( event_sub = kzalloc_obj(*event_sub); if (!event_sub) { + subscribe_event_xa_dealloc(devx_event_table, + key_level1, + obj, + obj_id); err = -ENOMEM; goto err; } + event_sub->ev_file = ev_file; + event_sub->xa_key_level1 = key_level1; list_add_tail(&event_sub->event_list, &sub_list); uverbs_uobject_get(&ev_file->uobj); if (use_eventfd) { @@ -2178,9 +2184,6 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_DEVX_SUBSCRIBE_EVENT)( } event_sub->cookie = cookie; - event_sub->ev_file = ev_file; - /* May be needed upon cleanup the devx object/subscription */ - event_sub->xa_key_level1 = key_level1; event_sub->xa_key_level2 = obj_id; INIT_LIST_HEAD(&event_sub->obj_list); } -- 2.43.0