From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/3291 Path: news.gmane.org!not-for-mail From: Jens Newsgroups: gmane.linux.lib.musl.general Subject: Re: procfs stdio writev problem Date: Sun, 5 May 2013 20:49:50 +0200 (CEST) Message-ID: References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Trace: ger.gmane.org 1367779786 22332 80.91.229.3 (5 May 2013 18:49:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 5 May 2013 18:49:46 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-3295-gllmg-musl=m.gmane.org@lists.openwall.com Sun May 05 20:49:47 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1UZ40D-00068c-Gz for gllmg-musl@plane.gmane.org; Sun, 05 May 2013 20:49:41 +0200 Original-Received: (qmail 5471 invoked by uid 550); 5 May 2013 18:49:40 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 5463 invoked from network); 5 May 2013 18:49:40 -0000 In-Reply-To: User-Agent: Alpine 2.10 (LNX 1266 2009-07-14) Xref: news.gmane.org gmane.linux.lib.musl.general:3291 Archived-At: On Sun, 5 May 2013, Justin Cormack wrote: > On Sun, May 5, 2013 at 10:16 AM, Jens 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. In this case its not the zero length that is the problem. The problem is that procfs treats each write (or apprently each part of the iov) as a separate operation. So the first operation is "60" which is fine. The next one is "\n" which is invalid. So we get two operations instead of one. The implementation in bash amounts to a printf("60") followed by putchar('\n'); The same thing in uclibc works as intended. I guess I can patch bash, or use sysctl program. AFAIK neither musl or procfs is doing anything wrong here, it just happens that a pure echo no longer works as it used to. Cheers, Jens > > Justin >