From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753402AbcHPLzj (ORCPT ); Tue, 16 Aug 2016 07:55:39 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:20654 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752240AbcHPLzh (ORCPT ); Tue, 16 Aug 2016 07:55:37 -0400 Subject: Re: [PATCH 1/2] pipe: check limits only when increasing pipe capacity To: "Michael Kerrisk (man-pages)" , Andrew Morton References: <86c85cff-7fee-cded-386a-e1d518573dda@gmail.com> Cc: Willy Tarreau , socketpair@gmail.com, Tetsuo Handa , Jens Axboe , Al Viro , stable@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org From: Vegard Nossum Message-ID: <57B2FF15.503@oracle.com> Date: Tue, 16 Aug 2016 13:55:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: <86c85cff-7fee-cded-386a-e1d518573dda@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/16/2016 01:10 PM, Michael Kerrisk (man-pages) wrote: > When changing a pipe's capacity with fcntl(F_SETPIPE_SZ), various > limits defined by /proc/sys/fs/pipe-* files are checked to see > if unprivileged users are exceeding limits on memory consumption. > [...] > --- > fs/pipe.c | 25 +++++++++++++++++-------- > 1 file changed, 17 insertions(+), 8 deletions(-) > > diff --git a/fs/pipe.c b/fs/pipe.c > index 4ebe6b2..a98ebca 100644 > --- a/fs/pipe.c > +++ b/fs/pipe.c > @@ -1122,14 +1122,23 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg) > if (!nr_pages) > goto out; > > - if (!capable(CAP_SYS_RESOURCE) && size > pipe_max_size) { > - ret = -EPERM; > - goto out; > - } else if ((too_many_pipe_buffers_hard(pipe->user) || > - too_many_pipe_buffers_soft(pipe->user)) && > - !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN)) { > - ret = -EPERM; > - goto out; > + /* > + * If trying to increase the pipe capacity, check that an > + * unprivileged user is not trying to exceed various limits. > + * (Decreasing the pipe capacity is always permitted, even > + * if the user is currently over a limit.) > + */ > + if (nr_pages > pipe->buffers) { > + if (!capable(CAP_SYS_RESOURCE) && size > pipe_max_size) { > + ret = -EPERM; > + goto out; > + } else if ((too_many_pipe_buffers_hard(pipe->user) || > + too_many_pipe_buffers_soft(pipe->user)) && > + !capable(CAP_SYS_RESOURCE) && > + !capable(CAP_SYS_ADMIN)) { > + ret = -EPERM; > + goto out; > + } > } > ret = pipe_set_size(pipe, nr_pages); > break; > FWIW: Reviewed-by: Vegard Nossum Vegard