From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86DDCC07E96 for ; Tue, 13 Jul 2021 16:14:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 72BCC6115A for ; Tue, 13 Jul 2021 16:14:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234448AbhGMQRk (ORCPT ); Tue, 13 Jul 2021 12:17:40 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:54698 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233729AbhGMQQt (ORCPT ); Tue, 13 Jul 2021 12:16:49 -0400 Message-Id: <20210713160749.961050050@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1626192838; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: references:references; bh=35IiguvMjyN9HS4qOQgfmae19noJXTGdkXOwXWuAzuM=; b=YkO68uKN/+nUuPh4Oiy+tXzhg2sJh7ru68wEnOjOEcth5ZUrw3YLyLhCQhb5pqsSIhZPaS RyUpoHNnWx97XiM3pXymB24xsmUl0cW4f3kZyk4romgsHBqDMrRgLfxR5565+BnAghMwSB USnf+nwcZwai7XY/Wa+yqHnaTeeQExdusFx0y38sU0GzG2oN8VLESTNluP4awtBu+uY039 FXEKnmHx1Z3jfkfy1dEzivfvWFMP2X3lzGf7dtXsJLTaHO7yD5zxurGAmh+N3IjLNBCI8q U+GFBA2AhljT80uM3pjOGybuHd6N3uMeSjqReiIo3RC2lDIlswO6EIFYqtB81g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1626192838; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: references:references; bh=35IiguvMjyN9HS4qOQgfmae19noJXTGdkXOwXWuAzuM=; b=rhgoLui0l9iQ1QNg4u/voiRa2HEErlocL1O2CR3m2fCa2nHknNRDgUnbBq4p5QgmRq/TZX +hD7QTQMOZk0wQBg== Date: Tue, 13 Jul 2021 17:11:35 +0200 From: Thomas Gleixner To: LKML Cc: Peter Zijlstra , Ingo Molnar , Juri Lelli , Steven Rostedt , Daniel Bristot de Oliveira , Will Deacon , Waiman Long , Boqun Feng , Sebastian Andrzej Siewior , Davidlohr Bueso Subject: [patch 41/50] futex: Validate waiter correctly in futex_proxy_trylock_atomic() References: <20210713151054.700719949@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-transfer-encoding: 8-bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Gleixner The loop in futex_requeue() has a sanity check for the waiter which is missing in futex_proxy_trylock_atomic(). In theory the key2 check is sufficient, but futexes are cursed so add it for completness and paranoia sake. Signed-off-by: Thomas Gleixner --- kernel/futex.c | 4 ++++ 1 file changed, 4 insertions(+) --- --- a/kernel/futex.c +++ b/kernel/futex.c @@ -1879,6 +1879,10 @@ futex_proxy_trylock_atomic(u32 __user *p if (!top_waiter) return 0; + /* Ensure that this is a waiter sitting in futex_wait_requeue_pi() */ + if (!top_waiter->rt_waiter || top_waiter->pi_state) + ret = -EINVAL; + /* Ensure we requeue to the expected futex. */ if (!match_futex(top_waiter->requeue_pi_key, key2)) return -EINVAL;