printf cannot write more than one line to /proc/pid/uid_map

2014-03-25 Thread Kusanagi Kouichi
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I../. -I.././include -I.././lib  -D_FORTIFY_SOURCE=2 -g 
-O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat 
-Werror=format-security -Wall
uname output: Linux crescent 3.14.0-rc7 #1 SMP Mon Mar 17 07:17:51 UTC 2014 
x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.3
Patch Level: 0
Release Status: release

Description:
Bash's builtin printf cannot write more than one line to
/proc/pid/uid_map because printf writes one line at a time
and uid_map can be written only once.

Repeat-By:
shell 1
$ unshare -U
$ echo $$
31861

shell 2
# printf '0 0 1\n1 1 1' > /proc/31861/uid_map
printf: write error: Operation not permitted



Re: printf cannot write more than one line to /proc/pid/uid_map

2014-03-25 Thread Greg Wooledge
On Tue, Mar 25, 2014 at 08:24:13PM +0900, Kusanagi Kouichi wrote:
> Description:
>   Bash's builtin printf cannot write more than one line to
>   /proc/pid/uid_map because printf writes one line at a time
>   and uid_map can be written only once.

Sounds like Bash is using the standard I/O library routines, in line
buffering mode (i.e.  setvbuf(..., _IOLBF, ...);  ).  It's not clear
to me whether this can be considered a bug, as line-buffered output
is common, and situations where it fails are rare.

> Repeat-By:
>   # printf '0 0 1\n1 1 1' > /proc/31861/uid_map
>   printf: write error: Operation not permitted

As a workaround, you might consider something like:

printf '0 0 1\n1 1 1' | dd bs=1024 > /proc/31861/uid_map



Re: printf cannot write more than one line to /proc/pid/uid_map

2014-03-25 Thread Eduardo A . Bustamante López
On Tue, Mar 25, 2014 at 08:24:13PM +0900, Kusanagi Kouichi wrote:
> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-gnu
> Compiler: gcc
> Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' 
> -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
> -DHAVE_CONFIG_H   -I.  -I../. -I.././include -I.././lib  -D_FORTIFY_SOURCE=2 
> -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat 
> -Werror=format-security -Wall
> uname output: Linux crescent 3.14.0-rc7 #1 SMP Mon Mar 17 07:17:51 UTC 2014 
> x86_64 GNU/Linux
> Machine Type: x86_64-pc-linux-gnu
> 
> Bash Version: 4.3
> Patch Level: 0
> Release Status: release
> 
> Description:
>   Bash's builtin printf cannot write more than one line to
>   /proc/pid/uid_map because printf writes one line at a time
>   and uid_map can be written only once.
I don't see why this is a bash bug though. printf works as
documented. The fact that the way it works is incompatible with this
/proc thing is *not* bash's fault. It just means that it's not
flexible enough to tell it to write all at once, but that's not a
bug.

> Repeat-By:
>   shell 1
>   $ unshare -U
>   $ echo $$
>   31861
> 
>   shell 2
>   # printf '0 0 1\n1 1 1' > /proc/31861/uid_map
>   printf: write error: Operation not permitted
> 

-- 
Eduardo Alan Bustamante López



Re: printf cannot write more than one line to /proc/pid/uid_map

2014-03-25 Thread Kusanagi Kouichi
On 2014-03-25 08:58:08 -0500, Dennis Williamson wrote:
> On Mar 25, 2014 8:40 AM, "Kusanagi Kouichi"  wrote:
> >
> > Configuration Information [Automatically generated, do not change]:
> > Machine: x86_64
> > OS: linux-gnu
> > Compiler: gcc
> > Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu'
> -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL
> -DHAVE_CONFIG_H   -I.  -I../. -I.././include -I.././lib
>  -D_FORTIFY_SOURCE=2 -g -O2 -fstack-protector --param=ssp-buffer-size=4
> -Wformat -Werror=format-security -Wall
> > uname output: Linux crescent 3.14.0-rc7 #1 SMP Mon Mar 17 07:17:51 UTC
> 2014 x86_64 GNU/Linux
> > Machine Type: x86_64-pc-linux-gnu
> >
> > Bash Version: 4.3
> > Patch Level: 0
> > Release Status: release
> >
> > Description:
> > Bash's builtin printf cannot write more than one line to
> > /proc/pid/uid_map because printf writes one line at a time
> > and uid_map can be written only once.
> >
> > Repeat-By:
> > shell 1
> > $ unshare -U
> > $ echo $$
> > 31861
> >
> > shell 2
> > # printf '0 0 1\n1 1 1' > /proc/31861/uid_map
> > printf: write error: Operation not permitted
> >
> 
> What happens if you use /usr/bin/printf instead of the Bash builtin?

/usr/bin/printf and dash's printf work as expected.



Re: printf cannot write more than one line to /proc/pid/uid_map

2014-03-25 Thread Andreas Schwab
Greg Wooledge  writes:

> Sounds like Bash is using the standard I/O library routines, in line
> buffering mode (i.e.  setvbuf(..., _IOLBF, ...);  ).

See sh_setlinebuf in shell_initialize.

Andreas.

-- 
Andreas Schwab, SUSE Labs, sch...@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



Re: printf cannot write more than one line to /proc/pid/uid_map

2014-03-25 Thread Pádraig Brady
On 03/25/2014 01:57 PM, Greg Wooledge wrote:
> On Tue, Mar 25, 2014 at 08:24:13PM +0900, Kusanagi Kouichi wrote:
>> Description:
>>  Bash's builtin printf cannot write more than one line to
>>  /proc/pid/uid_map because printf writes one line at a time
>>  and uid_map can be written only once.
> 
> Sounds like Bash is using the standard I/O library routines, in line
> buffering mode (i.e.  setvbuf(..., _IOLBF, ...);  ).  It's not clear
> to me whether this can be considered a bug, as line-buffered output
> is common, and situations where it fails are rare.
> 
>> Repeat-By:
>>  # printf '0 0 1\n1 1 1' > /proc/31861/uid_map
>>  printf: write error: Operation not permitted
> 
> As a workaround, you might consider something like:
> 
> printf '0 0 1\n1 1 1' | dd bs=1024 > /proc/31861/uid_map

Note dd will immediately write any short reads in that case too.
Though not a specific issue here (since the printf will issue a single write()),
to generall get dd to coalesce reads you needs to specify obs separately like:

  printf '0 0 1\n1 1 1' | dd obs=1024 > /proc/31861/uid_map

BTW it's a bit surprising that bash doesn't use standard
"default buffering modes" mentioned here:
http://www.pixelbeat.org/programming/stdio_buffering/

If you want to use the external printf to achieve more
standard buffering modes, you can use `env` like:

  env printf '%s' '0 0 1\n1 1 1' > /proc/31861/uid_map

thanks,
Pádraig.



Re: Special built-ins not persisting assignments

2014-03-25 Thread Mike Frysinger
On Tue 25 Mar 2014 00:39:18 Pollock, Wayne wrote:
> $ echo $BASH_VERSION
> 4.2.45(1)-release
> 
> $ unset foo
> 
> $ foo=bar :
> 
> $ echo $foo
> 
> 
> $
> 
> ===
> 
> According to POSIX/SUS issue 7, assignments for special builtins
> should persist.  So the output should be ``bar''.
> 
> Is there a setting I should turn off (or need to enable), to
> make this work correctly?
> 
> I was able to confirm this bug for version 4.2.37(1)-release as
> well.  (zsh 4.3.17 (i386-redhat-linux-gnu) has the same bug.)

as noted, this is a feature of bash :)

POSIX also imposes annoying behavior that bash fixes:
unset foo   
f() { :; }
foo=bar f
echo $foo

POSIX will show bar (ugh) while bash will not (yeah!)
-mike

signature.asc
Description: This is a digitally signed message part.


Re: printf cannot write more than one line to /proc/pid/uid_map

2014-03-25 Thread Chris Down
Pádraig Brady writes:
> If you want to use the external printf to achieve more
> standard buffering modes, you can use `env` like:
> 
>   env printf '%s' '0 0 1\n1 1 1' > /proc/31861/uid_map

While this will probably work, the more typical way to do this is with
command(1P).


pgpOycint6nTB.pgp
Description: PGP signature


Re: printf cannot write more than one line to /proc/pid/uid_map

2014-03-25 Thread Chet Ramey
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 3/25/14 4:11 PM, Chris Down wrote:
> Pádraig Brady writes:
>> If you want to use the external printf to achieve more
>> standard buffering modes, you can use `env` like:
>>
>>   env printf '%s' '0 0 1\n1 1 1' > /proc/31861/uid_map
> 
> While this will probably work, the more typical way to do this is with
> command(1P).

`command' is a shell builtin that will run shell builtins.  It only skips
shell functions.

- -- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlMx4+QACgkQu1hp8GTqdKt+uACdGGXBCsybrU6qmOXf8g/ibVpX
biMAnRAcmljPxqSkHUAAEzuOoIS1mSih
=RADZ
-END PGP SIGNATURE-



Re: printf cannot write more than one line to /proc/pid/uid_map

2014-03-25 Thread Chris Down
Chet Ramey writes:
> `command' is a shell builtin that will run shell builtins.  It only skips
> shell functions.

Huh, I guess I have been using zsh for too long. I forgot that the
behaviour in bash/POSIX is not the same.


pgpYBta6iEqrR.pgp
Description: PGP signature