Skip to content

Commit cf3d0c5

Browse files
kudureranganathbrauner
authored andcommitted
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@linux-foundation.org> Signed-off-by: K Prateek Nayak <kprateek.nayak@amd.com> Link: https://lore.kernel.org/r/20250307052919.34542-2-kprateek.nayak@amd.com Reviewed-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 00a7d39 commit cf3d0c5

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

fs/pipe.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,10 @@ int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots)
12711271
struct pipe_buffer *bufs;
12721272
unsigned int head, tail, mask, n;
12731273

1274+
/* nr_slots larger than limits of pipe->{head,tail} */
1275+
if (unlikely(nr_slots > (pipe_index_t)-1u))
1276+
return -EINVAL;
1277+
12741278
bufs = kcalloc(nr_slots, sizeof(*bufs),
12751279
GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
12761280
if (unlikely(!bufs))

0 commit comments

Comments
 (0)