lkml.org 
[lkml]   [2018]   [Oct]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
Subjectsys_tee() bug: after tee() of partial page, both pipes can merge, clobbering each other's data
Hi!

I noticed the following behavior; basically, after copying part of a
normal pipe buffer (anon_pipe_buf_ops) from pipe A to pipe B, both
pipe A and pipe B can merge new writes into the existing page,
clobbering each other's data:

============
$ cat tee_test.c
#define _GNU_SOURCE
#include <fcntl.h>
#include <unistd.h>
#include <err.h>
#include <stdio.h>

int main(void) {
int pipe_a[2];
if (pipe(pipe_a)) err(1, "pipe");
int pipe_b[2];
if (pipe(pipe_b)) err(1, "pipe");
if (write(pipe_a[1], "abcd", 4) != 4) err(1, "write");
if (tee(pipe_a[0], pipe_b[1], 2, 0) != 2) err(1, "tee");
if (write(pipe_b[1], "xx", 2) != 2) err(1, "write");

char buf[5];
if (read(pipe_a[0], buf, 4) != 4) err(1, "read");
buf[4] = 0;
printf("got back: '%s'\n", buf);
}
$ gcc -o tee_test tee_test.c
$ ./tee_test
got back: 'abxx'
$
============

splice_pipe_to_pipe() probably has the same problem?

I'm not sure what the cleanest way to fix this would be. Replace
anon_pipe_buf_ops with packet_pipe_buf_ops when copying a buffer? Or
add a new buffer flag for marking a buffer as mergeable, and get rid
of buf->ops->can_merge?

\
 
 \ /
  Last update: 2018-10-15 04:14    [W:0.029 / U:0.120 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site