From c028ff4bf5b76479bc7e8e04cf5333938aec386b Mon Sep 17 00:00:00 2001 From: cookpate Date: Tue, 21 Jul 2026 15:57:20 -0700 Subject: [PATCH] Add ownership check when giving a mutex Disallow a held mutex from being given by another task, one that did not first take the mutex. --- queue.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/queue.c b/queue.c index 83c7ac7309..0476f53156 100644 --- a/queue.c +++ b/queue.c @@ -966,6 +966,20 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue, } #endif + #if ( configUSE_MUTEXES == 1 ) + { + /* If the queue is a mutex and is held, only the owner can give it. */ + if( ( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX ) && + ( pxQueue->u.xSemaphore.xMutexHolder != NULL ) && + ( pxQueue->u.xSemaphore.xMutexHolder != xTaskGetCurrentTaskHandle() ) ) + { + traceRETURN_xQueueGenericSend( pdFAIL ); + + return pdFAIL; + } + } + #endif /* configUSE_MUTEXES */ + for( ; ; ) { taskENTER_CRITICAL();