Message info
 
To:Michael Stone From:Cyril Brulebois Subject:Bug#659499: bash fails to properly read /proc files Date:Sun, 19 Feb 2012 23:14:14 +0100
 

Hi kernel folks,

here's a tiny analysis I tried to perform on bash's having issues with
reading /proc files, which I think is related to seeking in those files.
I can't play much with other kernel versions right now though. My tests
were performed with squeeze's bpo kernel: 3.2.0-0.bpo.1-amd64 (Debian
3.2.4-1~bpo60+1).

I'm stripping parts of my explanations of why other shells seem
unaffected (different implementations for reading files).

Cyril Brulebois <kibi@debian.org> (18/02/2012):
> strace shows it's reading 128 bytes, then trying to adjust using
> lseek(), which might explain what you're seeing if the read() + lseek()
> calls trigger nasty things.

Attached is a reduced (as in “lighter than bash”) test case. The code is
ugly but I'm throwing it over the wall before the BSP's end: built with
bufsize=8000, everything is fine for my 600-ish bytes /proc/net/dev;
built with bufsize=128, read()+lseek() seem to trigger nasty stuff as I
suspected.

Here's the output for bufsize=8000:
| $ gcc mini-test.c && ./a.out
| Warning: no file specified, defaulting to /proc/net/dev
| Info: /proc/net/dev opened successfully
| Read: 694
| Found newline: 76 char-long line: with 617 extra chars:
| Inter-| Receive | Transmit
| Read: 617
| Found newline: 122 char-long line: with 494 extra chars:
| face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
| Read: 494
| Found newline: 122 char-long line: with 371 extra chars:
| lo: 63886 451 0 0 0 0 0 0 63886 451 0 0 0 0 0 0
| Read: 371
| Found newline: 122 char-long line: with 248 extra chars:
| pan0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
| Read: 248
| Found newline: 124 char-long line: with 123 extra chars:
| wlan0: 151354717 197302 0 0 0 0 0 0 22011993 189809 0 0 0 0 0 0
| Read: 123
| Found newline: 122 char-long line: with 0 extra chars:
| eth0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
| Final position: 694
→ OK

Here's the output for bufsize=128:
| $ gcc mini-test.c && ./a.out
| Warning: no file specified, defaulting to /proc/net/dev
| Info: /proc/net/dev opened successfully
| Read: 128
| Found newline: 76 char-long line: with 51 extra chars:
| Inter-| Receive | Transmit
| Read: 128
| Found newline: 122 char-long line: with 5 extra chars:
| face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
| Read: 128
| Found newline: 122 char-long line: with 5 extra chars:
| pan0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
| Final position: 323

Has anything like that been reported/fixed recently?


(Probably my last one:) Thanks to IRILL for sponsoring this BSP in Paris.

Mraw,
KiBi.