From nobody Tue Jun 16 20:45:44 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 9B76D32D0FC for ; Wed, 29 Apr 2026 06:04:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777442684; cv=none; b=domlv76cha6VkyhTBAQAieBqDtVkXvhf2jI39SeEu16yN3dnbW/ezDy9mTMju1NCiF+s+rF9g+ILA0Xt8oFZ9Sgjs6VZWH50p5KD0Xl/DUsZsBAXONU39JZG2tB/Ml3928yRrc0x4t6+uHMctZJdNR1lk/YXRgH9ukE7jJpfXR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777442684; c=relaxed/simple; bh=dfl9nC1Exc3AqWuntxQXKXMjbEeUtj6NKVJat3VsSDE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OsU32RfRl0FTMkYbP1qZzzQeqNtMSlFNch1B4Kdel51gME6SWY5zC/gbHz3rX2wbie6AC45lCyxN2Kpnjlj0tdAasiHjjWE39NcHWgqBVotGVoCCu9mAy3TRMs8BXr6o04Ud1K9DnasuuL4spY4wz1OlmjZe8MCWb7fVu/CuthY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ivAxYj6v; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ivAxYj6v" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777442684; x=1808978684; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dfl9nC1Exc3AqWuntxQXKXMjbEeUtj6NKVJat3VsSDE=; b=ivAxYj6vfqHwJdu1aDTdUeOYWAQV7c6abH+ePNEC13I62gneTvsEGvpu IStjVNmW+UcFGazvWd8f89Iim0BF/zyStD1hxrQ7QL6Kg+GsAamHOf18z We3ouymCDswiKDaP7xC9W4ZIFnXIl1pR77dpH9+hT15GOGccY+P5dSTgW m/QTf290HphuxUG/nTjabrvj0yeRaRdNvczdI9fpWVe+/vrF/RR6NT995 ridXtnaTSJn1soxn1jNVx7ebg2Q92dzS/FYExepE/8zFeLsKN7T+qAJle L/BJyH17MzOvl/ODR5mKwWzXSfAqwbK4fef8KlPNf3pMacgAHlKeIGc0A w==; X-CSE-ConnectionGUID: P5S6JxH7Tnmdg4FrpX7FHg== X-CSE-MsgGUID: 250NhN0ATUSO19J9vZkzZA== X-IronPort-AV: E=McAfee;i="6800,10657,11770"; a="88672085" X-IronPort-AV: E=Sophos;i="6.23,205,1770624000"; d="scan'208";a="88672085" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2026 23:04:44 -0700 X-CSE-ConnectionGUID: +wEHzoxDR5Kcb3xowzXUkg== X-CSE-MsgGUID: Jz6154WlSNuaWGw8DWSRew== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,205,1770624000"; d="scan'208";a="264562062" Received: from otc-chromeosbuild-8.ostc.intel.com (HELO otc-chromeosbuild-8.intel.com) ([10.54.29.153]) by orviesa002.jf.intel.com with ESMTP; 28 Apr 2026 23:04:43 -0700 From: george.d.sworo@intel.com To: maarten.lankhorst@linux.intel.com Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, George D Sworo Subject: [PATCH v2 1/2] drm/modeset_lock: add NULL check for ctx before WARN_ON Date: Tue, 28 Apr 2026 23:04:30 -0700 Message-Id: <20260429060431.1462589-2-george.d.sworo@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260429060431.1462589-1-george.d.sworo@intel.com> References: <20260429025952.1202080-1-george.d.sworo@intel.com> <20260429060431.1462589-1-george.d.sworo@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: George D Sworo modeset_lock() and drm_modeset_drop_locks() do not validate the ctx pointer before dereferencing it in WARN_ON(ctx->contended), which can lead to a NULL pointer dereference if ctx is NULL. Add a NULL check to prevent this. Signed-off-by: George D Sworo --- drivers/gpu/drm/drm_modeset_lock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_modeset_lock.c b/drivers/gpu/drm/drm_modes= et_lock.c index beb91a13a312..2052bb9bb9e5 100644 --- a/drivers/gpu/drm/drm_modeset_lock.c +++ b/drivers/gpu/drm/drm_modeset_lock.c @@ -295,7 +295,7 @@ static inline int modeset_lock(struct drm_modeset_lock = *lock, { int ret; =20 - if (WARN_ON(ctx->contended)) + if (ctx && WARN_ON(ctx->contended)) __drm_stack_depot_print(ctx->stack_depot); =20 if (ctx->trylock_only) { --=20 2.34.1 From nobody Tue Jun 16 20:45:44 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 D4FD333F5A8 for ; Wed, 29 Apr 2026 06:04:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777442686; cv=none; b=tgHRlhPo6t99R2NX27BqxB4wY9M0SQ2AqDFV5U98IiYwx26tVSYavj1/1gpFmWYBNZ2k4OrjRt9Ul9QWrV0KBR8AlFYMtYyWJ8yzFEla7/rbowhs3eZCvGbhnY+4X/5DHhCN9KyJ2WOFVnz7xVvqards2NRcyhh0TeMNUi9VUFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777442686; c=relaxed/simple; bh=K5FLQvf1ktzHuF8i12gIzU0mZ4t59UFwJnvlYzeS+v4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TxfKOwgCth/9CW9Wb9at0ik+80SDxxWLYzOkRe0/1PO134j5o3Nwotv6Xkbee/MeLJpCjaJRnFFzRi8sr4nfH1HvX1CmNMGbyMysJOjX9xATmbSiQM6Yv0qpha+ogSboRBsDkV3qlzEdHQPYEqsWMFLkxMnnHzy0Aef+2T2aK3M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=IpxbhmZr; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="IpxbhmZr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777442686; x=1808978686; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=K5FLQvf1ktzHuF8i12gIzU0mZ4t59UFwJnvlYzeS+v4=; b=IpxbhmZrC58nr/tdQcrSKEvlmBLsJXFKgJrgLUif9fbn3bc96m7LP4IM xfa7I08t/Q3lwdOOEH/rqghvizYj3b7OeFaBbrdI8IM4zekDuYiiu096X 3jPCmDvE+iAORpUNLMVRWAUFJuxHTQy6LjaisDxh6t59Jt1h+rWouTqhK +WB29YgXgIz7LgYYAMUpokHm/LpwRztJN3Be6PmJF7+TSahWkN+8nY1Pd fzsWzSMjDQha47qD+QSg5Ro6ZtJTJCUqW942qadW/lGja9bgSubHPUhR6 v5Vb0U18LWgW2OKEPA1yDvrO1oVF7Fden3iVK6GIeiT+FihAR3fDed7Ko A==; X-CSE-ConnectionGUID: jXeTamSqQmmR6LbSunzxCA== X-CSE-MsgGUID: p98wRL6JTYK1WXY5+fi+dQ== X-IronPort-AV: E=McAfee;i="6800,10657,11770"; a="88672089" X-IronPort-AV: E=Sophos;i="6.23,205,1770624000"; d="scan'208";a="88672089" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2026 23:04:45 -0700 X-CSE-ConnectionGUID: 4DqkoY9eRtGBhef4zWsZ2g== X-CSE-MsgGUID: nXZMcHK4Td+rhv6u3ShbgQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,205,1770624000"; d="scan'208";a="264562071" Received: from otc-chromeosbuild-8.ostc.intel.com (HELO otc-chromeosbuild-8.intel.com) ([10.54.29.153]) by orviesa002.jf.intel.com with ESMTP; 28 Apr 2026 23:04:45 -0700 From: george.d.sworo@intel.com To: maarten.lankhorst@linux.intel.com Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, George D Sworo Subject: [PATCH v2 2/2] drm/modeset: harden modeset_lock() against NULL ctx Date: Tue, 28 Apr 2026 23:04:31 -0700 Message-Id: <20260429060431.1462589-3-george.d.sworo@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260429060431.1462589-1-george.d.sworo@intel.com> References: <20260429025952.1202080-1-george.d.sworo@intel.com> <20260429060431.1462589-1-george.d.sworo@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: George D Sworo modeset_lock() dereferences ctx unconditionally. Add a defensive NULL guard to avoid NULL dereference if a buggy internal caller passes a NULL acquire context. For NULL ctx, fall back to plain ww_mutex locking semantics: - interruptible path uses ww_mutex_lock_interruptible(..., NULL) - non-interruptible path uses ww_mutex_lock(..., NULL) This keeps wait behavior consistent with the helper arguments. Signed-off-by: George D Sworo --- drivers/gpu/drm/drm_modeset_lock.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/gpu/drm/drm_modeset_lock.c b/drivers/gpu/drm/drm_modes= et_lock.c index 2052bb9bb9e5..5bee424805c3 100644 --- a/drivers/gpu/drm/drm_modeset_lock.c +++ b/drivers/gpu/drm/drm_modeset_lock.c @@ -294,6 +294,18 @@ static inline int modeset_lock(struct drm_modeset_lock= *lock, bool interruptible, bool slow) { int ret; + /* + * Defensive fallback: this helper is expected to be called with a + * valid acquire context, but if a NULL ctx slips through, preserve + * the lock wait semantics and avoid NULL dereference. + */ + if (unlikely(!ctx)) { + if (interruptible) + return ww_mutex_lock_interruptible(&lock->mutex, NULL); + + ww_mutex_lock(&lock->mutex, NULL); + return 0; + } =20 if (ctx && WARN_ON(ctx->contended)) __drm_stack_depot_print(ctx->stack_depot); --=20 2.34.1