From 736e2986763ba58fca1d7f27403cf0a11d479e2b Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Fri, 16 Dec 2011 15:50:05 +1100 Subject: [PATCH] pipe: fail cleanly when root tries F_SETPIPE_SZ with big size When a user with the CAP_SYS_RESOURCE cap tries to F_SETPIPE_SZ a pipe with size bigger than kmalloc() can alloc it spits out an ugly warning: [ 3.651552] ------------[ cut here ]------------ [ 3.652644] WARNING: at mm/page_alloc.c:2095 __alloc_pages_nodemask+0x5d3/0x7a0() [ 3.654313] Pid: 733, comm: a.out Not tainted 3.2.0-rc1+ #4 [ 3.655568] Call Trace: [ 3.656207] [] ? __alloc_pages_nodemask+0x5d3/0x7a0 [ 3.657698] [] warn_slowpath_common+0x75/0xb0 [ 3.659018] [] warn_slowpath_null+0x15/0x20 [ 3.660468] [] __alloc_pages_nodemask+0x5d3/0x7a0 [ 3.665725] [] ? handle_pte_fault+0xf2/0x200 [ 3.667032] [] ? _raw_spin_unlock+0x9/0x40 [ 3.668283] [] ? __pte_alloc+0x96/0x150 [ 3.669354] [] ? get_empty_filp+0x91/0x160 [ 3.670238] [] ? handle_mm_fault+0x1a4/0x360 [ 3.671139] [] __get_free_pages+0x12/0x50 [ 3.671972] [] __kmalloc+0x12b/0x150 [ 3.672782] [] pipe_set_size+0x75/0x120 [ 3.673681] [] pipe_fcntl+0xf8/0x140 [ 3.674833] [] do_fcntl+0x2d4/0x410 [ 3.675960] [] ? do_pipe_flags+0xb2/0x100 [ 3.677218] [] sys_fcntl+0x66/0xa0 [ 3.678037] [] system_call_fastpath+0x16/0x1b [ 3.679008] ---[ end trace 432f702e6db7b5ee ]--- Instead, make kcalloc() handle the overflow case and fail quietly. Signed-off-by: Sasha Levin Cc: Alexander Viro Acked-by: Pekka Enberg Signed-off-by: Andrew Morton --- fs/pipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/pipe.c b/fs/pipe.c index 2c59dfa838ff..406e8be94cec 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -1137,7 +1137,7 @@ static long pipe_set_size(struct pipe_inode_info *pipe, unsigned long nr_pages) if (nr_pages < pipe->nrbufs) return -EBUSY; - bufs = kcalloc(nr_pages, sizeof(struct pipe_buffer), GFP_KERNEL); + bufs = kcalloc(nr_pages, sizeof(struct pipe_buffer), GFP_KERNEL | __GFP_NOWARN); if (unlikely(!bufs)) return -ENOMEM; -- 2.39.5