public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin@cygwin.com
Subject: Re: [PATCH] fhandler_pipe: add sanity limit to handle loops
Date: Thu, 13 Jan 2022 19:56:38 +0900	[thread overview]
Message-ID: <20220113195638.d64430e6b03159c70721fb45@nifty.ne.jp> (raw)
In-Reply-To: <c7664703-0ec2-388f-64e3-8c46d4590b3e@cornell.edu>

I am sorry for being absent for a long time.

On Sun, 26 Dec 2021 10:09:57 -0500
Ken Brown wrote:
> On 12/25/2021 11:56 PM, Jeremy Drake wrote:
> > I set up a windows server 2022 VM last night and went nuts stressing
> > pacman/GPGME.  I was able to reproduce the issue there:
> > 
> > status = 0x00000000, phi->NumberOfHandles = 8261392, n_handle = 256
> > [#####----------------------------------]  14%
> > assertion "phi->NumberOfHandles <= n_handle" failed: file
> > "../../.././winsup/cygwin/fhandler_pipe.cc", line 1281, function: void*
> > fhandler_pipe::get_query_hdl_per_process(WCHAR*, OBJECT_NAME_INFORMATION*)
> > 
> > So it is not something inherent in the x86_64-on-ARM64 emulation but can
> > happen on native x86_64 also.
> 
> A Google search led me to something that might explain what's going on.  Look at 
> the function PhEnumHandlesEx2 starting at line 5713 in
> 
>   https://github.com/processhacker/processhacker/blob/master/phlib/native.c#L5152

Thank you very much for finding this,

> Two interesting things:
> 
> 1. For some processes, NtQueryInformationProcess(ProcessHandleInformation) can 
> return STATUS_SUCCESS with invalid handle information.  See the comment starting 
> at line 5754, where it is shown how to detect this.

and also applying the fix.

> 2. You can use the ReturnLength parameter of NtQueryInformationProcess to see 
> how big a buffer is needed.  This might be more efficient than repeatedly 
> doubling the buffer size.

Even if ReturnLength is used, the first NtQueryInformationProcess()
call and the second NtQueryInformationProcess() call will not be
done in atomic, so retrying is still necessary. However, it may be
more efficient as you mentioned.

The similar is true also for NtQuerySystemInformation().

Do you still think it is better to use ReturnLength rather than
doubling the buffer?

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

       reply	other threads:[~2022-01-13 10:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <alpine.BSO.2.21.2112231503400.11760@resin.csoft.net>
     [not found] ` <f97bba17-16ab-d7be-01f6-1c057fb5f1a5@cornell.edu>
     [not found]   ` <alpine.BSO.2.21.2112231623490.11760@resin.csoft.net>
     [not found]     ` <c5115e9b-6475-d30e-04d3-cb84cfa92b3a@cornell.edu>
     [not found]       ` <alpine.BSO.2.21.2112241136160.11760@resin.csoft.net>
     [not found]         ` <622d3ac6-fa5d-965c-52da-db7a4463fffd@cornell.edu>
     [not found]           ` <alpine.BSO.2.21.2112241638280.11760@resin.csoft.net>
     [not found]             ` <20211225121902.54b82f1bb0d4f958d34a8bb7@nifty.ne.jp>
     [not found]               ` <alpine.BSO.2.21.2112241945060.11760@resin.csoft.net>
     [not found]                 ` <20211225131242.adef568db53d561a6b134612@nifty.ne.jp>
     [not found]                   ` <alpine.BSO.2.21.2112242101520.11760@resin.csoft.net>
     [not found]                     ` <20211226021010.a2b2ad28f12df9ffb25b6584@nifty.ne.jp>
     [not found]                       ` <alpine.BSO.2.21.2112251111580.11760@resin.csoft.net>
     [not found]                         ` <alpine.BSO.2.21.2112251457480.11760@resin.csoft.net>
     [not found]                           ` <8172019c-e048-4fe2-79c9-0b3262057d3e@cornell.edu>
     [not found]                             ` <alpine.BSO.2.21.2112252054310.11760@resin.csoft.net>
     [not found]                               ` <c7664703-0ec2-388f-64e3-8c46d4590b3e@cornell.edu>
2022-01-13 10:56                                 ` Takashi Yano [this message]
2022-01-13 14:39                                   ` Ken Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220113195638.d64430e6b03159c70721fb45@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).