From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 88AFD80033 for ; Tue, 1 Dec 2026 12:42:41 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6B1CfOHp007455; Tue, 1 Dec 2026 15:41:25 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6B1CfOHp007455 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="Ddz+jsGC" Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6B1CfMTT007446 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 1 Dec 2026 15:41:22 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6B1CfMTT007446 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-6babdfe377cso8604008a12.0 for ; Tue, 01 Dec 2026 04:41:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErGoaGi2bBo2LAWrlUyFK9HNqAOg4LQzEmLQcFJYh8PJUxF9A+r5qm9bbsaWN8McZNxsIUS7PA==@openvz.org X-Gm-Message-State: APuU4Z9zX9V4En45s+Abc/qND9wgKOcs6sL/Kv5VDJsK7KL9N5VxciHu 2c0BbCYyb/hHLChQyDUqfGlMjhARqjr0EC9/0AdmHBZk9CNUXzZQdUJf9lL+ZVvASKUTLJUJt0o esmerrovVEWjOeKxq810Z+JqGVMOIdLzXR/29Ee+qeN5SfHHhIaWWAw== X-Gm-Gg: AZFdTZdcHooy8spdddpUZfJR28WYYvvnH5EVjZAjrd+1pPVHTwLH9xzUoQQTNAUybuY /SibLpR7ix76exGA7xpus0dmF79hz41eK1El4pijA4aHzc6j41fOIiDWEYxQLu0lnTw3UxHKHCt DKsKpRvx5RZwp3knX2IrtKpW4vveL4LCTA7G47qEKMZEsH49iegyxh/HazYr8gUHrWx2VOKDD23 2aKHn4utwipB2vjebXaF6jZ9htEKpD/rwMrPwqx7evUQVVIq4+bMxzHXhwCT3R5Us9tBwLS4rI2 NvuZPUA4BpomHE456zd+N8JXfEodHHoeKLT+DTpo5JPLR6pg6D7JpB/8tun/zmZWtgGwhsFVh7w Q5CC/jvx20FUtZ2pqYfCOyCfVrJaY2A== X-Received: by 2002:a05:6402:280e:b0:6b7:d55:87d3 with SMTP id 4fb4d7f45d1cf-6ba37ea7696mr23060475a12.36.1796128881789; Tue, 01 Dec 2026 04:41:21 -0800 (PST) X-Received: by 2002:a05:6402:280e:b0:6b7:d55:87d3 with SMTP id 4fb4d7f45d1cf-6ba37ea7696mr23060462a12.36.1796128881307; Tue, 01 Dec 2026 04:41:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1796128881; cv=none; d=google.com; s=arc-20260327; b=YkdTI2aiZ9vvaQPjeLI7So1Hc0zSKBfNrHGBWPxI+Je+seNMjQHi2r6lYMvRTsbW5T dJybrK63YlMPuTu+Ydxz105NcPbkq+gY3BshBE8HjXLlQtUOyxpRlMxfTEXcGAyIZOIj IKJfaKvYiGZXBGwUC7nkETlNBGeh3gX/qUv6uUHe747Q4miX15gSd1sd1CTr1BQZ3XNm UgrRfr2+IeC7TUtHLOXTsD8W9lMQgrFyrO283WhYNWUgDSyCjF17N9gjARXTeb0ZxCZq 3ACEHGBJ8W7+zzrE4n/T9UGq85pQL/4VVubGjG3v0wsLSVSe29YUjov6a1BBJ20bR/ot sI+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:dkim-signature; bh=qqCLJpa1t2+E4H1NbXI+G21lYsUIK1cWTeImCgitoDk=; fh=OOBPLl9PCJHy5FjSaPIrdL8lHgjk1ut2n2T6SRmLp6w=; b=bPkSvXpAG/XBcWhLABDpgg5x7ApBysXuAzlz/uKsPDgOUf758Gm+N2XCJMaMJQlj9a u+C3RlmRQmjXDNn766IzGfHG312Yt4go91+NexxmCaY1ZGgS3fbzZrt/I06DYHFydS1t Rwb9CM+wikmVGTOScuYsoZg+vF7IHCsjBVvQri2rMF9GPLlDE6T4Y7eKoer2azIwNqFu /0irfZrsnQyrMmol/ESexRYNF+CgGjcquju0xkC/kvHWmZ7VwtafMz9yxTs6WXN8KJKc nczECPead+G1kvhw7t1Vr9NYBM5TdtZj6puB1Ca1Uq09fX/KmjTdq1WP4mX2b3/F6L+x SWqg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=Ddz+jsGC; spf=pass (google.com: domain of vasileios.almpanis@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vasileios.almpanis@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-6baeae80ec2si19005833a12.242.2026.12.01.04.41.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 04:41:21 -0800 (PST) Received-SPF: pass (google.com: domain of vasileios.almpanis@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=Ddz+jsGC; spf=pass (google.com: domain of vasileios.almpanis@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vasileios.almpanis@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Message-Id:Content-Type:MIME-Version:Subject:Date :From; bh=qqCLJpa1t2+E4H1NbXI+G21lYsUIK1cWTeImCgitoDk=; b=Ddz+jsGC3CChAWypQJ6 0BAK4l7lCYD57kDKlXPrqlDYbfwuYXWb15ngInuVGqESUKOjzoDmRhF6MfZtAmP8O/KFj8F8rwkin /jcHDDj83AZomt9H7+zMzcYGH6ORKQvv6sN3MM6owF/gSihARPDCszdd+mTbua3zWY70VugMYJftx RlUDiqMUrAMmGHpIKqBxY821qYVwpxhmDZJZ0r8xOecDZYW55xrhr0xKLunaw9TtCiRYsgWL5HhrA GpjXizhmm/g1HT0JEriDiJGhC2v+N1idytywbMgikm0PiNiQIZm78/Dj5wc+QbRyJQ/Vwg5NgFPlO qBIpIlqcKdIXlRw==; Received: from [130.117.225.5] (helo=dev010.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xYNAK-004f8b-1e; Tue, 01 Dec 2026 13:41:11 +0100 From: Vasileios Almpanis Date: Tue, 01 Dec 2026 12:41:16 +0000 MIME-Version: 1.0 Message-Id: <20261201-pipe-resize-kvfree-v1-1-0a27f34709e0@virtuozzo.com> X-B4-Tracking: v=1; b=H4sIAGvADmsC/yWMwQ6CMBAFf4Xs2TW0qFR+xXiA+pDVBJtdJUbCv 1P1OJnMzGRQgVFTzKSYxOQxZnCbguLQjlewXDKTL/3B+dJxkgRWmHzA96lXgLu2DmGHUO3rI+U wKXp5/6YnGqJw2Ho6/4W9uhvi87ukZVkBItPV5H8AAAA= X-Change-ID: 20261201-pipe-resize-kvfree-ba7884e83579 To: Konstantin Khorenko X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796128880; l=2696; i=vasileios.almpanis@virtuozzo.com; s=20260812; h=from:subject:message-id; bh=7PkMP5RZN+mxn4d2IBJNYBFALC7ylxWUdEALIrbo5sc=; b=k0mpUscpnB38hKFlpZkUOhTHUw+yJjTg1xhJ3zchLobtS7TYfvYqK+IAKS/o+hPX41Q+3ceUH Vcn4qgSCIywDaM8cP+G6IExG1MJ9k+oCb+m3+xMfJq7spOkMYRBQN9s X-Developer-Key: i=vasileios.almpanis@virtuozzo.com; a=ed25519; pk=HhuHDXAcPva9A8zccWEMRsb36reu+y4IVbBjXKxNUjw= X-OZ-Fwd: true Cc: devel@openvz.org, Artem Bulgakov Subject: [Devel] [PATCH hci-8.2] fs/pipe: use kvfree() for the buffer arrays of a resized pipe X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org 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 Signed-off-by: Vasileios Almpanis --- 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