Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1464198

Re: [PATCH 2/2] pipe: make pipe user buffer limit checks more precise

Path csiph.com!feeder.erje.net!1.eu.feeder.erje.net!news2.arglkargh.de!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod
From Vegard Nossum <vegard.nossum@oracle.com>
Newsgroups linux.kernel
Subject Re: [PATCH 2/2] pipe: make pipe user buffer limit checks more precise
Date Wed, 17 Aug 2016 00:10:01 +0200
Message-ID <s6UIx-r4-5@gated-at.bofh.it> (permalink)
References <s6Kzw-2mV-21@gated-at.bofh.it> <s6Kzw-2mV-31@gated-at.bofh.it> <s6LlU-2U7-25@gated-at.bofh.it> <s6T9M-7MR-29@gated-at.bofh.it>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0
MIME-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Source-IP userv0022.oracle.com [156.151.31.74]
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 37
Organization linux.* mail to news gateway
X-Original-Cc Willy Tarreau <w@1wt.eu>, socketpair@gmail.com, Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>, Jens Axboe <axboe@fb.com>, Al Viro <viro@zeniv.linux.org.uk>, stable@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org
X-Original-Date Wed, 17 Aug 2016 00:00:23 +0200
X-Original-Message-ID <57B38CF7.5080803@oracle.com>
X-Original-References <86c85cff-7fee-cded-386a-e1d518573dda@gmail.com> <db82480c-7956-b89d-1f4e-ba2c94f4067e@gmail.com> <57B301FE.9090108@oracle.com> <1532b6c4-c618-348c-d36a-9679d5d5a1b4@gmail.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1464198

Show key headers only | View raw


On 08/16/2016 10:21 PM, Michael Kerrisk (man-pages) wrote:
>>> @@ -1132,8 +1136,8 @@ long pipe_fcntl(struct file *file, unsigned int cmd, unsigned long arg)
>>>    			if (!capable(CAP_SYS_RESOURCE) && size > pipe_max_size) {
>>>    				ret = -EPERM;
>>>    				goto out;
>>> -			} else if ((too_many_pipe_buffers_hard(pipe->user) ||
>>> -				too_many_pipe_buffers_soft(pipe->user)) &&
>>> +			} else if ((too_many_pipe_buffers_hard(pipe->user, nr_pages) ||
>>> +				too_many_pipe_buffers_soft(pipe->user, nr_pages)) &&
>>>    				!capable(CAP_SYS_RESOURCE) &&
>>>    				!capable(CAP_SYS_ADMIN)) {
>>>    				ret = -EPERM;
>>>
>>
>> Isn't there also a race where two or more concurrent pipe()/fnctl()
>> calls can together push us over the limits before the accounting is done?
>
> I guess there is!
>
>> I think there really ought to be a check after doing the accounting if
>> we really want to be meticulous here.
>
> Let me confirm what I understand from your comment: because of the race,
> then a user could subvert the checks and allocate an arbitrary amount
> of kernel memory for pipes. Right?
>
> I'm not sure what you mean by "a check after doing the accounting". Is not the
> only solution here some kind of lock around the check+accounting steps?

Instead of doing atomic_long_read() in the check + atomic_long_add() for
accounting we could do a single speculative atomic_long_add_return() and
then if it goes above the limit we can lower it again with atomic_sub()
when aborting the operation (if it doesn't go above the limit we don't
need to do anything).


Vegard

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/2] pipe: check limits only when increasing pipe capacity "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2016-08-16 13:20 +0200
  [PATCH 2/2] pipe: make pipe user buffer limit checks more precise "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2016-08-16 13:20 +0200
    Re: [PATCH 2/2] pipe: make pipe user buffer limit checks more precise Vegard Nossum <vegard.nossum@oracle.com> - 2016-08-16 14:10 +0200
      Re: [PATCH 2/2] pipe: make pipe user buffer limit checks more precise "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2016-08-16 22:30 +0200
        Re: [PATCH 2/2] pipe: make pipe user buffer limit checks more precise Vegard Nossum <vegard.nossum@oracle.com> - 2016-08-17 00:10 +0200
          Re: [PATCH 2/2] pipe: make pipe user buffer limit checks more precise "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2016-08-17 10:10 +0200
            Re: [PATCH 2/2] pipe: make pipe user buffer limit checks more precise Vegard Nossum <vegard.nossum@oracle.com> - 2016-08-17 21:40 +0200
              Re: [PATCH 2/2] pipe: make pipe user buffer limit checks more precise "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2016-08-17 21:50 +0200
                Re: [PATCH 2/2] pipe: make pipe user buffer limit checks more precise Vegard Nossum <vegard.nossum@oracle.com> - 2016-08-17 22:00 +0200
    Re: [PATCH 2/2] pipe: make pipe user buffer limit checks more precise "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2016-08-19 07:20 +0200
  Re: [PATCH 1/2] pipe: check limits only when increasing pipe capacity Vegard Nossum <vegard.nossum@oracle.com> - 2016-08-16 14:00 +0200
  Re: [PATCH 1/2] pipe: check limits only when increasing pipe capacity "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> - 2016-08-19 07:20 +0200

csiph-web