From patchwork Mon Jan 8 05:35:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10149051 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0500F601BE for ; Mon, 8 Jan 2018 05:40:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBE44287A6 for ; Mon, 8 Jan 2018 05:40:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEDE2287BE; Mon, 8 Jan 2018 05:40:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C6B8287A6 for ; Mon, 8 Jan 2018 05:40:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755681AbeAHFkA (ORCPT ); Mon, 8 Jan 2018 00:40:00 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:42133 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755522AbeAHFiz (ORCPT ); Mon, 8 Jan 2018 00:38:55 -0500 Received: by mail-pg0-f67.google.com with SMTP id q67so4878192pga.9; Sun, 07 Jan 2018 21:38:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Jw+OmNF5J1VoQ3nxuby7Vl/DGRDUrBhDxDpMU1y33AU=; b=V/jm+w2OvbdFJtXeTBTfxXZt9ltICpI9lVa0LwebpD8l0I/aqkBAwoh1WQIJEYZH4G JzSDqYIt8Pn7BwCxfuBQj8TtwnE6OJv9KIouwB/zIZ6y9qRlkqGCOomMrsE5Aw7ZfzVf j21H/lQE2Oa5Fif3wwXd6fLilHLraKdQ5Xpgkdjz6Q1ZdHrt2ltVzkwm3qdekycSD3WP WqFmSWwaxSr6UpxKKtnJnt1r6+e2fQTqiX6tCohJzd2JOU7f9nznruWcs9s8hre5fqzI LD5GeNK1826/fNaWsZ9eYfGewYz78rYJfRM9CMEtBwSd5OF0GDvXkgu3QaTILCw9FaOY Dk1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Jw+OmNF5J1VoQ3nxuby7Vl/DGRDUrBhDxDpMU1y33AU=; b=Zn6FvDdm2zPNDa4LM811C+VE5tBcO2CCchw4ai77/Dc2ityfgdBLzuwepLfH8xTkQG +0EHuil/PfPgV9BOvc8G+jx9dlOK09e7i7elF2F7XI1vB4BBbbX7oqoViPVu/gzpnHop Zth6Gqj2l6sbw1wlmfRuSFG0K6hj7X+JYX3sldmWQFqFc8wfBz3dgn/2z9ia7u3zKU4Y G25jfdStOATEbDt0rjr2MvabbbVIt+y8gdXOpCn9y+0A3+FmyfXPTNxrqT3VxZU53ENb 3Up8mcWaDrBWYLkCky0iifkQNbgJ4bhlJ8muFYlXbqvKTLj78Cf7AQAE/oQ9KFBIx0RX AxFg== X-Gm-Message-State: AKGB3mJ8BYlh1loez+t6wrSF5yhxYNflgCRllh/jLBxpMswzHsUjC8+f lSpZ+jJ6AxQKDOhVvgGv2dwMa8Re X-Google-Smtp-Source: ACJfBovv0eNdeqil30OWGryzEWJn/wHkFetmfFI6zKib7bikuuwA/qXjuz1vbEUAlbdHN2WamUIXLw== X-Received: by 10.101.80.72 with SMTP id k8mr8372124pgo.6.1515389934544; Sun, 07 Jan 2018 21:38:54 -0800 (PST) Received: from zzz.localdomain (c-67-185-97-198.hsd1.wa.comcast.net. [67.185.97.198]) by smtp.gmail.com with ESMTPSA id w84sm26611743pfk.16.2018.01.07.21.38.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Jan 2018 21:38:54 -0800 (PST) From: Eric Biggers To: linux-fsdevel@vger.kernel.org Cc: Alexander Viro , Joe Lawrence , Michael Kerrisk , Willy Tarreau , Mikulas Patocka , "Luis R . Rodriguez" , Kees Cook , linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH 5/7] pipe: reject F_SETPIPE_SZ with size over UINT_MAX Date: Sun, 7 Jan 2018 21:35:40 -0800 Message-Id: <20180108053542.6472-6-ebiggers3@gmail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180108053542.6472-1-ebiggers3@gmail.com> References: <20180108053542.6472-1-ebiggers3@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers A pipe's size is represented as an 'unsigned int'. As expected, writing a value greater than UINT_MAX to /proc/sys/fs/pipe-max-size fails with EINVAL. However, the F_SETPIPE_SZ fcntl silently truncates such values to 32 bits, rather than failing with EINVAL as expected. (It *does* fail with EINVAL for values above (1 << 31) but <= UINT_MAX.) Fix this by moving the check against UINT_MAX into round_pipe_size() which is called in both cases. Signed-off-by: Eric Biggers Acked-by: Kees Cook --- fs/pipe.c | 5 ++++- include/linux/pipe_fs_i.h | 2 +- kernel/sysctl.c | 3 --- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/pipe.c b/fs/pipe.c index 9f20e7128578..f1ee1e599495 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -1020,10 +1020,13 @@ const struct file_operations pipefifo_fops = { * Currently we rely on the pipe array holding a power-of-2 number * of pages. Returns 0 on error. */ -unsigned int round_pipe_size(unsigned int size) +unsigned int round_pipe_size(unsigned long size) { unsigned long nr_pages; + if (size > UINT_MAX) + return 0; + /* Minimum pipe size, as required by POSIX */ if (size < PAGE_SIZE) size = PAGE_SIZE; diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h index 5028bd4b2c96..5a3bb3b7c9ad 100644 --- a/include/linux/pipe_fs_i.h +++ b/include/linux/pipe_fs_i.h @@ -190,6 +190,6 @@ long pipe_fcntl(struct file *, unsigned int, unsigned long arg); struct pipe_inode_info *get_pipe_info(struct file *file); int create_pipe_files(struct file **, int); -unsigned int round_pipe_size(unsigned int size); +unsigned int round_pipe_size(unsigned long size); #endif diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 33e2f0f02000..31fe10fd745f 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c @@ -2630,9 +2630,6 @@ static int do_proc_dopipe_max_size_conv(unsigned long *lvalp, if (write) { unsigned int val; - if (*lvalp > UINT_MAX) - return -EINVAL; - val = round_pipe_size(*lvalp); if (val == 0) return -EINVAL;