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 B7020C432BE for ; Wed, 11 Aug 2021 12:26:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 91EBA60F22 for ; Wed, 11 Aug 2021 12:26:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237710AbhHKM0b (ORCPT ); Wed, 11 Aug 2021 08:26:31 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:50310 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238060AbhHKMYL (ORCPT ); Wed, 11 Aug 2021 08:24:11 -0400 Message-ID: <20210811121417.833987783@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1628684627; 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=J/Q5mp4iSoyn+xkjqqAPGiS328rpsMJOy9V5VRPg834=; b=YbWq8M8e6mURNf9kBScYSoCHRusuPBlCL+ZIQWxJQ2AGaf7Z/ZaowRxohcEvYwFUxsct8D pau6xDXdZl12sCyr5m1MrgTMFsT51wTANT9mtHn2QfN2NXTbHrFCDkKDMMK5Q/JLik5ajN 0x9ejy0UqelZUYxc8L2/e5I0kU6vS0+VNcHJUdQPFVqskiT3nQDTsN0B3Jfxsx2o63Ay+D utlpVah3q35L6ASEFGgf6D3+eoMBUerk0tc77d5sSj9NsnIKdjCQUpH0/H6qBvbUcfo2vA H2SaFREnwkgOJAf75zlKE5txuHHmX/uG3VfyGaDqiiYmAV86ysnlmcZCBOwd4Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1628684627; 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=J/Q5mp4iSoyn+xkjqqAPGiS328rpsMJOy9V5VRPg834=; b=o6gzxAqGgdoXFqKffxQQ+CT7thVxVwa6zPwlJjdfvIAeISjqTF9Q4AW4Gz8LeT4CJTBlTG tQxJqNSecnQP7SAg== 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 62/68] futex: Reorder sanity checks in futex_requeue() 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:47 +0200 (CEST) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org No point in allocating memory when the input parameters are bogus. Validate all parameters before proceeding. Suggested-by: Davidlohr Bueso Signed-off-by: Thomas Gleixner --- V4: New patch --- kernel/futex.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/kernel/futex.c +++ b/kernel/futex.c @@ -1934,13 +1934,6 @@ static int futex_requeue(u32 __user *uad return -EINVAL; /* - * requeue_pi requires a pi_state, try to allocate it now - * without any locks in case it fails. - */ - if (refill_pi_state_cache()) - return -ENOMEM; - - /* * futex_requeue() allows the caller to define the number * of waiters to wake up via the @nr_wake argument. With * REQUEUE_PI waking up more than one waiter is creating @@ -1963,6 +1956,13 @@ static int futex_requeue(u32 __user *uad */ if (nr_wake != 1) return -EINVAL; + + /* + * requeue_pi requires a pi_state, try to allocate it now + * without any locks in case it fails. + */ + if (refill_pi_state_cache()) + return -ENOMEM; } retry: