Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1386550ybp; Thu, 17 Oct 2019 12:02:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqyB9YNHuoe40kR26hgBrB4m/IPG4jno3jYzrtgL2pVdAuR9VtTSvj5TQcfPGlBm/e/ydxxm X-Received: by 2002:a17:906:48c6:: with SMTP id d6mr4983779ejt.291.1571338927918; Thu, 17 Oct 2019 12:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571338927; cv=none; d=google.com; s=arc-20160816; b=txQ01jADVBrOfywJEu9Xl/eEuN+Y5x1CVnhZP/Yt8LR8jk31l5BJnAVtPyPsaTABw5 +6ceCX9AvQYJEWjGgWo0DH0C2YniDjS+qZ5c983pdv9Db+IthTVP20NGzlbZZUHKcvE1 FIb2IoyFxmIx+0iB6AfDEM331xfAo91gQQqvcbY+sTXlBBvqkLdmGTw+qQXW6nhUcGWU aiyxttTRxXmZeaFPR5Efu3MInViYHUwKjD1vw8TmPPSJVTXPKzR94rdGnmfB1WMTEMlN UKABHwiiIiTRYoDtTCxkJm/g+GUAaKhmjEKK98e3on/OQ6BQ7mKcLFJTA9/Jvm1yGUV7 WraA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lFFvdAn8I/yhWxQxKipOmxKFcozOixKGnNYBWKrf5Ig=; b=J9i3Mnm0ugHSoV/zSmU153CyCXo9Yfdo4KluxLxx8+uVGqLbitqv9KrcKHgVIrUqId tD9xl+6nHd3Fsss0jfjPI9tHf8x42HN4TOzqggtTtEtoctrjqIIe/WruWrxfxizSeRew 4fOOH8H7NcqVms6X/9aNPczLdMlRVDh2JJMpeJVW8gmmfJHsas9cxDFjcymI6YzpSaDs Fk4uvEXwzf34thyQFvXrGbSWAnoGIygW3M47QhKAFktxKvg5O31ctW3l9YkL5c2xSULX J+EchryCqAkwyUuaP097Ns2gz+FWUvdejU+gx7yLKEIVCIRQONUg9LpS/jND1xaBEBrw jvGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yNwZUPxi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y20si2127483edo.436.2019.10.17.12.01.43; Thu, 17 Oct 2019 12:02:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yNwZUPxi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439233AbfJPWL7 (ORCPT + 99 others); Wed, 16 Oct 2019 18:11:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:48362 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395380AbfJPV4f (ORCPT ); Wed, 16 Oct 2019 17:56:35 -0400 Received: from localhost (unknown [192.55.54.58]) (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 6BD5D21A49; Wed, 16 Oct 2019 21:56:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571262994; bh=ZMCX9A9XKGm5q/+zflXd5y5AjLNg4mDznV7taU+wOc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yNwZUPxiLSBgiWVmfxG2eb91nR3dw4jfFDQ1ZXDD35h1Q+ld3T7++wr9oKTy38jWd 98NfJuzp81OGyCUE2A6mqnp0YK9dYUPxOtxVvKX96YakaEbvYPr3ANtOSqAfCOuWO/ Q3pKuvtpaCtf9i+/aR5pRm4Tgjmei+3cSbQRskSU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Steven Rostedt (VMware)" Subject: [PATCH 4.14 62/65] ftrace: Get a reference counter for the trace_array on filter files Date: Wed, 16 Oct 2019 14:51:16 -0700 Message-Id: <20191016214839.912090427@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214756.457746573@linuxfoundation.org> References: <20191016214756.457746573@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 9ef16693aff8137faa21d16ffe65bb9832d24d71 upstream. The ftrace set_ftrace_filter and set_ftrace_notrace files are specific for an instance now. They need to take a reference to the instance otherwise there could be a race between accessing the files and deleting the instance. It wasn't until the :mod: caching where these file operations started referencing the trace_array directly. Cc: stable@vger.kernel.org Fixes: 673feb9d76ab3 ("ftrace: Add :mod: caching infrastructure to trace_array") Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/ftrace.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -3629,21 +3629,22 @@ ftrace_regex_open(struct ftrace_ops *ops struct ftrace_hash *hash; struct list_head *mod_head; struct trace_array *tr = ops->private; - int ret = 0; + int ret = -ENOMEM; ftrace_ops_init(ops); if (unlikely(ftrace_disabled)) return -ENODEV; + if (tr && trace_array_get(tr) < 0) + return -ENODEV; + iter = kzalloc(sizeof(*iter), GFP_KERNEL); if (!iter) - return -ENOMEM; + goto out; - if (trace_parser_get_init(&iter->parser, FTRACE_BUFF_MAX)) { - kfree(iter); - return -ENOMEM; - } + if (trace_parser_get_init(&iter->parser, FTRACE_BUFF_MAX)) + goto out; iter->ops = ops; iter->flags = flag; @@ -3673,13 +3674,13 @@ ftrace_regex_open(struct ftrace_ops *ops if (!iter->hash) { trace_parser_put(&iter->parser); - kfree(iter); - ret = -ENOMEM; goto out_unlock; } } else iter->hash = hash; + ret = 0; + if (file->f_mode & FMODE_READ) { iter->pg = ftrace_pages_start; @@ -3691,7 +3692,6 @@ ftrace_regex_open(struct ftrace_ops *ops /* Failed */ free_ftrace_hash(iter->hash); trace_parser_put(&iter->parser); - kfree(iter); } } else file->private_data = iter; @@ -3699,6 +3699,13 @@ ftrace_regex_open(struct ftrace_ops *ops out_unlock: mutex_unlock(&ops->func_hash->regex_lock); + out: + if (ret) { + kfree(iter); + if (tr) + trace_array_put(tr); + } + return ret; } @@ -5098,6 +5105,8 @@ int ftrace_regex_release(struct inode *i mutex_unlock(&iter->ops->func_hash->regex_lock); free_ftrace_hash(iter->hash); + if (iter->tr) + trace_array_put(iter->tr); kfree(iter); return 0;