[tor-bugs] #24857 [Core Tor/Tor]: Tor uses 100% CPU when accessing the cache directory on Windows

Tor Bug Tracker & Wiki blackhole at torproject.org
Mon Aug 27 07:06:01 UTC 2018


#24857: Tor uses 100% CPU when accessing the cache directory on Windows
-------------------------------------------------+-------------------------
 Reporter:  Eugene646                            |          Owner:  (none)
     Type:  defect                               |         Status:
                                                 |  needs_revision
 Priority:  Medium                               |      Milestone:  Tor:
                                                 |  unspecified
Component:  Core Tor/Tor                         |        Version:  Tor:
                                                 |  0.3.1.9
 Severity:  Normal                               |     Resolution:
 Keywords:  cpu, windows, linux, performance,    |  Actual Points:
  regression, 033-triage-20180326,               |
  033-removed-20180326, 034-deferred-20180602,   |
  035-removed-20180711, 032-backport-maybe, 033  |
  -backport-maybe, 034-backport                  |
Parent ID:  #25500                               |         Points:
 Reviewer:                                       |        Sponsor:
-------------------------------------------------+-------------------------

Comment (by mestriga):

 > What happens if tor tries to access the memory mapped by the file after
 it's gone?

 I tested it and the memory access works. But I had missed a step in the
 test, and the unlinking is actually delayed if the file is mapped. This is
 handled in the code below by linking the file somewhere else.

 1. Open a handle to the file with the FILE_FLAG_DELETE_ON_CLOSE flag.
 Request DELETE access and allow FILE_SHARE_DELETE to ensure that step 3
 will succeed.

 {{{
 file_handle = fileCreateFile(
     tfilename,
     DELETE,
     FILE_SHARE_DELETE,
     NULL,
     OPEN_ALWAYS,
     FILE_FLAG_DELETE_ON_CLOSE,
     0);

 }}}
 2. Check that the handle is valid, fail if it is not (due to a sharing
 violation or if the file does not exist):

 {{{
 if (file_handle == INVALID_HANDLE_VALUE)
    goto win_err;

 }}}
 3. Put the file somewhere else in the same volume (maybe inside the cache
 directory itself, with a name that the cache can be programmed to ignore).

 {{{
 if (!MoveFile(tfilename, newfilename))
    goto win_err;
 }}}
 4.Close the handle:

 {{{
 CloseHandle(file_handle);

 }}}
 5. If the file is not mapped (or has some other handle to it open), it is
 gone. Otherwise, it will be gone automatically when the last handle to it
 is closed.

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/24857#comment:39>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list