linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
	Alexei Starovoitov <ast@kernel.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: Garbage data while reading via usermode driver?
Date: Mon, 16 Nov 2020 12:35:25 +0000	[thread overview]
Message-ID: <20201116123525.GW3576660@ZenIV.linux.org.uk> (raw)
In-Reply-To: <0c98ab7f-8483-bb54-7b8f-3d69ed45f1ff@i-love.sakura.ne.jp>

On Mon, Nov 16, 2020 at 08:11:04PM +0900, Tetsuo Handa wrote:
> Hello.
> 
> Below is a loadable kernel module which attempts to read (for example) /proc/interrupts from
> kernel using usermode driver interface. What is strange is that the total bytes obtained by
> doing "wc -c /proc/interrupts" from userspace's shell and trying to insmod this kernel module
> differs; for unknown reason, kernel_read() returns "#!/bin/cat /proc/interrupts\n" (28 bytes)
> at the end of input.

Because /bin/cat writes it out ;-)

$ echo "#!/bin/echo foo" >/tmp/a
$ chmod +x /tmp/a
$ /tmp/a
foo /tmp/a
$

IOW, same way #!/bin/sh -e in the beginning of /tmp/foo.sh results in exec
of /bin/sh with -e and /tmp/foo.sh in the arguments, #!/bin/cat /proc/interrupts
in /tmp/bar.sh will result in exec of /bin/cat with /proc/interrupts and
/tmp/bar.sh in parameters.  With cat(1) doing what it's supposed to do.

  parent reply	other threads:[~2020-11-16 12:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-16 11:11 Garbage data while reading via usermode driver? Tetsuo Handa
2020-11-16 12:23 ` Tetsuo Handa
2020-11-16 12:35 ` Al Viro [this message]
2020-11-16 14:15   ` Tetsuo Handa

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=20201116123525.GW3576660@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=ast@kernel.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    /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).