From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793831518; b=xSGP5+ORYMs+LGfF/aCps0IDkM/neOK0Xf58JRJOnM9ZqfWeRKrMFhFbmKIjMt1ptNh4 z8NITu2VWN8k33M1plnqDJrG5CTPeXJofLp939/uoqD5DA1JxVdIfre6eVcU6ejQLAa6m HO9ykL0kDoaHrzwgT4j3LUqvBCTF9I3NK47ljvpoe6Y77k8weYDJ3UkNXWRp2AEstCv61 BE37Tu4QpRZ17D4FICOenfK/bC41qcUya9Cczmd9jlY0glJNSNY1bNkdA00m9O/OEedWp CkTutRe0NxqPIpsxhLrJNbMGYdxiJflvQausariTHp3IZeTGPR5mOGZAi0Eg3GInwqQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793831518; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=+ex4sYRuctXwXfj3dp8MZQ0qXgMmnNCkmAHeaR43AJQ=; b=3jEnkrwJJ4LzwvTrjcFJUuit1Vzh/iMwB90b42bgqKsbnxEarbzbzkQ/uKU1DW1KTBTM 8PArWvDEA5orozgsrr7Fe8XI+zLl+/icJXLVoVfCb177U2R0J6Q6JAhv3OkxwTw/I8lW4 T6yaq9NOAcY2fZ9J2q0KhW84TIg7mhLnYlokauLwiViMARVPac8Av4RceVGy5bvuhCNeK kU8NlkpZ1+UQ7yG6XzxvMxYwsRi745jvfkICN27GjpGqWhPB1AWNLMl4Iovrlogiu2LO1 4WkCZrN8YmpI1t2S9gZtcsX14JDtuo9NqJ7sxuKnwbszB54VQDLg6OQbY4bvwRVBCbw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=RJvIj9GU; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEB69606D80B; Wed, 4 Nov 2026 22:31:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=RJvIj9GU Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6852B1F0093A; Wed, 4 Nov 2026 22:31:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793831517; bh=+ex4sYRuctXwXfj3dp8MZQ0qXgMmnNCkmAHeaR43AJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RJvIj9GUf+eW5tcjjG+h6L8uzfU62WgKWkHclKjT4749T3Upxbj5BKJdtxy72SE9I T8P+L/x/CEsZzpGu1dwHst/a3dw8tkDlLTNKVnMWkPAa0qJJzJe3+uETfeQI5KnQsC YS6BNnsVifSRVH2RP6e8i8heUSvbHUjbwolFtjP8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sean Young , Hans Verkuil Subject: [PATCH 6.18 0751/1005] media: rc: Fix ABBA deadlock by making locks more fine grained Date: Wed, 4 Nov 2026 16:08:04 -0500 Message-ID: <20261104211104.487788407@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261104211043.516122098@linuxfoundation.org> References: <20261104211043.516122098@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sean Young commit c6d68866ad8aa1e957a3e5a6ede971148f1e3d59 upstream. The ir_raw_event_unregister() function takes the ir_raw_handler_lock first and then the rc_dev->lock. Other functions like change_protocol do this in the reverse order. This means that an ir decoder module unload and writing to the protocol sysfs file can cause a deadlock. ir_raw_handler_lock protects the client list, amongst other things. Split this out into a separate lock so we can ensure the locking order is always the same. Fixes: 93cffffc18f6 ("[media] media: rc: fix decoder module unloading") Signed-off-by: Sean Young Cc: stable@vger.kernel.org Acked-by: Hans Verkuil Signed-off-by: Greg Kroah-Hartman --- drivers/media/rc/rc-ir-raw.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) --- a/drivers/media/rc/rc-ir-raw.c +++ b/drivers/media/rc/rc-ir-raw.c @@ -10,7 +10,8 @@ #include #include "rc-core-priv.h" -/* Used to keep track of IR raw clients, protected by ir_raw_handler_lock */ +/* Used to keep track of IR raw clients, protected by ir_raw_client_lock */ +static DEFINE_MUTEX(ir_raw_client_lock); static LIST_HEAD(ir_raw_client_list); /* Used to handle IR raw handler extensions */ @@ -288,13 +289,6 @@ static int change_protocol(struct rc_dev return 0; } -static void ir_raw_disable_protocols(struct rc_dev *dev, u64 protocols) -{ - mutex_lock(&dev->lock); - dev->enabled_protocols &= ~protocols; - mutex_unlock(&dev->lock); -} - /** * ir_raw_gen_manchester() - Encode data with Manchester (bi-phase) modulation. * @ev: Pointer to pointer to next free event. *@ev is incremented for @@ -633,15 +627,18 @@ int ir_raw_event_register(struct rc_dev { struct task_struct *thread; + /* Holding dev->lock could result in a dead-lock */ + lockdep_assert_not_held(&dev->lock); + thread = kthread_run(ir_raw_event_thread, dev->raw, "rc%u", dev->minor); if (IS_ERR(thread)) return PTR_ERR(thread); dev->raw->thread = thread; - mutex_lock(&ir_raw_handler_lock); + mutex_lock(&ir_raw_client_lock); list_add_tail(&dev->raw->list, &ir_raw_client_list); - mutex_unlock(&ir_raw_handler_lock); + mutex_unlock(&ir_raw_client_lock); return 0; } @@ -674,16 +671,19 @@ void ir_raw_event_unregister(struct rc_d kthread_stop(dev->raw->thread); timer_delete_sync(&dev->raw->edge_handle); - mutex_lock(&ir_raw_handler_lock); + mutex_lock(&ir_raw_client_lock); list_del(&dev->raw->list); + + mutex_lock(&ir_raw_handler_lock); list_for_each_entry(handler, &ir_raw_handler_list, list) if (handler->raw_unregister && (handler->protocols & dev->enabled_protocols)) handler->raw_unregister(dev); lirc_bpf_free(dev); - mutex_unlock(&ir_raw_handler_lock); + + mutex_unlock(&ir_raw_client_lock); } /* @@ -706,15 +706,24 @@ void ir_raw_handler_unregister(struct ir struct ir_raw_event_ctrl *raw; u64 protocols = ir_raw_handler->protocols; + mutex_lock(&ir_raw_client_lock); + mutex_lock(&ir_raw_handler_lock); list_del(&ir_raw_handler->list); + atomic64_andnot(protocols, &available_protocols); + mutex_unlock(&ir_raw_handler_lock); + list_for_each_entry(raw, &ir_raw_client_list, list) { + mutex_lock(&raw->dev->lock); + mutex_lock(&ir_raw_handler_lock); if (ir_raw_handler->raw_unregister && (raw->dev->enabled_protocols & protocols)) ir_raw_handler->raw_unregister(raw->dev); - ir_raw_disable_protocols(raw->dev, protocols); + raw->dev->enabled_protocols &= ~protocols; + mutex_unlock(&ir_raw_handler_lock); + mutex_unlock(&raw->dev->lock); } - atomic64_andnot(protocols, &available_protocols); - mutex_unlock(&ir_raw_handler_lock); + + mutex_unlock(&ir_raw_client_lock); } EXPORT_SYMBOL(ir_raw_handler_unregister);