splice: Prevent gifting of multipage folios
Subsystems (3)
RFC PATCH v2 1/1 splice: Prevent gifting of multipage folios
Don't let parts of compound pages/multipage folios be gifted by (vm)splice into a pipe as the other end may only be expecting single-page gifts (fuse and virtio console for example).
replace_page_cache_folio(), for example, will do the wrong thing if it tries to replace a single paged folio with a multipage folio.
Try to avoid this by making add_to_pipe() remove the gift flag on multipage folios.
--- fs/splice.c | 2 ++ 1 file changed, 2 insertions(+)
fs/splice.c +2 -0
@@ -240,6 +240,8 @@ ssize_t add_to_pipe(struct pipe_inode_info *pipe, struct pipe_buffer *buf) }else if (pipe_full (head, tail, pipe->max_usage)) { ret = -EAGAIN ; }else { +if (PageCompound (buf->page)) + buf->flags &= ~PIPE_BUF_FLAG_GIFT ; pipe->bufs[head & mask] = *buf; pipe->head = head +1 ;return buf->len;
Quoted 8 lines · David Howells
Don't let parts of compound pages/multipage folios be gifted by (vm)splice into a pipe as the other end may only be expecting single-page gifts (fuse and virtio console for example).
replace_page_cache_folio(), for example, will do the wrong thing if it tries to replace a single paged folio with a multipage folio.
Quoted 6 lines
Try to avoid this by making
add_to_pipe()remove the gift flag on multipage folios.Fixes 7afa6fd037e5 ("[PATCH] vmsplice: allow user to pass in gift pages")Signed-off-by David Howells <[email protected]>cc Matthew Wilcox <[email protected]>
Quoted 24 lines
cc Jens Axboe <[email protected]>cc Miklos Szeredi <[email protected]>cc Amit Shah <[email protected]>--- fs/splice.c | 2 ++ 1 file changed, 2 insertions(+)fs/splice.c +2
-0@@ -240,6 +240,8 @@ ssize_t add_to_pipe(struct pipe_inode_info *pipe, struct pipe_buffer *buf) }else if (pipe_full (head, tail, pipe->max_usage)) { ret = -EAGAIN ; }else { +if (PageCompound (buf->page)) + buf->flags &= ~PIPE_BUF_FLAG_GIFT ; pipe->bufs[head & mask] = *buf; pipe->head = head +1 ;return buf->len;