Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1938784ybv; Fri, 14 Feb 2020 08:33:04 -0800 (PST) X-Google-Smtp-Source: APXvYqwPwzJGVPD1olstvCTf+mtdGiRsueQBzqaHWp5q0eR7VY9z0+vVXIS7cSsW8dolZ+4jg8er X-Received: by 2002:a9d:1c96:: with SMTP id l22mr3020403ota.322.1581697984360; Fri, 14 Feb 2020 08:33:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581697984; cv=none; d=google.com; s=arc-20160816; b=Z1yQiDjl2vDqsIDTDFg+PoPgPYMLfnGjr2IY0Z1DdzFrhFcderJ3Fi3Rgw9LhGamuH mEWijY9egPdYzVMdtXTxJYGp7xYV1ENw1XiIhhy90NTVuGt/zW+J7qCgyxaAuVafO0d3 Bezh98vR1f8EPM93PcW6jdCG8rBTs2LEuLQkkHYjG/BQLsFD6Qi3InkpNbPBe8p6Yavn oKkXJ6cJFVY5fO2I8hn82sx0HgTLyCtMXdkI0ktArtm34xKh+KkfJbWvHFO2h/4xmyBJ GmOqtaqtbgfkqoRWAtt9eh9lOFbCVSBE9q2ZZahGJakFws6CqD5CmKEBAGxOSEvafsY1 m/5Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lKqI8t6hrqkBCiwJNfWJpql8UoRcnsdn8CwIwNqdsu8=; b=Xs23CIioai9oEiL7jFJDNUgS+sGc5MA60rXb2IzY0Z49hxRNicM1uKfY0JommgHwgY s5zl8BkgqWss04AVqvO2HqIwmduklQeUaD2SQ0QN4WhSK0zUWWvukBrUm7XyK+bLFNnE SZAEH5XbbnFlBCEB83lr8dmHljdniXLBF9PSuH+H+FT1NSke4Ve6PYAPVN2jsI8+pDKW vO6eU2PRPN382hJDHRb9Z/27IRdtRtDIxnXskC+H5uYHRIHJrm0dM6ZWt99UZ8xT19vG Lg9zLQzjXeg+Og5TGPSG6O/SeC5z1fFV2PjeAIMDbqxjxr+Fw3oVhyrW2XAfKZmCQubt wzAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XjDj1Qil; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q26si2942885oij.38.2020.02.14.08.32.52; Fri, 14 Feb 2020 08:33:04 -0800 (PST) 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=XjDj1Qil; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406308AbgBNQ0I (ORCPT + 99 others); Fri, 14 Feb 2020 11:26:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:60644 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405796AbgBNQYE (ORCPT ); Fri, 14 Feb 2020 11:24:04 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3085B2478B; Fri, 14 Feb 2020 16:24:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581697443; bh=f3FB7IBIjO231L3q8BcFPZb+tImF0hnLMlwnUYFEUMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XjDj1Qiltypln4sA2+UOCHvid5d7VB+lY1KbuQ6AYdhhmNWzVCJuETCD2c+Fy1uvH w8B6P6NmwIlqz27ZFsc9KuyoHJ7LaSd1OxPQyX19h3/IKf9ppU1vmDUhqOAPeHx/Ja 16tyel7Bv8dAlhdPFWxraSboFcUR42AbLoXT9RrI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Vasily Averin , Steven Rostedt , Sasha Levin Subject: [PATCH AUTOSEL 4.9 129/141] ftrace: fpid_next() should increase position index Date: Fri, 14 Feb 2020 11:21:09 -0500 Message-Id: <20200214162122.19794-129-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200214162122.19794-1-sashal@kernel.org> References: <20200214162122.19794-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vasily Averin [ Upstream commit e4075e8bdffd93a9b6d6e1d52fabedceeca5a91b ] if seq_file .next fuction does not change position index, read after some lseek can generate unexpected output. Without patch: # dd bs=4 skip=1 if=/sys/kernel/tracing/set_ftrace_pid dd: /sys/kernel/tracing/set_ftrace_pid: cannot skip to specified offset id no pid 2+1 records in 2+1 records out 10 bytes copied, 0.000213285 s, 46.9 kB/s Notice the "id" followed by "no pid". With the patch: # dd bs=4 skip=1 if=/sys/kernel/tracing/set_ftrace_pid dd: /sys/kernel/tracing/set_ftrace_pid: cannot skip to specified offset id 0+1 records in 0+1 records out 3 bytes copied, 0.000202112 s, 14.8 kB/s Notice that it only prints "id" and not the "no pid" afterward. Link: http://lkml.kernel.org/r/4f87c6ad-f114-30bb-8506-c32274ce2992@virtuozzo.com https://bugzilla.kernel.org/show_bug.cgi?id=206283 Signed-off-by: Vasily Averin Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Sasha Levin --- kernel/trace/ftrace.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 71a40e5c3a9f0..2ae98f8bce81b 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -5455,9 +5455,10 @@ static void *fpid_next(struct seq_file *m, void *v, loff_t *pos) struct trace_array *tr = m->private; struct trace_pid_list *pid_list = rcu_dereference_sched(tr->function_pids); - if (v == FTRACE_NO_PIDS) + if (v == FTRACE_NO_PIDS) { + (*pos)++; return NULL; - + } return trace_pid_next(pid_list, v, pos); } -- 2.20.1