[<prev] [next>] [day] [month] [year] [list]
Message-ID: <41461336-2ba0-3f7a-7d37-d4a51bad57ff@gmail.com>
Date: Sun, 21 Mar 2021 16:31:59 +0100
From: "Michael Kerrisk (man-pages)" <mtk.manpages@...il.com>
To: Christian Brauner <christian.brauner@...ntu.com>,
Stephen Kitt <steve@....org>
Cc: mtk.manpages@...il.com, linux-man@...r.kernel.org,
Alejandro Colomar <alx.manpages@...il.com>,
Giuseppe Scrivano <gscrivan@...hat.com>,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH v6] close_range.2: new page documenting close_range(2)
Hello Stephen and Christian,
Late follow-up, I'm afraid...
On 1/29/21 11:00 AM, Christian Brauner wrote:
> On Thu, Jan 28, 2021 at 11:10:40PM +0100, Stephen Kitt wrote:
>> Hello Michael,
>>
>> On Thu, 28 Jan 2021 21:50:23 +0100, "Michael Kerrisk (man-pages)"
>> <mtk.manpages@...il.com> wrote:
>>> Thanks for your patch revision. I've merged it, and have
>>> done some light editing, but I still have a question:
>>>
>>> On 1/23/21 5:11 PM, Stephen Kitt wrote:
>>>
>>> [...]
>>>
>>>> +.SH ERRORS
>>>
>>>> +.TP
>>>> +.B EMFILE
>>>> +The per-process limit on the number of open file descriptors has been
>>>> reached +(see the description of
>>>> +.B RLIMIT_NOFILE
>>>> +in
>>>> +.BR getrlimit (2)).
>>>
>>> I think there was already a question about this error, but
>>> I still have a doubt.
>>>
>>> A glance at the code tells me that indeed EMFILE can occur.
>>> But how can the reason be because the limit on the number
>>> of open file descriptors has been reached? I mean: no new
>>> FDs are being opened, so how can we go over the limit. I think
>>> the cause of this error is something else, but what is it?
>>
>> Here’s how I understand the code that can lead to EMFILE:
>>
>> * in __close_range(), if CLOSE_RANGE_UNSHARE is set, call unshare_fd() with
>> CLONE_FILES to clone the fd table
>> * unshare_fd() calls dup_fd()
>> * dup_fd() allocates a new fdtable, and if the resulting fdtable ends up
>> being too small to hold the number of fds calculated by
>> sane_fdtable_size(), fails with EMFILE
>>
>> I suspect that, given that we’re starting with a valid fdtable, the only way
>> this can happen is if there’s a race with sysctl_nr_open being reduced.
>
> Yes, and sysctls are racy by nature.
Got it, I think. I changed the error text here to:
EMFILE The number of open file descriptors exceeds the limit spec‐
ified in /proc/sys/fs/nr_open (see proc(5)). This error
can occur in situations where that limit was lowered before
a call to close_range() where the CLOSE_RANGE_UNSHARE flag
is specified.
Thanks,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
Powered by blists - more mailing lists