All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
To: Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>,
	Konstantin Khorenko <khorenko@virtuozzo.com>
Cc: devel@openvz.org, Artem Bulgakov <artem.bulgakov@virtuozzo.com>
Subject: Re: [Devel] [PATCH hci-8.2] fs/pipe: use kvfree() for the buffer arrays of a resized pipe
Date: Tue, 1 Dec 2026 14:08:37 +0100	[thread overview]
Message-ID: <4b3c0010-088e-4f06-92a1-3006bb91475e@virtuozzo.com> (raw)
In-Reply-To: <20261201-pipe-resize-kvfree-v1-1-0a27f34709e0@virtuozzo.com>

Reviewed-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>

On 12/1/26 13:41, Vasileios Almpanis wrote:
> Since commit c14599b9e5f7 ("fs/pipe: Use kvcalloc for pipe buffers")
> the buffer array of a pipe comes from kvcalloc(), but
> pipe_resize_ring() still frees it in two wrong ways.
> 
> When the pipe holds more data than the new size, the EBUSY path frees
> the new array with kfree(). For a large pipe the array comes from
> vmalloc(), and kfree() of a vmalloc address crashes the node. Host root
> hits it with a filled 1 GiB pipe shrunk to 512 MiB:
> 
>   BUG: unable to handle page fault for address: ffffeb0200088008
>   RIP: 0010:kfree+0x83/0x460
>   pipe_resize_ring+0x546/0x5d0
>   pipe_fcntl+0x2da/0x500
>   do_fcntl+0x236/0x1560
> 
> On success the old array is freed with kvfree() under
> pipe->rd_wait.lock with interrupts off, and vfree() can sleep:
> 
>   BUG: sleeping function called from invalid context at mm/vmalloc.c
> 
> Use kvfree() on the EBUSY path, and free the old array after the
> unlock.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-158055
> 
> Feature: mm: avoid high order allocations in all subsystems
> Fixes: c14599b9e5f7 ("fs/pipe: Use kvcalloc for pipe buffers")
> Reported-by: Artem Bulgakov <artem.bulgakov@virtuozzo.com>
> Signed-off-by: Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>
> ---
>  fs/pipe.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/pipe.c b/fs/pipe.c
> index aff1e06a9e2e..4d683870bbfd 100644
> --- a/fs/pipe.c
> +++ b/fs/pipe.c
> @@ -1266,7 +1266,7 @@ unsigned int round_pipe_size(unsigned int size)
>   */
>  int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots)
>  {
> -	struct pipe_buffer *bufs;
> +	struct pipe_buffer *bufs, *old_bufs;
>  	unsigned int head, tail, mask, n;
>  
>  	bufs = kvcalloc(nr_slots, sizeof(*bufs),
> @@ -1282,7 +1282,7 @@ int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots)
>  	n = pipe_occupancy(head, tail);
>  	if (nr_slots < n) {
>  		spin_unlock_irq(&pipe->rd_wait.lock);
> -		kfree(bufs);
> +		kvfree(bufs);
>  		return -EBUSY;
>  	}
>  
> @@ -1309,7 +1309,7 @@ int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots)
>  	head = n;
>  	tail = 0;
>  
> -	kvfree(pipe->bufs);
> +	old_bufs = pipe->bufs;
>  	pipe->bufs = bufs;
>  	pipe->ring_size = nr_slots;
>  	if (pipe->max_usage > nr_slots)
> @@ -1324,6 +1324,8 @@ int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots)
>  
>  	spin_unlock_irq(&pipe->rd_wait.lock);
>  
> +	kvfree(old_bufs);
> +
>  	/* This might have made more room for writers */
>  	wake_up_interruptible(&pipe->wr_wait);
>  	return 0;
> 
> ---
> base-commit: beda1840d22b7707e3f8e18f413afbfffef93d25
> change-id: 20261201-pipe-resize-kvfree-ba7884e83579
> 

-- 
Best regards, Pavel Tikhomirov
Senior Software Developer, Virtuozzo.

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  parent reply	other threads:[~2026-12-01 13:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 12:41 Vasileios Almpanis
2026-12-01 12:44 ` no-reply
2026-12-01 13:08 ` Pavel Tikhomirov [this message]
2026-12-01 15:24 ` Konstantin Khorenko
2026-12-01 15:24 ` Konstantin Khorenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4b3c0010-088e-4f06-92a1-3006bb91475e@virtuozzo.com \
    --to=ptikhomirov@virtuozzo.com \
    --cc=artem.bulgakov@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    --cc=vasileios.almpanis@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.