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,URIBL_BLOCKED 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 30635C432BE for ; Wed, 11 Aug 2021 12:25:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 11B55604DC for ; Wed, 11 Aug 2021 12:25:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231373AbhHKM0S (ORCPT ); Wed, 11 Aug 2021 08:26:18 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:50274 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238292AbhHKMYC (ORCPT ); Wed, 11 Aug 2021 08:24:02 -0400 Message-ID: <20210811121417.417875300@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1628684618; 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=dIDJMNRwhT3cmHlH64KgwOQfGpxXmECFG6+jpah8Ozg=; b=KVFJ/Va1+AIlKEtlY/rDiRlin47pGxUE5ekWRZMy/9anGTWcMiyDwSaUyBb0hFGwX0W7bM cso4NX9nSBZtbpDwVUq158w8ZWH+ab+Eurhb/RF2xT7mYxvWhnGJk1zheZa+KLt1O0jaRb sx9ZUdjJ5TwjE6XrZ0DNuriOtY7zR3oRFmJTV/jFQzEGae63k1zcqwR/QWHraDnmWFNF+a IwySzo0HYZRAd8yZwjijfrLk4D6J6As6a+W8pm3BDCIGXxxhvWp3aOB7FGATIBWcFY6zFa LN+S5q1FIRWd5biYlJqnwLrTPNaNAxyNNbLQsR7TfGC2oOCuNk4Kiq0QP+bTVQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1628684618; 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=dIDJMNRwhT3cmHlH64KgwOQfGpxXmECFG6+jpah8Ozg=; b=NwELPFklSH4w12SEMJ1CIYj2qNM6VkzJFGcP8INb9T+FUV/a32ZW7NeF2bNZ9zyURxCrHg OjGbVcUfAcYWxCBw== 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 , Mike Galbraith Subject: [patch V4 55/68] futex: Validate waiter correctly in futex_proxy_trylock_atomic() References: <20210811120348.855823694@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-transfer-encoding: 8-bit Date: Wed, 11 Aug 2021 14:23:38 +0200 (CEST) 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 completeness and paranoia sake. Signed-off-by: Thomas Gleixner --- kernel/futex.c | 7 +++++++ 1 file changed, 7 insertions(+) --- --- a/kernel/futex.c +++ b/kernel/futex.c @@ -1879,6 +1879,13 @@ futex_proxy_trylock_atomic(u32 __user *p if (!top_waiter) return 0; + /* + * Ensure that this is a waiter sitting in futex_wait_requeue_pi() + * and waiting on the 'waitqueue' futex which is always !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;