[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#797479: write(2): returns success but discards the data



Package: src:linux
Version: 3.16.7-ckt11-1+deb8u3
Severity: grave
Justification: causes non-serious data loss

Dear Maintainer,

In certain circumstances, the write(2) syscall returns success, but the data
written is not seen on the other end of the fd.

For example:

   * What led up to the situation?

1. Run 'cat' in xterm
2. Type a single line with 4098 characters (including the newline), e.g.,
   by running `yes | head -2049 | xargs | xclip -i` and pasting the output.
3. Type ^D (EOF)

   * What was the outcome of this action?

4. The write(2) syscall in xterm indicates all 4098 bytes and the subsequent EOF
were written, but the read(2) syscall receives only 4096 bytes before the EOF.
Neither xterm nor cat reports an error.

straces are enclosed; compare lines 37-39 in the xterm xtrace to lines 3-5 in
the cat strace.

   * What outcome did you expect instead?

I expected the read(2) call on line 5 to read the two bytes "y\n", or failing
that the write(2) call on line 38 to return an error.

Cheers,

Daniel

P.S. I initially filed this as #796226 against coreutils.


strace of xterm:

     1	% strace -e write -p ...
     2	write(5, "c", 1)                        = 1
     3	write(5, "a", 1)                        = 1
     4	write(5, "t", 1)                        = 1
     5	write(5, "\r", 1)                       = 1
     6	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
     7	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
     8	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
     9	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    10	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    11	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    12	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    13	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    14	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    15	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    16	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    17	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    18	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    19	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    20	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    21	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    22	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    23	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    24	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    25	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    26	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    27	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    28	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    29	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    30	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    31	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    32	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    33	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    34	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    35	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    36	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    37	write(5, "y y y y y y y y y y y y y y y y "..., 128) = 128
    38	write(5, "y\r", 2)                      = 2
    39	write(5, "\4", 1)                       = 1

strace of cat:

     1	% strace -e trace=desc -p ...
     2	Process 4519 attached
     3	read(0, "y y y y y y y y y y y y y y y y "..., 131072) = 4096
     4	write(1, "y y y y y y y y y y y y y y y y "..., 4096) = 4096
     5	read(0, "", 131072)                     = 0
     6	close(0)                                = 0
     7	close(1)                                = 0
     8	close(2)                                = 0
     9	+++ exited with 0 +++



-- Package-specific info:
** Version:
Linux version 3.16.0-4-amd64 (debian-kernel@lists.debian.org) (gcc version 4.8.4 (Debian 4.8.4-1) ) #1 SMP Debian 3.16.7-ckt11-1+deb8u3 (2015-08-04)

-- System Information:
Debian Release: 8.1
  APT prefers stable
  APT policy: (990, 'stable'), (500, 'testing-updates'), (500, 'stable-updates'), (250, 'testing'), (200, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.16.0-4-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.utf8, LC_CTYPE=en_US.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)


Reply to: