From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 52CE018B476; Fri, 15 Nov 2024 07:00:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731654006; cv=none; b=NzN70CduQpeHF4hAdCrLXU3s2cx3QNEmc2hea81/JuiaVTvaeRw5cfUd0xmuRk6BsnSdWyxj5TdD7gtqDLEYZTP51U1x2196J5/BEelvvuvyx7G1I8p1iJGjq7nqXoMSL3Bj+cznG/4N1lmnGuRkje+Dm189gY5HqQks5S2+mm4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731654006; c=relaxed/simple; bh=iJMCGrgZHRKFh4NU34e3bJ1nErW1/iVHuUOeJERvVuY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SDjnWz7dhBzgBA0Z3hORIXK8gxxPVKdH+uewZB/dICNM9WF44+6hEerghxzuWVpFbQpdH8W7G+AFahjTZz+ydPU/9eIXtiPTtvNZlsCFtaHXD8j+YIgH4DpFtLQp5jtvwLXSTWKgLO3VQbRGVgZeBpjUEjDt93dX4WdwaqPPR0U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=i+QKb9QZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="i+QKb9QZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56FEAC4CECF; Fri, 15 Nov 2024 07:00:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1731654005; bh=iJMCGrgZHRKFh4NU34e3bJ1nErW1/iVHuUOeJERvVuY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i+QKb9QZsx/Rnj4gU0n3w5gkQafm6l0D7IExT6NW2rgLbBg0o7dRXEAzZFnrdCxij x7Cn42acD7HbN42TaexDCDxoBDxZDiydKZofqZ95qyd41WbycGky542X8Dx3t10IzW 6HARTWarE7bLr03Z3n1QLtR3ekS++vqUMDXltaYw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Maximilian Heyne , Hagar Hemdan , Jens Axboe Subject: [PATCH 5.15 17/22] io_uring: fix possible deadlock in io_register_iowq_max_workers() Date: Fri, 15 Nov 2024 07:39:03 +0100 Message-ID: <20241115063721.798128552@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115063721.172791419@linuxfoundation.org> References: <20241115063721.172791419@linuxfoundation.org> User-Agent: quilt/0.67 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-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hagar Hemdan commit 73254a297c2dd094abec7c9efee32455ae875bdf upstream. The io_register_iowq_max_workers() function calls io_put_sq_data(), which acquires the sqd->lock without releasing the uring_lock. Similar to the commit 009ad9f0c6ee ("io_uring: drop ctx->uring_lock before acquiring sqd->lock"), this can lead to a potential deadlock situation. To resolve this issue, the uring_lock is released before calling io_put_sq_data(), and then it is re-acquired after the function call. This change ensures that the locks are acquired in the correct order, preventing the possibility of a deadlock. Suggested-by: Maximilian Heyne Signed-off-by: Hagar Hemdan Link: https://lore.kernel.org/r/20240604130527.3597-1-hagarhem@amazon.com Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- io_uring/io_uring.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -10822,8 +10822,10 @@ static int io_register_iowq_max_workers( } if (sqd) { + mutex_unlock(&ctx->uring_lock); mutex_unlock(&sqd->lock); io_put_sq_data(sqd); + mutex_lock(&ctx->uring_lock); } if (copy_to_user(arg, new_count, sizeof(new_count))) @@ -10848,8 +10850,11 @@ static int io_register_iowq_max_workers( return 0; err: if (sqd) { + mutex_unlock(&ctx->uring_lock); mutex_unlock(&sqd->lock); io_put_sq_data(sqd); + mutex_lock(&ctx->uring_lock); + } return ret; }