Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2463416imm; Thu, 7 Jun 2018 11:01:20 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL6KqPbxHuq9d/QxPiV17YjR0AcuzVREj82kJmgcnGL970dY3TgHflS+/F5OqZ36h82O9A5 X-Received: by 2002:a17:902:900a:: with SMTP id a10-v6mr3049911plp.41.1528394480140; Thu, 07 Jun 2018 11:01:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528394480; cv=none; d=google.com; s=arc-20160816; b=zQ0XPA0yyGMRp0qC6iV/R0BqVBdrc7vbbGBvGPYGWgMvd0nmHDmAZwigr84aIRHj9n Qc5LTYT+ceZE584NtHxID5cVsyuAhm+G+ivO23lGX5GF2JPhS6Y9aNN7VctSDKjOxhdD z2VelsqiX+doZQJNOMh3nKPdrmAwc6nLJ9G4DmURGxGsr1L+N9BSBgqfs7rCUeweYWzT 3wr/BEelThpmWGtDXwr1CnTmCRvNK4k7CHc87Km1oFbSD3Nz5K80kozvJTsYZLztePtJ WiK8jg5rRMJrCStdKH3E49bBhr/dFuvCXwBhPWjRiid5gXrsx+sFsX1WmyWVIciX/yuR RWyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=lbKyzzpZewVli5xj8nlxwknyne1JR57Xp0qlN1Xla0Q=; b=QXkHLArfbSbX0XD45Qtv+jeN46SFPs2/ivjvhP+mDRgyS/xBFBWwlKv4PWB2Nvwpsa s2fTXAK7JcKzd1Qz7bjFXxYJCF9lW/o62oIF9VgpGRczYCUxur9B3mZSI+yuklzgrhg4 iLItCfwcVttl6u7Chfie+5uzXVyq1nXlhVDqniWWR0gYoUG8B+fDU7b7GKQeujupwRfY 4cVcB9lg58Cew7yrFkEIabI50wfzjlTpjF4i1G+xd9KgXKxEmgfeVdxMzHOCpgA7AqNf t3OlAx+xw6mOpHe8yqdfiNG5iH2dPhjXfZIvw7BvEpeFsY3RzUGP0+UC5CX61Lvphxm/ ExDw== ARC-Authentication-Results: i=1; mx.google.com; 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 d16-v6si33793686pll.197.2018.06.07.11.01.05; Thu, 07 Jun 2018 11:01:20 -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; 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 S935326AbeFGO4K (ORCPT + 99 others); Thu, 7 Jun 2018 10:56:10 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41079 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935497AbeFGOzv (ORCPT ); Thu, 7 Jun 2018 10:55:51 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbe-0005hK-E3; Thu, 07 Jun 2018 15:09:38 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb6-00031q-LH; Thu, 07 Jun 2018 15:09:04 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Joe Lawrence" , "Alexander Viro" , "Willy Tarreau" , "Mikulas Patocka" , "Eric Biggers" , "Kees Cook" , "Michael Kerrisk" , "Luis R . Rodriguez" , "Linus Torvalds" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 215/410] pipe: simplify round_pipe_size() In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Eric Biggers commit c4fed5a91fadc8a277b1eda474317b501651dd3e upstream. round_pipe_size() calculates the number of pages the requested size corresponds to, then rounds the page count up to the next power of 2. However, it also rounds everything < PAGE_SIZE up to PAGE_SIZE. Therefore, there's no need to actually translate the size into a page count; we just need to round the size up to the next power of 2. We do need to verify the size isn't greater than (1 << 31), since on 32-bit systems roundup_pow_of_two() would be undefined in that case. But that can just be combined with the UINT_MAX check which we need anyway now. Finally, update pipe_set_size() to not redundantly check the return value of round_pipe_size() for the "invalid size" case twice. Link: http://lkml.kernel.org/r/20180111052902.14409-7-ebiggers3@gmail.com Signed-off-by: Eric Biggers Acked-by: Kees Cook Acked-by: Joe Lawrence Cc: Alexander Viro Cc: "Luis R . Rodriguez" Cc: Michael Kerrisk Cc: Mikulas Patocka Cc: Willy Tarreau Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Ben Hutchings --- fs/pipe.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) --- a/fs/pipe.c +++ b/fs/pipe.c @@ -1010,20 +1010,14 @@ const struct file_operations pipefifo_fo */ unsigned int round_pipe_size(unsigned long size) { - unsigned long nr_pages; - - if (size > UINT_MAX) + if (size > (1U << 31)) return 0; /* Minimum pipe size, as required by POSIX */ if (size < PAGE_SIZE) - size = PAGE_SIZE; - - nr_pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; - if (nr_pages == 0) - return 0; + return PAGE_SIZE; - return roundup_pow_of_two(nr_pages) << PAGE_SHIFT; + return roundup_pow_of_two(size); } /* @@ -1038,8 +1032,6 @@ static long pipe_set_size(struct pipe_in long ret = 0; size = round_pipe_size(arg); - if (size == 0) - return -EINVAL; nr_pages = size >> PAGE_SHIFT; if (!nr_pages)