From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755576AbcHSUvh (ORCPT ); Fri, 19 Aug 2016 16:51:37 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35814 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754127AbcHSUvf (ORCPT ); Fri, 19 Aug 2016 16:51:35 -0400 Subject: Re: [PATCH 4/8] pipe: fix limit checking in pipe_set_size() To: Willy Tarreau References: <67ce15aa-cf43-0c89-d079-2d966177c56d@gmail.com> <7f0732a9-6172-e92d-7c5b-473b769fe37e@gmail.com> <20160819054818.GH17944@1wt.eu> Cc: mtk.manpages@gmail.com, Andrew Morton , Vegard Nossum , socketpair@gmail.com, Tetsuo Handa , Jens Axboe , Al Viro , linux-api@vger.kernel.org, linux-kernel@vger.kernel.org From: "Michael Kerrisk (man-pages)" Message-ID: Date: Sat, 20 Aug 2016 08:51:26 +1200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20160819054818.GH17944@1wt.eu> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/19/2016 05:48 PM, Willy Tarreau wrote: > Hi Michael, > > Since you're changing this code, it's probably worth swapping the size > check and capable() below to save a function call in the normal path : > > On Fri, Aug 19, 2016 at 05:25:35PM +1200, Michael Kerrisk (man-pages) wrote: >> + if (nr_pages > pipe->buffers) { >> + if (!capable(CAP_SYS_RESOURCE) && size > pipe_max_size) { > > => if (size > pipe_max_size && !capable(CAP_SYS_RESOURCE)) { > >> + ret = -EPERM; >> + goto out_revert_acct; >> + } 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_revert_acct; >> + } >> + } > (...) Thanks, Willy. Fixed for the next iteration. (And I made the same fix made also in the 8/8 patch). Cheers, Michael -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/