Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2060828imm; Thu, 24 May 2018 05:14:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqq3iacxWwTjBRewsDJc0ha2LjsenefCdpvnAAsgUbM+32rbIV/l4PeDgmomgou6WuoYWus X-Received: by 2002:a17:902:a714:: with SMTP id w20-v6mr6993208plq.374.1527164098183; Thu, 24 May 2018 05:14:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527164098; cv=none; d=google.com; s=arc-20160816; b=SvgkJR0D0GFs0MC/pARueXDkdwlsWVZ+229FujdEKGmyIcQeEYdhWuoMs3vV7FEbAA 0PTZGN4VSHZxkim4A5eYmmJ3NAAxf1kbrRrX6Cv16cRfrpEud/4pUifCQy8PCX905YI1 dvOU7SxD+OA9OUpMg19/cKt5paiHHLt8pYU79b+l/WbnDc7OgAdyuCVfYHnpivtK/D1i wHEqt0ISBV/hclfgahAU2qhXSdSpm02+diSkEqBmT2/cKijMPQKIePhdX5AEpd8r4F5N KuJSoFTYWWjqZKjpPrtIhcasCyuBVC9NVK9cHW8ZIqGsS58363IS9D+5AUAc802B2Pzf hVXw== 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=SGXg0co0H7QqggR687K0l5YC5l29kU0c0kZPAkPU3cs=; b=Nw2GXC1kuxzj2SiOR6WF9Pj74v1qYLqaOlzJbf2EWrFfCOVhX4GFh82HTkzsNY1t0h Vhx+uPtFoee3vdOZ9KNBH8aKNsIXyN13ACOv88SZ2GaRa2NkTdik3l1WsW5DgGhdrnqc Ufq+Sj2oeqlLyl4uv/80PgJKKZyUyBsGa1V0CgVwFfZh663/441Ih1NBapHhg+GLa50m l802Or2RwYpFpVl9ZmfAqrBdxA/YNufw4ekdFz54DwnIpODTip+QFaEGJLNKMzT0vBqv zDKsr8eDuynWSNb26G0e76l5FY83PA0x+TvRNF3U2g3UxXdaQ26QekqoJnUQDvN8iHJh Qj5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZJHjmeap; 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 o8-v6si4583054pgf.116.2018.05.24.05.14.41; Thu, 24 May 2018 05:14:58 -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=ZJHjmeap; 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 S969816AbeEXMN7 (ORCPT + 99 others); Thu, 24 May 2018 08:13:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:54214 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966060AbeEXJme (ORCPT ); Thu, 24 May 2018 05:42:34 -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 2FA5E2087E; Thu, 24 May 2018 09:42:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527154953; bh=DTkDFg59AdRvFTlvHdthJpI/xLUwu8Idrrf6LXKNEYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZJHjmeapF4q2jpsyJLrFTgdcNBK5fRmgaLSMfDXxLS9qUEHLCefk+Ys8g7u8nZgTs E3ofZdJHUbM8M5oYVnI2nZ9qz63MItq+oOF5h0gg8lbgnJnz7eeFPvnM/QgKvrF2HQ gaE16SEM1Xh7W3uj28AdWspV6EKS7rISMGlUsGJk= 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 3.18 21/45] pipe: cap initial pipe capacity according to pipe-max-size limit Date: Thu, 24 May 2018 11:38:29 +0200 Message-Id: <20180524093123.356107231@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093120.599252450@linuxfoundation.org> References: <20180524093120.599252450@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 3.18-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 @@ -618,6 +618,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;