linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>
To: Andrew Morton <akpm@linux-foundation.org>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Ingo Molnar <mingo@kernel.org>, Michal Hocko <mhocko@suse.com>,
	John Stultz <john.stultz@linaro.org>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] procfs: let userspace find out max /proc/pid/comm length
Date: Thu, 31 Aug 2017 21:12:51 +0200	[thread overview]
Message-ID: <9b1b41ef58ad245de0e9bb89a66932e73ca55b04.1504206475.git.mirq-linux@rere.qmqm.pl> (raw)
In-Reply-To: <cover.1504206475.git.mirq-linux@rere.qmqm.pl>

Abuse llseek(SEEK_END) to return max /proc/pid/comm length.

This is needed for pthread_getname_np to be able to return ERANGE
without modifying thread's name.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 fs/proc/base.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 7238a64751e4..48089f087a8e 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1542,11 +1542,20 @@ static int comm_open(struct inode *inode, struct file *filp)
 	return single_open(filp, comm_show, inode);
 }
 
+static loff_t comm_lseek(struct file *file, loff_t offset, int whence)
+{
+	/* SEEK_END for seq_files normally gets -EINVAL */
+	if (whence == SEEK_END && offset == 0)
+		return TASK_COMM_LEN - 1;
+
+	return seq_lseek(file, offset, whence);
+}
+
 static const struct file_operations proc_pid_set_comm_operations = {
 	.open		= comm_open,
 	.read		= seq_read,
 	.write		= comm_write,
-	.llseek		= seq_lseek,
+	.llseek		= comm_lseek,
 	.release	= single_release,
 };
 
-- 
2.11.0

      parent reply	other threads:[~2017-08-31 19:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-31 19:12 [PATCH 0/2] procfs: /proc/pid/comm fixes Michał Mirosław
2017-08-31 19:12 ` [PATCH 1/2] procfs: signal /proc/pid/comm write truncation Michał Mirosław
2017-08-31 19:12 ` Michał Mirosław [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9b1b41ef58ad245de0e9bb89a66932e73ca55b04.1504206475.git.mirq-linux@rere.qmqm.pl \
    --to=mirq-linux@rere.qmqm.pl \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhocko@suse.com \
    --cc=mingo@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).