OpenVZ / Virtuozzo kernel development (devel@openvz.org)
 help / color / mirror / Atom feed
* [Devel] [PATCH hci-8.2] fs/pipe: use kvfree() for the buffer arrays of a resized pipe
@ 2026-12-01 12:41 Vasileios Almpanis
  2026-12-01 12:44 ` no-reply
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Vasileios Almpanis @ 2026-12-01 12:41 UTC (permalink / raw)
  To: Konstantin Khorenko; +Cc: devel, Artem Bulgakov

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, Vasileios Almpanis
Software Developer, Virtuozzo.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Devel] [PATCH hci-8.2] fs/pipe: use kvfree() for the buffer arrays of a resized pipe
  2026-12-01 12:41 [Devel] [PATCH hci-8.2] fs/pipe: use kvfree() for the buffer arrays of a resized pipe Vasileios Almpanis
@ 2026-12-01 12:44 ` no-reply
  2026-12-01 13:08 ` Pavel Tikhomirov
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: no-reply @ 2026-12-01 12:44 UTC (permalink / raw)
  To: Vasileios Almpanis, Konstantin Khorenko; +Cc: devel, Artem Bulgakov

> 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>

Sashiko has reviewed this patch and found no issues.

Carry the trailer below into the next revision and Sashiko will not review this patch again.

Reviewed-by: Sashiko <no-reply@sashiko.virtuozzo.com>

-- 
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261201-pipe-resize-kvfree-v1-1-0a27f34709e0@virtuozzo.com?part=1


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Devel] [PATCH hci-8.2] fs/pipe: use kvfree() for the buffer arrays of a resized pipe
  2026-12-01 12:41 [Devel] [PATCH hci-8.2] fs/pipe: use kvfree() for the buffer arrays of a resized pipe Vasileios Almpanis
  2026-12-01 12:44 ` no-reply
@ 2026-12-01 13:08 ` Pavel Tikhomirov
  2026-12-01 15:24 ` Konstantin Khorenko
  2026-12-01 15:24 ` Konstantin Khorenko
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Tikhomirov @ 2026-12-01 13:08 UTC (permalink / raw)
  To: Vasileios Almpanis, Konstantin Khorenko; +Cc: devel, Artem Bulgakov

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Devel] [PATCH hci-8.2] fs/pipe: use kvfree() for the buffer arrays of a resized pipe
  2026-12-01 12:41 [Devel] [PATCH hci-8.2] fs/pipe: use kvfree() for the buffer arrays of a resized pipe Vasileios Almpanis
  2026-12-01 12:44 ` no-reply
  2026-12-01 13:08 ` Pavel Tikhomirov
@ 2026-12-01 15:24 ` Konstantin Khorenko
  2026-12-01 15:24 ` Konstantin Khorenko
  3 siblings, 0 replies; 5+ messages in thread
From: Konstantin Khorenko @ 2026-12-01 15:24 UTC (permalink / raw)
  To: Vasileios Almpanis; +Cc: devel, Artem Bulgakov

Applying with these fixes on my side:
- Fixes: moved above the Jira URL, as in the vz commit template

On Tue, 1 Dec 2026 12:41:16 +0000, Vasileios Almpanis wrote:
> vmalloc(), and kfree() of a vmalloc address crashes the node. Host root
> hits it with a filled 1 GiB pipe shrunk to 512 MiB:

Not only host root: kvcalloc() tries kmalloc with __GFP_NORETRY first
for anything above a page and falls back to vmalloc when it fails. A
task in a Container near its memory limit can grow a pipe to 1 MiB,
fill it and shrink it, and get the same oops. Worth knowing when
deciding on a ReadyKernel patch; no change needed here.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Devel] [PATCH hci-8.2] fs/pipe: use kvfree() for the buffer arrays of a resized pipe
  2026-12-01 12:41 [Devel] [PATCH hci-8.2] fs/pipe: use kvfree() for the buffer arrays of a resized pipe Vasileios Almpanis
                   ` (2 preceding siblings ...)
  2026-12-01 15:24 ` Konstantin Khorenko
@ 2026-12-01 15:24 ` Konstantin Khorenko
  3 siblings, 0 replies; 5+ messages in thread
From: Konstantin Khorenko @ 2026-12-01 15:24 UTC (permalink / raw)
  To: Vasileios Almpanis; +Cc: devel, Artem Bulgakov

On Tue, 01 Dec 2026 12:41:16 +0000, Vasileios Almpanis wrote:
> fs/pipe: use kvfree() for the buffer arrays of a resized pipe

Applied to branch-rh10-6.12.0-211.75.1.26.x.vz10-ovz, will be released in rh10-6.12.0-211.75.1.26.7.vz10, thanks!

[1/1] fs/pipe: use kvfree() for the buffer arrays of a resized pipe
      https://bitbucket.org/virtuozzocore/vzkernel.vzs/commits/3c1391c9b6ec

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-01 15:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 12:41 [Devel] [PATCH hci-8.2] fs/pipe: use kvfree() for the buffer arrays of a resized pipe Vasileios Almpanis
2026-12-01 12:44 ` no-reply
2026-12-01 13:08 ` Pavel Tikhomirov
2026-12-01 15:24 ` Konstantin Khorenko
2026-12-01 15:24 ` Konstantin Khorenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox