Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2053214imm; Thu, 24 May 2018 05:08:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpDCtQOxGnBzpz8wUbLzcypu+c7oAX+y6/zq0h4yvL3Y89hw5Mi0eEj5qX5KfPoiS9hSWtO X-Received: by 2002:a17:902:710f:: with SMTP id a15-v6mr7253938pll.171.1527163710586; Thu, 24 May 2018 05:08:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527163710; cv=none; d=google.com; s=arc-20160816; b=Cid28ytzzECAZIFkI+n8hlZf3KximmaNydr8TNGNG1IbavehCQKbvHGUr/zdJKe9Tb 9L/VpmJPQ/PtcLQErYfEPFedOeg5KPuKoiAVoZZMMJOwinT8kVPmc4dew7JW9NZJsnfA hM7AYB2Nrym77ULcexlu2i1J7yMJsGj3tRsIse76cXwPDU5qVzHKJvXtBDwczDFa9TJN owPR2YAuHXN4lpRqaQP8NKlnnUdJO/w8Z3V2WkEdefSI4K5BMwF1CgalKZMFH0rNeMAb 2j4OZQla1vtn68e7IUcB3k5EHKQI0vO3aZnWYVSfbVbflj6i1IOITdw/jAHJB8gZFSVc 1wZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=aBEgqUgZdyHvhJ0JYNE881PSSEMs62BUZcB10QVL9ek=; b=FTiatYBrn0LYqIFvYJHPl5+acxJJx8lw+v2pMypNDdOlr6iwTZxcmp90G+N75ZmuEL fzQ00oKiJ9iZJK3Awwv3FlfNuCLeX984ozlpFDxZSa55XTWmZX8qxlv/bdPLhxjDdDqK isNNjh+0gaADbs05MtjPXVkN52e1WMI5i+BY+SAvu6na07qs+Wp3gkByYjaXMkF4LZCb D9AHP6sDll7tONVVACnsvUXetE+4wJgY+fBt+ZUbhquBkLHz252CEN2ewiZbnCtmOFjW yeiUem1SkQn7LoJcm1l/ztn6flRsnijODPinwYfchjiuGjEkDd+f7exMtKUrwf6G7/26 m6lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MQDYny+u; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q17-v6si4617097pls.255.2018.05.24.05.08.15; Thu, 24 May 2018 05:08:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MQDYny+u; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1033221AbeEXMHX (ORCPT + 99 others); Thu, 24 May 2018 08:07:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:55262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966544AbeEXJnx (ORCPT ); Thu, 24 May 2018 05:43:53 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5282D2089F; Thu, 24 May 2018 09:43:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155032; bh=WSowi0Z+QA+Fm3zuEavlCQDPARqpHRHrvSMPGdIkXW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MQDYny+uUyA1D0iRvo6bgpdsMrSXMjc4duXGTBHJ36419n9jBomsQIG1t3Wkfvcoo WsIZ6wlNUoGuVfbzUspjyKBVBaNKqSrcLpdTJby1qJ5xKzQ+/6exMUrEQOYNS4tq5e +HtOWDEI1FSFAFF49v+3jp8ZU3KffycXgaLu9qEM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Kerrisk , Vegard Nossum , Willy Tarreau , socketpair@gmail.com, Tetsuo Handa , Jens Axboe , Al Viro , Andrew Morton , Linus Torvalds , Daniel Sangorrin Subject: [PATCH 4.4 30/92] pipe: cap initial pipe capacity according to pipe-max-size limit Date: Thu, 24 May 2018 11:38:07 +0200 Message-Id: <20180524093201.812425243@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093159.286472249@linuxfoundation.org> References: <20180524093159.286472249@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael Kerrisk (man-pages) commit 086e774a57fba4695f14383c0818994c0b31da7c upstream. This is a patch that provides behavior that is more consistent, and probably less surprising to users. I consider the change optional, and welcome opinions about whether it should be applied. By default, pipes are created with a capacity of 64 kiB. However, /proc/sys/fs/pipe-max-size may be set smaller than this value. In this scenario, an unprivileged user could thus create a pipe whose initial capacity exceeds the limit. Therefore, it seems logical to cap the initial pipe capacity according to the value of pipe-max-size. The test program shown earlier in this patch series can be used to demonstrate the effect of the change brought about with this patch: # cat /proc/sys/fs/pipe-max-size 1048576 # sudo -u mtk ./test_F_SETPIPE_SZ 1 Initial pipe capacity: 65536 # echo 10000 > /proc/sys/fs/pipe-max-size # cat /proc/sys/fs/pipe-max-size 16384 # sudo -u mtk ./test_F_SETPIPE_SZ 1 Initial pipe capacity: 16384 # ./test_F_SETPIPE_SZ 1 Initial pipe capacity: 65536 The last two executions of 'test_F_SETPIPE_SZ' show that pipe-max-size caps the initial allocation for a new pipe for unprivileged users, but not for privileged users. Link: http://lkml.kernel.org/r/31dc7064-2a17-9c5b-1df1-4e3012ee992c@gmail.com Signed-off-by: Michael Kerrisk Reviewed-by: Vegard Nossum Cc: Willy Tarreau Cc: Cc: Tetsuo Handa Cc: Jens Axboe Cc: Al Viro Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Daniel Sangorrin Signed-off-by: Greg Kroah-Hartman --- fs/pipe.c | 3 +++ 1 file changed, 3 insertions(+) --- a/fs/pipe.c +++ b/fs/pipe.c @@ -616,6 +616,9 @@ struct pipe_inode_info *alloc_pipe_info( unsigned long pipe_bufs = PIPE_DEF_BUFFERS; struct user_struct *user = get_current_user(); + if (pipe_bufs * PAGE_SIZE > pipe_max_size && !capable(CAP_SYS_RESOURCE)) + pipe_bufs = pipe_max_size >> PAGE_SHIFT; + if (!too_many_pipe_buffers_hard(user)) { if (too_many_pipe_buffers_soft(user)) pipe_bufs = 1;