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 92C3350EC1C; Wed, 30 Sep 2026 16:37:14 +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=1790786236; cv=none; b=VDtrajAcj/KFZxcK77wwq/VyqyOSVP17Ru2U3xWDfc4/bMkwdp5K8RMHx1UyLjjhqg0IKy/fLgVXzmZkwSL1ieTCJq1EfY76qGtSy+pPd8/6R88Lz5gjkh7CX8X9dcM4Wza8TSC8Fne4V4la4KUe+gxYzwkTWkTEx30tSTt4Hhc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790786236; c=relaxed/simple; bh=1DgWuwP9BIX0wa17pVBAbPzNSWoVoZdQuPe5xUG57kM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JN+ktzbGk42jmKdRanT57Dt7UDEljCbGva3tOyS0sB9Bn6OSqYvkDl4BFb8ewmRhG5UR22RJjJHJEce5I6Ap+6ow42QlQngAv2twQkzFPWtjccqF24UjOQolTxHagRQ66OEHn7UiGzJRYVOYVk6ozoJ3y+TYm6hYVhwfI15G+Qg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=bZ/JSkTm; 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="bZ/JSkTm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD4D61F000FF; Wed, 30 Sep 2026 16:37:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790786234; bh=lxLLI8f6Up8+ZLartWCxl1S6YUURbxBmnZkj0v+WuL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bZ/JSkTml6t3ucWjMe2i41eLUNW2LZys/LlqinLkz4psDMHK+lgmk12ZHGRIdsyyR 5g9jEV8xm/MGSSqVECygHmAzYnvK8PF485LGSM0wCPnJbZreFKBtz3sNMdGwKjGSf1 9GlcnYdEl9Qwo36KloxXIWuZR6y5Wcp64ytpbEHk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Beno=C3=AEt=20Sevens?= , Jiri Kosina , Lee Jones , Sasha Levin Subject: [PATCH 6.1 783/982] HID: logitech-hidpp: fix race condition when accessing stale stack pointer Date: Wed, 30 Sep 2026 17:25:19 +0200 Message-ID: <20260930152433.574351063@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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Benoît Sevens commit e2aaf2d3ad92ac4a8afa6b69ad4c38e7747d3d6e upstream. The driver uses hidpp->send_receive_buf to point to a stack-allocated buffer in the synchronous command path (__do_hidpp_send_message_sync). However, this pointer is not cleared when the function returns. If an event is processed (e.g. by a different thread) while the send_mutex is held by a new command, but before that command has updated send_receive_buf, the handler (hidpp_raw_hidpp_event) will observe that the mutex is locked and dereference the stale pointer. This results in an out-of-bounds access on a different thread's kernel stack (or a NULL pointer dereference on the very first command). Fix this by: 1. Clearing hidpp->send_receive_buf to NULL before releasing the mutex in the synchronous command path. 2. Moving the assignment of the local 'question' and 'answer' pointers inside the mutex_is_locked() block in the handler, and adding a NULL check before dereferencing. Fixes: 2f31c5252910 ("HID: Introduce hidpp, a module to handle Logitech hid++ devices") Cc: stable@vger.kernel.org Signed-off-by: Benoît Sevens Signed-off-by: Jiri Kosina [Lee: Clear hidpp->send_receive_buf at exit label in hidpp_send_message_sync() as __do_hidpp_send_message_sync() was split out later in 60165ab774cb] Signed-off-by: Lee Jones Signed-off-by: Sasha Levin --- drivers/hid/hid-logitech-hidpp.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 1d4df88f690c0..37fe852dd2da9 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -315,6 +315,7 @@ static int hidpp_send_message_sync(struct hidpp_device *hidpp, } exit: + hidpp->send_receive_buf = NULL; mutex_unlock(&hidpp->send_mutex); return ret; @@ -3620,8 +3621,7 @@ static int hidpp_input_configured(struct hid_device *hdev, static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data, int size) { - struct hidpp_report *question = hidpp->send_receive_buf; - struct hidpp_report *answer = hidpp->send_receive_buf; + struct hidpp_report *question, *answer; struct hidpp_report *report = (struct hidpp_report *)data; int ret; @@ -3630,6 +3630,12 @@ static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data, * previously sent command. */ if (unlikely(mutex_is_locked(&hidpp->send_mutex))) { + question = hidpp->send_receive_buf; + answer = hidpp->send_receive_buf; + + if (!question) + return 0; + /* * Check for a correct hidpp20 answer or the corresponding * error -- 2.53.0