[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250307052919.34542-2-kprateek.nayak@amd.com>
Date: Fri, 7 Mar 2025 05:29:16 +0000
From: K Prateek Nayak <kprateek.nayak@....com>
To: Linus Torvalds <torvalds@...ux-foundation.org>, Oleg Nesterov
<oleg@...hat.com>, Alexander Viro <viro@...iv.linux.org.uk>, "Christian
Brauner" <brauner@...nel.org>, <linux-fsdevel@...r.kernel.org>,
<linux-kernel@...r.kernel.org>
CC: Jan Kara <jack@...e.cz>, "Matthew Wilcox (Oracle)" <willy@...radead.org>,
Mateusz Guzik <mjguzik@...il.com>, Rasmus Villemoes <ravi@...vas.dk>,
"Gautham R. Shenoy" <gautham.shenoy@....com>, <Neeraj.Upadhyay@....com>,
<Ananth.narayan@....com>, Swapnil Sapkal <swapnil.sapkal@....com>, "K Prateek
Nayak" <kprateek.nayak@....com>
Subject: [PATCH v2 1/4] 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 related calculations where the pipe
will never appear full.
Suggested-by: Linus Torvalds <torvalds@...ux-foundation.org>
Signed-off-by: K Prateek Nayak <kprateek.nayak@....com>
---
Changelog:
RFC v1..v2:
o Use (pipe_index_t)-1u as the limit instead of BITS_PER_TYPE()
hackery. (Oleg)
o Added the "Suggested-by:" tag.
---
fs/pipe.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/pipe.c b/fs/pipe.c
index 4d0799e4e719..88e81f84e3ea 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -1271,6 +1271,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 > (pipe_index_t)-1u))
+ return -EINVAL;
+
bufs = kcalloc(nr_slots, sizeof(*bufs),
GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
if (unlikely(!bufs))
--
2.43.0
Powered by blists - more mailing lists