public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: [PATCH] fhandler_pipe: add sanity limit to handle loops
       [not found]                               ` <c7664703-0ec2-388f-64e3-8c46d4590b3e@cornell.edu>
@ 2022-01-13 10:56                                 ` Takashi Yano
  2022-01-13 14:39                                   ` Ken Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Takashi Yano @ 2022-01-13 10:56 UTC (permalink / raw)
  To: cygwin

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>

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] fhandler_pipe: add sanity limit to handle loops
  2022-01-13 10:56                                 ` [PATCH] fhandler_pipe: add sanity limit to handle loops Takashi Yano
@ 2022-01-13 14:39                                   ` Ken Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Ken Brown @ 2022-01-13 14:39 UTC (permalink / raw)
  To: cygwin

On 1/13/2022 5:56 AM, Takashi Yano wrote:
> Ken Brown wrote:
>> 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?

I'm not sure.  I only mentioned it because I saw that that's what Process Hacker 
did, but still in a retry loop as you said.

I suspect it doesn't make a lot of difference in practice, since we call the 
function once and then cache the value.  Do whatever you think is best.

Thanks.

Ken

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-13 14:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [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                                 ` [PATCH] fhandler_pipe: add sanity limit to handle loops Takashi Yano
2022-01-13 14:39                                   ` Ken Brown

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).