From: Justin Cormack <justin@specialbusservice.com>
To: musl@lists.openwall.com
Subject: Re: procfs stdio writev problem
Date: Sun, 5 May 2013 11:01:59 +0100 [thread overview]
Message-ID: <CAK4o1Wy1M2jRW=T+1EhPU=sVq3TmNRHo9jSRftQu0i6uSwC7sQ@mail.gmail.com> (raw)
In-Reply-To: <alpine.LNX.2.10.1305051109540.14689@laas.mine.nu>
On Sun, May 5, 2013 at 10:16 AM, Jens <jensl@laas.mine.nu> wrote:
>
> Hello!
>
> I've noticed a problem when using bash linked with musl.
>
> laas:~# echo 60 > /proc/sys/kernel/panic
> -su: echo: write error: Invalid argument
>
> laas:~# cat t.sh
> #!/bin/bash
> echo 60 > /proc/sys/kernel/panic
>
> laas:~# strace -f t.sh
> ...
> writev(1, [{"60", 2}, {"\n", 1}], 2) = 2
> writev(1, [{"", 0}, {"\n", 1}], 2) = -1 EINVAL (Invalid argument)
>
> I'm guessing that musl uses writev in its stdio implementation.
>
> And I think the error is due to a simplistic implementation in procfs, that
> parses each write on its own, and that the writev is split into several
> writes.
Looks to me at a quick glance like stdio needs something like (untested)
--- ./src/stdio/__stdio_write.c~ 2012-12-01 22:56:34.156555480 +0000
+++ ./src/stdio/__stdio_write.c 2013-05-05 10:59:49.856504883 +0100
@@ -37,7 +37,7 @@
return iovcnt == 2 ? 0 : len-iov[0].iov_len;
}
rem -= cnt;
- if (cnt > iov[0].iov_len) {
+ if (cnt >= iov[0].iov_len) {
f->wpos = f->wbase = f->buf;
cnt -= iov[0].iov_len;
iov++; iovcnt--;
In the case where the kernel exactly eats the iov you need to move
onto the next one rather than have a zero length write pointing just
after the existing one, as that could be an invalid address.
Justin
next prev parent reply other threads:[~2013-05-05 10:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-05 9:16 Jens
2013-05-05 10:01 ` Justin Cormack [this message]
2013-05-05 18:49 ` Jens
2013-05-05 19:03 ` Rich Felker
2013-05-11 3:49 ` Rich Felker
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='CAK4o1Wy1M2jRW=T+1EhPU=sVq3TmNRHo9jSRftQu0i6uSwC7sQ@mail.gmail.com' \
--to=justin@specialbusservice.com \
--cc=musl@lists.openwall.com \
/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.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
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).