From: Jakub Jankowski <shasta@toxcorp.com>
To: linux-kernel@vger.kernel.org
Subject: get_mm_cmdline and userspace (Perl) changing argv0
Date: Fri, 5 Apr 2019 23:50:01 +0200 (CEST) [thread overview]
Message-ID: <alpine.LNX.2.21.1904052326230.3249@kich.toxcorp.com> (raw)
Starting with 4.18 we noticed changing own commandline in Perl by setting
$0 leads to (a bit) surprising results.
As long as we're setting $0 to something longer than the initial argv0,
everything works (almost) as expected: reading from /proc/$$/cmdline
yields what we set $0 to, followed by a single NULL byte.
However, when setting $0 to something shorter, doing the same yields what
we set $0 to, then a single NULL byte, then thousands (depending on the
size of the environment) of ' ' (0x20), and then a single NULL.
$ for i in $(seq 1 10); do
perl -e '$0 = "1234567890"x'"$i"'; print `cat /proc/$$/cmdline`;' | wc -c;
done
3291
3291
3291
3291
3291
3291
71
81
91
101
$
This leads to weird output of commands like "ps axufww", where a
daemonized Perl script that had changed its $0 shows up as a long, mostly
empty line on the process list.
We've seen this on both Perl 5.20 and 5.28, and Perl's code handling
changes to $0 hasn't really changed since:
https://perl5.git.perl.org/perl.git/blob/HEAD:/mg.c#l2673
Reverting commit 5ab8271899658042fabc5ae7e6a99066a210bc0e ("fs/proc:
simplify and clarify get_mm_cmdline() function") in kernel, however, seems
to restore previous behavior (no NULL byte at the end):
$ for i in $(seq 1 10); do
perl -e '$0 = "1234567890"x'"$i"'; print `cat /proc/$$/cmdline`;' | wc -c;
done
10
20
30
40
50
60
70
80
90
100
$
Has anybody else seen / been bothered by this?
Regards,
Jakub.
--
Jakub Jankowski|shasta@toxcorp.com|https://toxcorp.com/
GPG: FCBF F03D 9ADB B768 8B92 BB52 0341 9037 A875 942D
reply other threads:[~2019-04-05 21:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=alpine.LNX.2.21.1904052326230.3249@kich.toxcorp.com \
--to=shasta@toxcorp.com \
--cc=linux-kernel@vger.kernel.org \
/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).