Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp543453pxj; Thu, 20 May 2021 15:48:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7mJK9JIxtkmIm1YgBFRYK0X1jPIy2HbQD83GrakvPQjIXpHKY18WgD1+Fe3jgoYb4RBqL X-Received: by 2002:aa7:cb4e:: with SMTP id w14mr7547357edt.40.1621550900121; Thu, 20 May 2021 15:48:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621550900; cv=none; d=google.com; s=arc-20160816; b=Dis5wvUhVS9gjwMacLdMLerwNsJqUeXO0eiYh67/5o1190LWf8YIlGqBl23+yNjMEF 8bmK7dB2s2ZI8LG5zyZxWI5X30aEehMSfJafZjgNN59IMoU19LrAvgkWgOteTWA9Bg+i jiZBe3e1aZ86evEOcI3PUjkyp5B57JdaQ7ewpF9hzR6+gOxQ2tZV85n26b8qmpDqwiYz ohBsf7vF6kte5P+tHoH6Rt3ikSFV0q4jKViApmg4je5jKYv5Qz0LdzNnaiOq2wmFWDib T8/GiDLXI2eDrwI7R9enTqKxx7Odb/s8FjCRuc6V6jMVP+6cn/57UkxHztTDqIjb6u3k xqvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EGhDr/E3y0vGO70EDERi8997+ZyttputLh1yYvDtXcY=; b=yhijQ9o6qI01CvbR9S9tW4r33TCbvppcejXnOTzFtuMWP6NdisSubpIf8jLO7LtruS jZ9KP5oIX0viUE1/J7QDI+NMuUo98iJmvl4Ib5Ah4+umwyVsQv2zw9q1/R9fhktmKhuB Oytre8TEaw5F8QmuLEVlXm3P74yJS25slxDU6k5dOf1yE+VM+0jQzshJw62A4xjEviGj KGtlRur40H21d8p1RG2SaSSSBp34l//pbK2YsI72uMUPWFGRHXcOWWlH+P+kXXcZNOw6 gPi1uKb8C/VMIHcRaKjk9JCtTN2Dg6mSRFqACqBfv6CPHCff0wWkoAHV3OAZnTWG4UiF gF2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kurvXe9K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g13si3298494ejt.512.2021.05.20.15.47.56; Thu, 20 May 2021 15:48:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kurvXe9K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238945AbhETLHc (ORCPT + 99 others); Thu, 20 May 2021 07:07:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:48432 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238452AbhETKsq (ORCPT ); Thu, 20 May 2021 06:48:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 39B7161CBB; Thu, 20 May 2021 09:58:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504738; bh=Ab0KjWe/3oPlBT00cEJsIbOdiOuPeGiXJsW6+7XFwbw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kurvXe9KZlNFHfCILp3MemrhkxcLdH5yfaO/JUx5Fq4KniFTdkItZOcVaCZYqrkCI lTN1a3dcztu2p077GEY5BWmi3aOoQ+yVysuiJyxomT1YQrxUpjyMWyWQWn1Fz0iNvk STiicMV1hCMAyn5Xb9BaAR0xFNAS5GGa3gvpyv7M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Steven Rostedt (VMware)" Subject: [PATCH 4.9 058/240] ftrace: Handle commands when closing set_ftrace_filter file Date: Thu, 20 May 2021 11:20:50 +0200 Message-Id: <20210520092110.638571049@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092108.587553970@linuxfoundation.org> References: <20210520092108.587553970@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: linux-kernel@vger.kernel.org From: Steven Rostedt (VMware) commit 8c9af478c06bb1ab1422f90d8ecbc53defd44bc3 upstream. # echo switch_mm:traceoff > /sys/kernel/tracing/set_ftrace_filter will cause switch_mm to stop tracing by the traceoff command. # echo -n switch_mm:traceoff > /sys/kernel/tracing/set_ftrace_filter does nothing. The reason is that the parsing in the write function only processes commands if it finished parsing (there is white space written after the command). That's to handle: write(fd, "switch_mm:", 10); write(fd, "traceoff", 8); cases, where the command is broken over multiple writes. The problem is if the file descriptor is closed, then the write call is not processed, and the command needs to be processed in the release code. The release code can handle matching of functions, but does not handle commands. Cc: stable@vger.kernel.org Fixes: eda1e32855656 ("tracing: handle broken names in ftrace filter") Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/ftrace.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -4486,8 +4486,11 @@ int ftrace_regex_release(struct inode *i parser = &iter->parser; if (trace_parser_loaded(parser)) { + int enable = !(iter->flags & FTRACE_ITER_NOTRACE); + parser->buffer[parser->idx] = 0; - ftrace_match_records(iter->hash, parser->buffer, parser->idx); + ftrace_process_regex(iter->hash, parser->buffer, + parser->idx, enable); } trace_parser_put(parser);