[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250306113924.20004-2-kprateek.nayak@amd.com>
Date: Thu, 6 Mar 2025 11:39:22 +0000
From: K Prateek Nayak <kprateek.nayak@....com>
To: Linus Torvalds <torvalds@...ux-foundation.org>, Oleg Nesterov
<oleg@...hat.com>, Miklos Szeredi <miklos@...redi.hu>, Alexander Viro
<viro@...iv.linux.org.uk>, Christian Brauner <brauner@...nel.org>, "Andrew
Morton" <akpm@...ux-foundation.org>, Hugh Dickins <hughd@...gle.com>,
<linux-fsdevel@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linux-mm@...ck.org>
CC: Jan Kara <jack@...e.cz>, "Matthew Wilcox (Oracle)" <willy@...radead.org>,
Mateusz Guzik <mjguzik@...il.com>, "Gautham R. Shenoy"
<gautham.shenoy@....com>, Rasmus Villemoes <ravi@...vas.dk>,
<Neeraj.Upadhyay@....com>, <Ananth.narayan@....com>, Swapnil Sapkal
<swapnil.sapkal@....com>, K Prateek Nayak <kprateek.nayak@....com>
Subject: [RFC PATCH 1/3] fs/pipe: Limit the slots in pipe_resize_ring()
Limit the number of slots in pipe_resize_ring() to the maximum value
representable by pipe->{head,tail}. Values beyond the max limit can
lead to incorrect pipe_occupancy() calculations where the pipe will
never appear full.
Since nr_slots is always a power of 2 and the maximum size of
pipe_index_t is 32 bits, BIT() is sufficient to represent the maximum
value possible for nr_slots.
Signed-off-by: K Prateek Nayak <kprateek.nayak@....com>
---
fs/pipe.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/pipe.c b/fs/pipe.c
index e8e6698f3698..3ca3103e1de7 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -1272,6 +1272,10 @@ int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots)
struct pipe_buffer *bufs;
unsigned int head, tail, mask, n;
+ /* nr_slots larger than limits of pipe->{head,tail} */
+ if (unlikely(nr_slots > BIT(BITS_PER_TYPE(pipe_index_t) - 1)))
+ return -EINVAL;
+
bufs = kcalloc(nr_slots, sizeof(*bufs),
GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
if (unlikely(!bufs))
base-commit: 848e076317446f9c663771ddec142d7c2eb4cb43
--
2.43.0
Powered by blists - more mailing lists