Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1346667ybp; Thu, 17 Oct 2019 11:23:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQVP0Neq1ZE1dELqmqXaC7xdim44f0HFAznLW3qQuDo2JKOw9QYe7H+bENRPBwrNXPtwlu X-Received: by 2002:a50:ce06:: with SMTP id y6mr5320415edi.259.1571336611777; Thu, 17 Oct 2019 11:23:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571336611; cv=none; d=google.com; s=arc-20160816; b=UFg4BkVFaYyYO/l09/E5hI8y+dJyU/Q70amxUov2A9ERz7PtIEWEr2l0IguPpGYetc 0Zvq+tol33llm32xCVe3AtZZT2nA5zEPGRZ7V9ppxAolyue1rm849w1JS0s9jw6A1Efn 0llOa28ufRjNKwsdEhJgw+0WsOHBaIMe1jeUHys0jJgboRY4u5nM6NxXWoyVmrRj2Qd7 /4qRSQJMFYEi7leQnXj29rJ1ULwcq2NFAkxznwAkoCXjtbij6mvolTw4sJ+PRcs8+xL6 3ioQi0eW2+mfpn1C3tXgmu6K5YXO0Y2OzOaKEd24fDLq+KYcz2eIl1EZlDBfPcQvzq/P HwVw== 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=hJNwRXuYKHxo3OCA+jXijTJKBsfo0MuDYppkra68Jn8=; b=LHubr3l53HD7EeO1H8lNvF/CIfqA4y/YrZXLPnPsA3qAwTeuH/GkiPUeCknwC+l11h PnhhZUHnNkI4zmzNnT1wIFtFJc0YBCKS1xoKVDuu0F3ZICNm/H6M4XLcZUjSlTv4B+6i AD4Av/DZtkDtEOjPyLPz9nmqnCPZM0Sy1KnY4xi4uh7WGo/neVkwUGRfxxuGvT78G1Ts Uh89e8xBrbTD/AI+5Sq5V/eGwlOhTn91ZRb8hVZrWcjD+67vLkAsBQSmDcW1hOSoOQJi 1lML4H0T9CZbOIPbhaXxgoFzo1NoQ3w9pvNyutkzTgp1mKX6A+US+ugV1QfyNWkvqXDk mefw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YWLt+QWC; 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 g5si1797904ejp.418.2019.10.17.11.23.09; Thu, 17 Oct 2019 11:23:31 -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=YWLt+QWC; 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 S2439025AbfJPWCl (ORCPT + 99 others); Wed, 16 Oct 2019 18:02:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:54638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438572AbfJPV7i (ORCPT ); Wed, 16 Oct 2019 17:59:38 -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 8C63121D7E; Wed, 16 Oct 2019 21:59:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571263177; bh=ISLKsaq/FqtvBASq4WxtSQF4p5xLaOZAWFmz4fOgPG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YWLt+QWCftWkKUxJlwf8PzDyDyMWRCsD2Kb0PsxJ896U7vYC/U4vM5F/prRparhFF b+nyY7HzMW+InWwkJOBCzp4xk2Qpb3smUgMkn2kVoLBe+o36Du9Q/jLsHVDyIuJ3Wj 5gX8gHfxnPqReDamIPezCG9DjENDgk2mZK557yoE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Steven Rostedt (VMware)" Subject: [PATCH 5.3 105/112] ftrace: Get a reference counter for the trace_array on filter files Date: Wed, 16 Oct 2019 14:51:37 -0700 Message-Id: <20191016214907.043942126@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016214844.038848564@linuxfoundation.org> References: <20191016214844.038848564@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 @@ -3540,21 +3540,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; @@ -3584,13 +3585,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; @@ -3602,7 +3603,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; @@ -3610,6 +3610,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; } @@ -5037,6 +5044,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;