Skip to content

Commit da73fcd

Browse files
committed
Merge branch 'pipe-rework' (patches from David Howells)
Merge two fixes for the pipe rework from David Howells: "Here are a couple of patches to fix bugs syzbot found in the pipe changes: - An assertion check will sometimes trip when polling a pipe because the ring size and indices used are approximate and may be being changed simultaneously. An equivalent approximate calculation was done previously, but without the assertion check, so I've just dropped the check. To make it accurate, the pipe mutex would need to be taken or the spin lock could be used - but usage of the spinlock would need to be rolled out into splice, iov_iter and other places for that. - The index mask and the max_usage values cannot be cached across pipe_wait() as F_SETPIPE_SZ could have been called during the wait. This can cause pipe_write() to break" * pipe-rework: pipe: Fix missing mask update after pipe_wait() pipe: Remove assertion from pipe_poll()
2 parents 3f1266e + 8f868d6 commit da73fcd

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

fs/pipe.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
389389
{
390390
struct file *filp = iocb->ki_filp;
391391
struct pipe_inode_info *pipe = filp->private_data;
392-
unsigned int head, max_usage, mask;
392+
unsigned int head;
393393
ssize_t ret = 0;
394394
int do_wakeup = 0;
395395
size_t total_len = iov_iter_count(from);
@@ -408,12 +408,11 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
408408
}
409409

410410
head = pipe->head;
411-
max_usage = pipe->max_usage;
412-
mask = pipe->ring_size - 1;
413411

414412
/* We try to merge small writes */
415413
chars = total_len & (PAGE_SIZE-1); /* size of the last buffer */
416414
if (!pipe_empty(head, pipe->tail) && chars != 0) {
415+
unsigned int mask = pipe->ring_size - 1;
417416
struct pipe_buffer *buf = &pipe->bufs[(head - 1) & mask];
418417
int offset = buf->offset + buf->len;
419418

@@ -443,7 +442,8 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
443442
}
444443

445444
head = pipe->head;
446-
if (!pipe_full(head, pipe->tail, max_usage)) {
445+
if (!pipe_full(head, pipe->tail, pipe->max_usage)) {
446+
unsigned int mask = pipe->ring_size - 1;
447447
struct pipe_buffer *buf = &pipe->bufs[head & mask];
448448
struct page *page = pipe->tmp_page;
449449
int copied;
@@ -465,7 +465,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
465465
spin_lock_irq(&pipe->wait.lock);
466466

467467
head = pipe->head;
468-
if (pipe_full(head, pipe->tail, max_usage)) {
468+
if (pipe_full(head, pipe->tail, pipe->max_usage)) {
469469
spin_unlock_irq(&pipe->wait.lock);
470470
continue;
471471
}
@@ -510,7 +510,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
510510
break;
511511
}
512512

513-
if (!pipe_full(head, pipe->tail, max_usage))
513+
if (!pipe_full(head, pipe->tail, pipe->max_usage))
514514
continue;
515515

516516
/* Wait for buffer space to become available. */
@@ -579,8 +579,6 @@ pipe_poll(struct file *filp, poll_table *wait)
579579

580580
poll_wait(filp, &pipe->wait, wait);
581581

582-
BUG_ON(pipe_occupancy(head, tail) > pipe->ring_size);
583-
584582
/* Reading only -- no need for acquiring the semaphore. */
585583
mask = 0;
586584
if (filp->f_mode & FMODE_READ) {
@@ -1176,6 +1174,7 @@ static long pipe_set_size(struct pipe_inode_info *pipe, unsigned long arg)
11761174
pipe->max_usage = nr_slots;
11771175
pipe->tail = tail;
11781176
pipe->head = head;
1177+
wake_up_interruptible_all(&pipe->wait);
11791178
return pipe->max_usage * PAGE_SIZE;
11801179

11811180
out_revert_acct:

0 commit comments

Comments
 (0)