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=-6.8 required=3.0 tests=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 F0308C3A5A8 for ; Wed, 4 Sep 2019 18:07:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CC14F2341E for ; Wed, 4 Sep 2019 18:07:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620425; bh=uWaPL25pe0Llx5gG/+yzOEfACXboyd03F+p56skofao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=Nn6hZ22ELzckZM6AFLTDTTReZAeDptcqSfvISzYcy7zev5dQqSB7tbg5WYwAEEpKu 9PyMi6jDCH6xnD8EYfAqJbsnPo41RdIKSQau8kcm6cPfPUr0QSmGiWf2hUTii8AxTQ K+s5FbZuenR5FHeG9lyG9JxR7ac3wljnBOKs0By8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388614AbfIDSHE (ORCPT ); Wed, 4 Sep 2019 14:07:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:49362 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389556AbfIDSHD (ORCPT ); Wed, 4 Sep 2019 14:07:03 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 BB93722CF7; Wed, 4 Sep 2019 18:07:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620422; bh=uWaPL25pe0Llx5gG/+yzOEfACXboyd03F+p56skofao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cUASt3zzDRa5syxicgez5Vbd63mYxriP2a2pySoZ0Pw8aGozSh9KL48ZPZCVmIRBQ 1xyJe8b6Vcfmy2pxw0L1i9Oh+5Lrh9mDsr/JdCi+IYbrmJg+R3rtehCNMgwTs8+sc3 iAvjmzz0YxKat24I6LhEX4aCxb4X2+8eapU4xfMw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Steven Rostedt (VMware)" Subject: [PATCH 4.19 53/93] ftrace: Check for empty hash and comment the race with registering probes Date: Wed, 4 Sep 2019 19:53:55 +0200 Message-Id: <20190904175307.599372951@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175302.845828956@linuxfoundation.org> References: <20190904175302.845828956@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steven Rostedt (VMware) commit 372e0d01da71c84dcecf7028598a33813b0d5256 upstream. The race between adding a function probe and reading the probes that exist is very subtle. It needs a comment. Also, the issue can also happen if the probe has has the EMPTY_HASH as its func_hash. Cc: stable@vger.kernel.org Fixes: 7b60f3d876156 ("ftrace: Dynamically create the probe ftrace_ops for the trace_array") Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/ftrace.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -3113,7 +3113,11 @@ t_probe_next(struct seq_file *m, loff_t hash = iter->probe->ops.func_hash->filter_hash; - if (!hash) + /* + * A probe being registered may temporarily have an empty hash + * and it's at the end of the func_probes list. + */ + if (!hash || hash == EMPTY_HASH) return NULL; size = 1 << hash->size_bits; @@ -4311,6 +4315,10 @@ register_ftrace_function_probe(char *glo mutex_unlock(&ftrace_lock); + /* + * Note, there's a small window here that the func_hash->filter_hash + * may be NULL or empty. Need to be carefule when reading the loop. + */ mutex_lock(&probe->ops.func_hash->regex_lock); orig_hash = &probe->ops.func_hash->filter_hash;