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=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 A9804C388F7 for ; Tue, 3 Nov 2020 21:51:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 66F1A223AB for ; Tue, 3 Nov 2020 21:51:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604440269; bh=gKeQlPlU2BL6oNOlRUoiQnJGawgTLyrqz/iDEHV+cTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=mHEM58jhB9S0qb4t2O+7fGUstB6ipa7Azf/U4riU5HqgMNg9rszrYP2EH7JVBtCtS mxmXHw9WuqbRIx91NtgnvsGIs8TiN/qu9Gw2VGGXD6QO+kchLj8TrNeNjfYj8IWqLI BirwzJPl4kc2xVGuYJvd46889pLWvmT0d6Bv9G0Y= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729989AbgKCVvI (ORCPT ); Tue, 3 Nov 2020 16:51:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:40104 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730199AbgKCUsa (ORCPT ); Tue, 3 Nov 2020 15:48:30 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 863A7223FD; Tue, 3 Nov 2020 20:48:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436510; bh=gKeQlPlU2BL6oNOlRUoiQnJGawgTLyrqz/iDEHV+cTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hfJDTMtGW23v7LQSDvL5qP7MSbgzaHtQKFkE/qRl0hOSrr5xA0VIJADy8bXw9Mpxm IIR6M9qhd0INxpEb9ZhOw4YF6bupgL9GFGocF6tpql+Z4wlDt9KdCRaVKpKIPtMSZm vXpcSnhPBUVOs8Vu4UBPvIkIQq85RNg3OGM/BPx8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Jiri Olsa , bpf@vger.kernel.org, "Paul E. McKenney" Subject: [PATCH 5.9 281/391] rcu-tasks: Fix low-probability task_struct leak Date: Tue, 3 Nov 2020 21:35:32 +0100 Message-Id: <20201103203405.996797510@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203348.153465465@linuxfoundation.org> References: <20201103203348.153465465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org From: Paul E. McKenney commit 592031cc10858be4adb10f6c0f2608f6f21824aa upstream. When rcu_tasks_trace_postgp() function detects an RCU Tasks Trace CPU stall, it adds all tasks blocking the current grace period to a list, invoking get_task_struct() on each to prevent them from being freed while on the list. It then traverses that list, printing stall-warning messages for each one that is still blocking the current grace period and removing it from the list. The list removal invokes the matching put_task_struct(). This of course means that in the admittedly unlikely event that some task executes its outermost rcu_read_unlock_trace() in the meantime, it won't be removed from the list and put_task_struct() won't be executing, resulting in a task_struct leak. This commit therefore makes the list removal and put_task_struct() unconditional, stopping the leak. Note further that this bug can occur only after an RCU Tasks Trace CPU stall warning, which by default only happens after a grace period has extended for ten minutes (yes, not a typo, minutes). Fixes: 4593e772b502 ("rcu-tasks: Add stall warnings for RCU Tasks Trace") Cc: Alexei Starovoitov Cc: Daniel Borkmann Cc: Jiri Olsa Cc: Cc: # 5.7.x Signed-off-by: Paul E. McKenney Signed-off-by: Greg Kroah-Hartman --- kernel/rcu/tasks.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/kernel/rcu/tasks.h +++ b/kernel/rcu/tasks.h @@ -1082,11 +1082,11 @@ static void rcu_tasks_trace_postgp(struc if (READ_ONCE(t->trc_reader_special.b.need_qs)) trc_add_holdout(t, &holdouts); firstreport = true; - list_for_each_entry_safe(t, g, &holdouts, trc_holdout_list) - if (READ_ONCE(t->trc_reader_special.b.need_qs)) { + list_for_each_entry_safe(t, g, &holdouts, trc_holdout_list) { + if (READ_ONCE(t->trc_reader_special.b.need_qs)) show_stalled_task_trace(t, &firstreport); - trc_del_holdout(t); - } + trc_del_holdout(t); // Release task_struct reference. + } if (firstreport) pr_err("INFO: rcu_tasks_trace detected stalls? (Counter/taskslist mismatch?)\n"); show_stalled_ipi_trace();