Tor Bug Tracker & Wiki: Ticket #9701: Prevent TorBrowser from creating clipboardcache turds https://trac.torproject.org/projects/tor/ticket/9701 <p> Firefox dumps these wonderful UTF-16 files right into /tmp if you happen to highlight and copy a significantly large amount of text, this does not seem that ideal for security reasons. </p> en-us Tor Bug Tracker & Wiki /images/tor-logo.png https://trac.torproject.org/projects/tor/ticket/9701 Trac 1.0.1 arma Sun, 08 Sep 2013 19:09:16 GMT priority, type changed; keywords set; version deleted https://trac.torproject.org/projects/tor/ticket/9701#comment:1 https://trac.torproject.org/projects/tor/ticket/9701#comment:1 <ul> <li><strong>keywords</strong> <em>tbb-disk-leak</em> added </li> <li><strong>priority</strong> changed from <em>minor</em> to <em>normal</em> </li> <li><strong>version</strong> <em>Tor: 0.2.3.25</em> deleted </li> <li><strong>type</strong> changed from <em>enhancement</em> to <em>defect</em> </li> </ul> Ticket mikeperry Fri, 24 Jan 2014 06:59:24 GMT keywords changed https://trac.torproject.org/projects/tor/ticket/9701#comment:2 https://trac.torproject.org/projects/tor/ticket/9701#comment:2 <ul> <li><strong>keywords</strong> <em>interview</em> added </li> </ul> Ticket gk Wed, 26 Mar 2014 09:44:23 GMT cc set https://trac.torproject.org/projects/tor/ticket/9701#comment:3 https://trac.torproject.org/projects/tor/ticket/9701#comment:3 <ul> <li><strong>cc</strong> <em>gk</em> added </li> </ul> Ticket michael Mon, 12 May 2014 08:57:07 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:4 https://trac.torproject.org/projects/tor/ticket/9701#comment:4 <p> Amending this ticket to state that neither cutting nor copying is particularly relevant. While cut/copy does trigger additional turds to be written, a simple text selection (with no cut/copy at all) causes the symptom in question. </p> Ticket michael Mon, 12 May 2014 08:57:51 GMT cc changed https://trac.torproject.org/projects/tor/ticket/9701#comment:5 https://trac.torproject.org/projects/tor/ticket/9701#comment:5 <ul> <li><strong>cc</strong> <em>michael</em> added </li> </ul> Ticket michael Wed, 14 May 2014 23:39:27 GMT attachment set https://trac.torproject.org/projects/tor/ticket/9701 https://trac.torproject.org/projects/tor/ticket/9701 <ul> <li><strong>attachment</strong> set to <em>msvb-9701.diff</em> </li> </ul> <p> Proposed solution removing affected code region. </p> Ticket michael Wed, 14 May 2014 23:41:53 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:6 https://trac.torproject.org/projects/tor/ticket/9701#comment:6 <p> This bug affects all platforms served by the Tor Browser Bundle (Linux (IA32|AMD64), OSX IA32, Win32 IA32.) Although the degree is different, in that a simple selection &gt;1Mo only causes temp file leakage in the Linux builds. </p> Ticket michael Wed, 14 May 2014 23:43:45 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:7 https://trac.torproject.org/projects/tor/ticket/9701#comment:7 <p> DEFENSE OF SIMPLISTIC SOLUTION (IN ATTACHMENT 'msvb-9701.diff') TO THIS PROBLEM </p> <p> Q1) Why didn't you make the same change in other parts of tor-browser? A1) Because there is exactly one place where the data in question is </p> <blockquote> <p> written to a disk cache, and it is in the SetData method of the nsTransferable interface. </p> </blockquote> <p> Q2) Won't other blocks try to read from the disk cache instead of mData? A2) No, since they test mData for existence before testing for a cache file. </p> <p> Q3) Won't the mData memory buffer be exhausted with excessive clipboard data? </p> <blockquote> <p> In other words isn't the proposed solution vulnerable to a buffer overflow? </p> </blockquote> <p> A3) Only a reference to the actual data is copied avoiding a buffer overflow. A3 Oberservation 1) While it's not well understood how the underlying browser </p> <blockquote> <p> logic handles memory problems when populating aData, any such testing falls into a larger scope of DOM/Dragdrop/ and other more generic storage questions (and bugs.) </p> </blockquote> <p> A3 Oberservation 2) It would seem from the patched code that a valid case </p> <blockquote> <p> for caching clipboard data to disk exists. Unfortunately, no documentation exists to support this. Worse, the upstream source code repository doesn't reflect any earlier file history to gain insight. </p> </blockquote> <p> Q4) You mean neither writing nor reading of data can lead to a memory overflow? A4) Yes, the data is in aData from the beginning. Regardless of whether the </p> <blockquote> <p> data is later stored to a disk cache or not, it was present in memory before this solution changed any storage allocation logic. </p> </blockquote> <p> A4 Oberservation 3) Investigation is needed to better understand why the </p> <blockquote> <p> upstream author chose to disk cache in the first place. </p> </blockquote> <p> Q5) What are the security implications of this bug report? A5) This bug report (wether applying the proposed solution or not) </p> <blockquote> <p> implies memory conditions which could lead to a buffer overflow and root compromise of a system running the tor-browser software. Note that this potential (probably very low) exists equally whether the proposed solution is applied (tor-browser is patched) or not, that is the proposed solution carries no added risk. </p> </blockquote> <p> Q6) Has the tor-browser been tested thoroughly for the named buffer overflow? A6) Security analysis of tor-browser without applying the proposed solution </p> <blockquote> <p> falls outside the scope of this bug report, so it hasn't been carried out. Furthermore, the proposed solution carries no added security risk. </p> </blockquote> <p> Q7) Where did the value kLargeDatasetSize come from? A7) Nobody knows, since the very first revisions of nsTransferable.cpp </p> <blockquote> <p> and nsTransferable.h contain the logic and constant value. </p> </blockquote> <p> Q8) What about implementing memory chunking for large data sets? A8) This would require alternative storage, probably defeating the purpose </p> <blockquote> <p> of disk avoidance by design. It would also open a large can of worms due to Firefox's portable nature as the paste interface of underlying platforms behaves differently, requiring several chunking implementations. Lastly, it is out of the scope of the corresponding bug report. </p> </blockquote> <p> Q9) What is the mathematical proof behind the proposed solution defense? A9) Assuming that all web pages (DOM) are stored entirely in virtual memory, </p> <blockquote> <p> and that any web page consumes at most 1/2 available virtual memory, and that selected or copied data consumes at most 100% DOM representation, ...the proposed solution carries no side effects while correcting the otherwise violated premise of disk avoidance by design. </p> </blockquote> <p> Q10) What documentation was referred to while engineering the proposed solution? A10 <a class="ext-link" href="https://developer.mozilla.org/en-US/docs/Using_the_Clipboard/"><span class="icon">​</span>https://developer.mozilla.org/en-US/docs/Using_the_Clipboard/</a> </p> <blockquote> <p> <a class="ext-link" href="https://wiki.mozilla.org/Firefox/Projects/ClipboardAPI"><span class="icon">​</span>https://wiki.mozilla.org/Firefox/Projects/ClipboardAPI</a> <a class="ext-link" href="https://bugzilla.mozilla.org/show_bug.cgi?id=407983"><span class="icon">​</span>https://bugzilla.mozilla.org/show_bug.cgi?id=407983</a> <a class="ext-link" href="http://kb.mozillazine.org/Clipboard_not_working"><span class="icon">​</span>http://kb.mozillazine.org/Clipboard_not_working</a> <a class="ext-link" href="http://kb.mozillazine.org/Memory_Leak"><span class="icon">​</span>http://kb.mozillazine.org/Memory_Leak</a> </p> </blockquote> <p> Q11) In which source context was the proposed solution engineered? A11) After cloning tor-browser and checking out tor-browser-24.5.0esr-1-build4 </p> <p> Q12) How was the proposed solution built? A12) By carrying out the command 'cd tor-browser &amp;&amp; make -f client.mk' </p> <blockquote> <p> After gaining confidence by QA, TBB packages were built for all variants. </p> </blockquote> <p> Q13) What was tested to assure the quality (QA) of this change? A13) The binary tor-browser/obj-x86_64-unknown-linux-gnu/dist/bin/firefox was </p> <blockquote> <p> launched using code in tor-browser/obj-x86_64-unknown-linux-gnu/toolkit/library/libxul.so After that, similar launches were carried out on Mac OSX 10.9 AMD64 and Windows 8.1 AMD64 platforms. The launches were observed for symptoms of the clipboard turd bug and found to be free of this problem once the proposed solution was applied. All platforms are affected by this bug. </p> </blockquote> <p> Q14) Were only tor-browser builds tested for the platforms in question? A14) No, the Tor Browser Bundle was created for all platforms (32-bit EN </p> <blockquote> <p> variants and 64-bit Linux EN) and tested as well. </p> </blockquote> <p> Q15) What was not tested to assure the quality of this change? A15) Unit tests were not constructed using the ClipboardHelper and </p> <blockquote> <p> Clipboard XPCOM interfaces in order to fully guarantee correctness. This can optionally be carried out on request by TPI. </p> </blockquote> <p> A15 Oberservation 4) Does a tor-browser or Firefox test harness exist? </p> Ticket michael Wed, 14 May 2014 23:45:03 GMT status changed https://trac.torproject.org/projects/tor/ticket/9701#comment:8 https://trac.torproject.org/projects/tor/ticket/9701#comment:8 <ul> <li><strong>status</strong> changed from <em>new</em> to <em>needs_review</em> </li> </ul> Ticket gk Thu, 15 May 2014 06:48:27 GMT keywords changed https://trac.torproject.org/projects/tor/ticket/9701#comment:9 https://trac.torproject.org/projects/tor/ticket/9701#comment:9 <ul> <li><strong>keywords</strong> <em>GeorgKoppen201405</em> added </li> </ul> Ticket mcs Thu, 15 May 2014 19:03:46 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:10 https://trac.torproject.org/projects/tor/ticket/9701#comment:10 <p> Here is the commit log (CVS revision 1.23) that shows when the concept of writing to disk first landed in the Mozilla code: </p> <p> <a class="ext-link" href="http://bonsai.mozilla.org/cvslog.cgi?file=mozilla/widget/src/xpwidgets/nsTransferable.cpp&amp;rev=1.23"><span class="icon">​</span>http://bonsai.mozilla.org/cvslog.cgi?file=mozilla/widget/src/xpwidgets/nsTransferable.cpp&amp;rev=1.23</a> </p> <p> Unfortunately, this is ancient history and there is no reference to a bug number. And the check in comment does not say why they changed things to write clipboard data to disk rather than keep it in memory. My best guess is that they just wanted to ensure that memory usage stayed as low as possible. </p> <p> I think your proposed fix is OK. It might be better to add a preference or a compile-time method to disable the WriteCache() code (Mozilla would be more like to accept a patch that uses such an approach). For example, the kLargeDatasetSize value could be retrieved from a preference and a zero value could mean "never write to disk." </p> Ticket michael Fri, 16 May 2014 16:48:22 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:11 https://trac.torproject.org/projects/tor/ticket/9701#comment:11 <p> DataStruct::WriteCache and nsIOutputStream::Write don't deallocate the memory in aData. If you look closely, nsMemory::Free(buff) only frees the 'buff' memory that was deep copied from aData by nsPrimitiveHelpers::CreateDataFromPrimitive. </p> <p> Before proposing a preference, it might be wise to do a real world test to confirm this. If confirmed it makes no sense producing the cache disk files under any conditions (even the stock Firefox) whatsoever. </p> Ticket mikeperry Thu, 22 May 2014 16:06:47 GMT keywords changed https://trac.torproject.org/projects/tor/ticket/9701#comment:12 https://trac.torproject.org/projects/tor/ticket/9701#comment:12 <ul> <li><strong>keywords</strong> <em>MikePerry201405R</em> added </li> </ul> Ticket gk Fri, 23 May 2014 13:23:34 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:13 https://trac.torproject.org/projects/tor/ticket/9701#comment:13 <p> Replying to <a class="closed" href="https://trac.torproject.org/projects/tor/ticket/9701#comment:10" title="Comment 10 for Ticket #9701">mcs</a>: </p> <blockquote class="citation"> <p> I think your proposed fix is OK. It might be better to add a preference or a compile-time method to disable the WriteCache() code (Mozilla would be more like to accept a patch that uses such an approach). For example, the kLargeDatasetSize value could be retrieved from a preference and a zero value could mean "never write to disk." </p> </blockquote> <p> That would be one approach. But I'd be in favor of another one: binding it to the state of the Private Browser Mode: if we are in PBM we don't write to disk otherwise we do as I think the current behavior is just a violation of the Private Browsing Mode paradigm (at least as we would like to have it). </p> <p> I tested the patch on all platforms and it is working fine. </p> Ticket mcs Fri, 23 May 2014 14:40:57 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:14 https://trac.torproject.org/projects/tor/ticket/9701#comment:14 <p> Replying to <a class="closed" href="https://trac.torproject.org/projects/tor/ticket/9701#comment:13" title="Comment 13 for Ticket #9701">gk</a>: </p> <blockquote class="citation"> <p> That would be one approach. But I'd be in favor of another one: binding it to the state of the Private Browser Mode: if we are in PBM we don't write to disk otherwise we do as I think the current behavior is just a violation of the Private Browsing Mode paradigm (at least as we would like to have it). </p> </blockquote> <p> Tying this to PBM sounds perfect to me. </p> Ticket mikeperry Thu, 05 Jun 2014 10:14:00 GMT keywords changed https://trac.torproject.org/projects/tor/ticket/9701#comment:15 https://trac.torproject.org/projects/tor/ticket/9701#comment:15 <ul> <li><strong>keywords</strong> <em>MikePerry201406R</em> added; <em>MikePerry201405R</em> removed </li> </ul> <p> So should we just go with this hack for now then? It seems like yes, while we wait to see what Mozilla says about the deeper issue? </p> Ticket michael Fri, 06 Jun 2014 05:54:54 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:16 https://trac.torproject.org/projects/tor/ticket/9701#comment:16 <p> Replying to <a class="closed" href="https://trac.torproject.org/projects/tor/ticket/9701#comment:11" title="Comment 11 for Ticket #9701">michael</a>: </p> <blockquote class="citation"> <p> DataStruct::WriteCache and nsIOutputStream::Write don't deallocate the memory in aData. If you look closely, nsMemory::Free(buff) only frees the 'buff' memory that was deep copied from aData by nsPrimitiveHelpers::CreateDataFromPrimitive. </p> <p> Before proposing a preference, it might be wise to do a real world test to confirm this. If confirmed it makes no sense producing the cache disk files under any conditions (even the stock Firefox) whatsoever. </p> </blockquote> <p> Unfortunately, a limited <a class="missing changeset" title="No default repository defined">[1]</a> black box test has confirmed the opposite of the hypothesis based on aData block code analysis. Basically, a prestine TBB 3.6.1 (which creates clipboardcache files) consumes no new memory when selecting &gt;1Mo text: </p> <pre class="wiki">pmap `pgrep firefox` &gt;pmap1.txt echo 'Select text now...' pmap `pgrep firefox` &gt;pmap2.txt diff pmap1.txt pmap2.txt </pre><p> Testing a modified (with msvb-9701.diff) tor-browser build reveals additional memory use: </p> <pre class="wiki">diff pmap3.txt pmap4.txt 4a5 &gt; 00007f2962700000 131072K rw--- [ anon ] 649c650 &lt; total 771608K --- &gt; total 902680K </pre> Ticket michael Fri, 06 Jun 2014 06:00:06 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:17 https://trac.torproject.org/projects/tor/ticket/9701#comment:17 <p> Replying to <a class="closed" href="https://trac.torproject.org/projects/tor/ticket/9701#comment:15" title="Comment 15 for Ticket #9701">mikeperry</a>: </p> <blockquote class="citation"> <p> So should we just go with this hack for now then? It seems like yes, while we wait to see what Mozilla says about the deeper issue? </p> </blockquote> <p> The test (above) was quick and dirty, but suggests increased memory consumption. Mozilla will probably not accept a change that increases footprint by 30 Mo when selecting large text blocks. </p> <p> I'll implement Georg's suggestion of changing this logic only when in Private Browser Mode. </p> Ticket erinn Fri, 25 Jul 2014 17:30:29 GMT keywords changed https://trac.torproject.org/projects/tor/ticket/9701#comment:18 https://trac.torproject.org/projects/tor/ticket/9701#comment:18 <ul> <li><strong>keywords</strong> <em>tbb-firefox-patch</em> added </li> </ul> Ticket erinn Fri, 25 Jul 2014 17:58:55 GMT component changed https://trac.torproject.org/projects/tor/ticket/9701#comment:19 https://trac.torproject.org/projects/tor/ticket/9701#comment:19 <ul> <li><strong>component</strong> changed from <em>Firefox Patch Issues</em> to <em>Tor Browser</em> </li> </ul> Ticket mikeperry Tue, 05 Aug 2014 03:49:47 GMT status, keywords changed; resolution set https://trac.torproject.org/projects/tor/ticket/9701#comment:20 https://trac.torproject.org/projects/tor/ticket/9701#comment:20 <ul> <li><strong>status</strong> changed from <em>needs_review</em> to <em>closed</em> </li> <li><strong>keywords</strong> <em>MikePerry201406R</em> removed </li> <li><strong>resolution</strong> set to <em>fixed</em> </li> </ul> <p> Hrmm. I am going to call this closed. We can decide how we want to handle the Private Browsing Mode isolation when we review our patches for upstreaming after the FF31 rebase. </p> Ticket michael Tue, 06 Jan 2015 21:10:24 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:21 https://trac.torproject.org/projects/tor/ticket/9701#comment:21 <p> The <a href="https://trac.torproject.org/projects/tor/attachment/ticket/9701/msvb9701-283f7c6.patch">most recent patch</a> improves on this solution by implementing the idea (from TBB meetings) to <strong>disable turds conditionally</strong> according to privacy preference. </p> Ticket michael Tue, 06 Jan 2015 21:11:47 GMT status, keywords changed; resolution deleted https://trac.torproject.org/projects/tor/ticket/9701#comment:22 https://trac.torproject.org/projects/tor/ticket/9701#comment:22 <ul> <li><strong>status</strong> changed from <em>closed</em> to <em>reopened</em> </li> <li><strong>keywords</strong> <em>TorBrowserTeam201501</em> added </li> <li><strong>resolution</strong> <em>fixed</em> deleted </li> </ul> Ticket michael Tue, 06 Jan 2015 21:12:24 GMT keywords, status changed https://trac.torproject.org/projects/tor/ticket/9701#comment:23 https://trac.torproject.org/projects/tor/ticket/9701#comment:23 <ul> <li><strong>keywords</strong> <em>TorBrowserTeam201501R</em> added; <em>TorBrowserTeam201501</em> removed </li> <li><strong>status</strong> changed from <em>reopened</em> to <em>needs_review</em> </li> </ul> Ticket gk Wed, 07 Jan 2015 08:35:57 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:24 https://trac.torproject.org/projects/tor/ticket/9701#comment:24 <p> What speaks against the solution in <a class="closed" href="https://trac.torproject.org/projects/tor/ticket/9701#comment:13" title="Comment 13 for Ticket #9701">comment:13</a>? Isolating possible (cache) identifiers to the URL bar domain is one thing but the clipboard cache is of a different kind I think. Moreover, I still think this is a real bug in Firefox's PBM (seen as a do-not-store-things-to-disk-mode) and should get fixed there directly. </p> Ticket michael Mon, 12 Jan 2015 19:44:39 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:25 https://trac.torproject.org/projects/tor/ticket/9701#comment:25 <p> Replying to <a class="closed" href="https://trac.torproject.org/projects/tor/ticket/9701#comment:24" title="Comment 24 for Ticket #9701">gk</a>: </p> <blockquote class="citation"> <p> What speaks against the solution in <a class="closed" href="https://trac.torproject.org/projects/tor/ticket/9701#comment:13" title="Comment 13 for Ticket #9701">comment:13</a>? </p> </blockquote> <p> If you mean, why did I implement the condition according to <em>privacy.thirdparty.isolate</em> rather than <em>NS_UsePrivateBrowsing(aChannel)</em>, it's because the nsTransferable code block dealing with disk caching has no chance at knowing in which channel it's operating. So it can't know if Private Browsing Mode is active. <br /> </p> <blockquote class="citation"> <p> Isolating possible (cache) identifiers to the URL bar domain is one thing but the clipboard cache is of a different kind I think. </p> </blockquote> <p> I see your point and agree. Lets figure out: </p> <p> 1) How hard it would be to implement the channel driven PBM approach. 2) If we want to go this distance at giving something so obvious (for Tor) a condition. <br /> </p> <blockquote class="citation"> <p> Moreover, I still think this is a real bug in Firefox's PBM (seen as a do-not-store-things-to-disk-mode) and should get fixed there directly. </p> </blockquote> <p> I'm not sure, since Firefox in PBM doesn't have as strong a requirement as Tor to not store things to disk. Mozilla would probably rather support old hardware by <strong>reducing memory consumption.</strong> </p> <p> Is there some specification that you're referring to where Mozilla emphasizes disk avoidance? </p> Ticket gk Tue, 13 Jan 2015 09:39:50 GMT keywords, status changed https://trac.torproject.org/projects/tor/ticket/9701#comment:26 https://trac.torproject.org/projects/tor/ticket/9701#comment:26 <ul> <li><strong>keywords</strong> <em>TorBrowserTeam201501</em> added; <em>GeorgKoppen201405</em> <em>TorBrowserTeam201501R</em> removed </li> <li><strong>status</strong> changed from <em>needs_review</em> to <em>needs_revision</em> </li> </ul> Ticket michael Thu, 15 Jan 2015 01:32:14 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:27 https://trac.torproject.org/projects/tor/ticket/9701#comment:27 <p> <tt>void DataStruct::SetData ( nsISupports* aData, uint32_t aDataLen )</tt> </p> <p> After new trials like: </p> <pre class="wiki">nsCOMPtr&lt;nsIChannel&gt; aChannel(do_QueryInterface(aData, &amp;rv)); nsCOMPtr&lt;nsIDOMWindow&gt; aWin(do_QueryInterface(aData, &amp;rv)); nsCOMPtr&lt;nsIDOMChromeWindow&gt; aChromeWin(do_QueryInterface(aData, &amp;rv)); nsCOMPtr&lt;nsILoadContext&gt; aLoadContext(do_QueryInterface(aData, &amp;rv)); </pre><p> ...in every case rv == NS_NOINTERFACE, with the exception of: </p> <p> <tt>nsCOMPtr&lt;nsISupportsString&gt; aSuppStr(do_QueryInterface(aData, &amp;rv));</tt> </p> <p> So the recent suggestions to 'get a top level chrome window' or to 'reverse engineer the JavaScript PrivateBrowsingUtils module' seem misguided. Maybe Firefox runtime exposes undocumented window/document/channel globals? </p> Ticket michael Thu, 15 Jan 2015 01:33:08 GMT status changed https://trac.torproject.org/projects/tor/ticket/9701#comment:28 https://trac.torproject.org/projects/tor/ticket/9701#comment:28 <ul> <li><strong>status</strong> changed from <em>needs_revision</em> to <em>needs_information</em> </li> </ul> Ticket michael Thu, 15 Jan 2015 15:18:29 GMT keywords, status changed https://trac.torproject.org/projects/tor/ticket/9701#comment:29 https://trac.torproject.org/projects/tor/ticket/9701#comment:29 <ul> <li><strong>keywords</strong> <em>TorBrowserTeam201501R</em> added; <em>TorBrowserTeam201501</em> removed </li> <li><strong>status</strong> changed from <em>needs_information</em> to <em>needs_review</em> </li> </ul> <p> Regarding <a href="https://trac.torproject.org/projects/tor/attachment/ticket/9701/msvb9701-283f7c6.patch">msvb9701-283f7c6.patch</a>, preemptive consideration of the question is: </p> <p> <strong>Won't this break binary compatibility</strong> causing dependent code to crash at runtime? </p> <p> Answer: Yes, but <strong>only if the dependent code uses the new method <sup>1</sup></strong> while calling into the old (not overloaded) vtable. Or possibly NS_ERROR_OBJECT_IS_IMMUTABLE is returned from dependent code. </p> <p> <sup>1</sup> Assuming XPCOM/GCC works like classic COM/VC++. </p> <p> Furthermore, the interface signature (struct DataStruct) in question has no corresponding IDL entry, so it hopefully won't be called from foreign (non Mozilla) components at all? </p> Ticket mcs Thu, 15 Jan 2015 15:39:43 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:30 https://trac.torproject.org/projects/tor/ticket/9701#comment:30 <p> Kathy and I took a quick look at msvb9701-283f7c6.patch. I am glad you found a way to make this approach work! </p> <p> I don't think we have to worry about non-Mozilla components calling DataStruct::SetData(); it looks like that method is only called from within nsTransferable.cpp (I am not sure why it is not declared inside nsTransferable.cpp instead of in the header). Is that your conclusion as well? </p> <p> I would feel better if the old DataStruct::SetData() call that does not accept a aIsPrivBrowsing parameter was removed entirely (to avoid any chance that the wrong call could be made). In fact, there is another call later in nsTransferable::SetTransferData() that should be modified to use the new method as well. </p> <p> One nit: You should be able to just access the mPrivateData member directly instead of bothering with a call to GetIsPrivateData(). </p> Ticket michael Thu, 15 Jan 2015 20:29:02 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:31 https://trac.torproject.org/projects/tor/ticket/9701#comment:31 <p> Replying to <a class="closed" href="https://trac.torproject.org/projects/tor/ticket/9701#comment:30" title="Comment 30 for Ticket #9701">mcs</a>: </p> <blockquote class="citation"> <p> I don't think we have to worry about non-Mozilla components calling DataStruct::SetData(); it looks like that method is only called from within nsTransferable.cpp [...] Is that your conclusion as well? </p> </blockquote> <p> Yes, SetData is not defined in IDL and only nsTransferable objects call DataStruct::SetData(). So Arthur and I think it's okay to change the arguments by adding a <strong>PBM flag.</strong> </p> <p> Furthermore, with no IDL entries, there's no XPCOM transport to get interfaces, so my attempt to avoid foreign code crashing by <strong>adding an overloaded method</strong> might not help that much. <br /> </p> <blockquote class="citation"> <p> (I am not sure why it is not declared inside nsTransferable.cpp instead of in the header). </p> </blockquote> <p> ...or why <strong>DataStruct</strong> is a independent class, rather than a private member of <strong>nsTransferable?</strong> <br /> </p> <blockquote class="citation"> <p> I would feel better if the old DataStruct::SetData() call that does not accept a aIsPrivBrowsing parameter was removed entirely (to avoid any chance that the wrong call could be made). </p> </blockquote> <p> Assuming the overloaded method is a NOOP there's no tradeoff to worry about, so thanks for the tip. </p> <p> I've deleted the original DataStruct::SetData() definition and implementation not including the bool PBM flag. <del>DataStruct::SetData ( nsISupports*, uint32_t);</del> DataStruct::SetData ( nsISupports*, uint32_t, bool); <br /> </p> <blockquote class="citation"> <p> In fact, there is another call later in nsTransferable::SetTransferData() that should be modified to use the new method as well. </p> </blockquote> <p> Opla, good catch. Now the second (of two) call has the relevant PBM aware logic as well. <br /> </p> <blockquote class="citation"> <p> One nit: You should be able to just access the mPrivateData member directly instead of bothering with a call to GetIsPrivateData(). </p> </blockquote> <p> I used the accessor so that the mPrivateData type could be internally changed in a future FF release (typical raison d'etre for accessors,) but either way is fine. If we have a convention of direct member manipulation I'll change the logic to match. </p> <p> Do we/should I? </p> Ticket mcs Thu, 15 Jan 2015 22:06:15 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:32 https://trac.torproject.org/projects/tor/ticket/9701#comment:32 <p> Replying to <a class="closed" href="https://trac.torproject.org/projects/tor/ticket/9701#comment:31" title="Comment 31 for Ticket #9701">michael</a>: </p> <blockquote class="citation"> <p> I used the accessor so that the mPrivateData type could be internally changed in a future FF release (typical raison d'etre for accessors,) but either way is fine. If we have a convention of direct member manipulation I'll change the logic to match. </p> <p> Do we/should I? </p> </blockquote> <p> I do not know that we have a policy, but in this case things are simple enough (and you are in the same class), so direct access seems OK to me. And it will simplify the patch a little since you can avoid some error checking that is not needed. </p> Ticket mcs Fri, 16 Jan 2015 15:38:46 GMT cc changed https://trac.torproject.org/projects/tor/ticket/9701#comment:33 https://trac.torproject.org/projects/tor/ticket/9701#comment:33 <ul> <li><strong>cc</strong> <em>mcs</em> <em>brade</em> added </li> </ul> Ticket mcs Fri, 16 Jan 2015 16:10:44 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:34 https://trac.torproject.org/projects/tor/ticket/9701#comment:34 <p> The revised patch looks OK. My only nit is to avoid checks like boolVar == false. Please change the line that uses that kind of test to: </p> <blockquote> <p> if ((aDataLen &gt; kLargeDatasetSize) &amp;&amp; !aIsPrivBrowsing) { </p> </blockquote> <p> (I think a simple ! test is more consistent with code elsewhere in nsTransferable.cpp and with other Mozilla code). </p> <p> Have you tested the fix? I am not sure how difficult it would be to add automated tests to ensure that the fix does not break in the future, but Mozilla will want them. That could be addressed in a separate bug though. </p> Ticket michael Fri, 16 Jan 2015 18:42:11 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:35 https://trac.torproject.org/projects/tor/ticket/9701#comment:35 <p> Replying to <a class="closed" href="https://trac.torproject.org/projects/tor/ticket/9701#comment:34" title="Comment 34 for Ticket #9701">mcs</a>: </p> <blockquote class="citation"> <p> ... boolVar == false. Please change the line that uses that kind of test to: </p> <blockquote> <p> if ((aDataLen &gt; kLargeDatasetSize) &amp;&amp; !aIsPrivBrowsing) { </p> </blockquote> </blockquote> <p> Good idea, I like the more consistent syntax better as well. It's in the latest patch post. <br /> </p> <blockquote class="citation"> <p> Have you tested the fix? </p> </blockquote> <p> <br /> </p> <h3 id="Blackbox">Blackbox</h3> <p> I've high level tested <a class="missing changeset" title="No default repository defined">[1]</a><a class="missing changeset" title="No default repository defined">[2]</a> without covering all code paths, like when unregistered flavor handling causes recursion or a format converter to manipulate the flavor (see around line 410.) I can nevertheless try to force all code paths on request. There might be no natural (or possible?) use case for some conditions however, like selecting millions of <em>kLargeDatasetSize</em> bytes from a <strong>about: URI.</strong> </p> <p> <a class="missing changeset" title="No default repository defined">[1]</a> PBM on, <a class="ext-link" href="http://www.gutenberg.org/cache/epub/345/pg345.txt"><span class="icon">​</span>navigate a large doc</a>, select Ctrl-A, ls $TMPDIR/clipboardcache* <a class="missing changeset" title="No default repository defined">[2]</a> PBM off, <a class="ext-link" href="http://www.gutenberg.org/cache/epub/345/pg345.txt"><span class="icon">​</span>navigage a large doc</a>, select Ctrl-A, ls $TMPDIR/clipboardcache* </p> <h3 id="Controlflow">Control flow</h3> <p> On another note, DataStruct::GetData() is left unmodified as my tests conclude that that logic can only read from disk if no selection exists in memory. </p> <h3 id="Implicittests">Implicit tests</h3> <p> An unconditional state of disk avoidance has been in Tor Browser releases <a class="missing changeset" title="No default repository defined">[3]</a> since tor-browser-24.5.0esr-1. </p> <p> <a class="missing changeset" title="No default repository defined">[3]</a> <a class="ext-link" href="https://gitweb.torproject.org/tor-browser.git/commit/?h=tor-browser-24.5.0esr-1&amp;id=8088761c"><span class="icon">​</span>https://gitweb.torproject.org/tor-browser.git/commit/?h=tor-browser-24.5.0esr-1&amp;id=8088761c</a> <br /> </p> <blockquote class="citation"> <p> I am not sure how difficult it would be to add automated tests to ensure that the fix does not break in the future, but Mozilla will want them. </p> </blockquote> <p> Good idea regardless of Mozilla, like a xpcshell test for regression. <br /> </p> <blockquote class="citation"> <p> That could be addressed in a separate bug though. </p> </blockquote> <p> Yes, better for clarity and code reuse. The new requirement is described in <a class="closed ticket" href="https://trac.torproject.org/projects/tor/ticket/14255" title="task: Conduct periodic regression tests of nsTransferable selection caching (closed: wontfix)">#14255</a>. </p> Ticket mcs Mon, 19 Jan 2015 21:15:56 GMT keywords, status changed; resolution set https://trac.torproject.org/projects/tor/ticket/9701#comment:36 https://trac.torproject.org/projects/tor/ticket/9701#comment:36 <ul> <li><strong>keywords</strong> <em>TorBrowserTeam201501</em> added; <em>TorBrowserTeam201501R</em> removed </li> <li><strong>status</strong> changed from <em>needs_review</em> to <em>closed</em> </li> <li><strong>resolution</strong> set to <em>fixed</em> </li> </ul> <p> The revised fix has been merged into tor-browser-31.4.0esr-4.5-1. </p> <p> Revert old fix: <a class="ext-link" href="https://gitweb.torproject.org/tor-browser.git/commit/?h=tor-browser-31.4.0esr-4.5-1&amp;id=ba4eca38fdad352c564719ff49aaa8c87e8a8ded"><span class="icon">​</span>https://gitweb.torproject.org/tor-browser.git/commit/?h=tor-browser-31.4.0esr-4.5-1&amp;id=ba4eca38fdad352c564719ff49aaa8c87e8a8ded</a> Apply new fix: <a class="ext-link" href="https://gitweb.torproject.org/tor-browser.git/commit/?h=tor-browser-31.4.0esr-4.5-1&amp;id=453b4ee4b2cd1c3dd22ee2040b38f09d26e8a60f"><span class="icon">​</span>https://gitweb.torproject.org/tor-browser.git/commit/?h=tor-browser-31.4.0esr-4.5-1&amp;id=453b4ee4b2cd1c3dd22ee2040b38f09d26e8a60f</a> </p> <p> I hope this was the correct (cleanest and clearest) way to handle this with git. </p> Ticket mcs Mon, 19 Jan 2015 21:49:24 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:37 https://trac.torproject.org/projects/tor/ticket/9701#comment:37 <p> We committed a follow up fix after a standalone test build failed on Mac OS: </p> <p> <a class="ext-link" href="https://gitweb.torproject.org/tor-browser.git/commit/?h=tor-browser-31.4.0esr-4.5-1&amp;id=a78a094886091a90e5f4e13c0579f9ad730ea8b5"><span class="icon">​</span>https://gitweb.torproject.org/tor-browser.git/commit/?h=tor-browser-31.4.0esr-4.5-1&amp;id=a78a094886091a90e5f4e13c0579f9ad730ea8b5</a> </p> <p> We did not attempt a Gitian-based build; hopefully all is well. </p> Ticket michael Tue, 20 Jan 2015 00:42:46 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:38 https://trac.torproject.org/projects/tor/ticket/9701#comment:38 <p> A corresponding report with hopes of merging to ESR38 is on <a class="ext-link" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1123480"><span class="icon">​</span>Bugzilla.</a> </p> Ticket michael Tue, 20 Jan 2015 11:24:53 GMT attachment set https://trac.torproject.org/projects/tor/ticket/9701 https://trac.torproject.org/projects/tor/ticket/9701 <ul> <li><strong>attachment</strong> set to <em>msvb9701-283f7c6.patch</em> </li> </ul> <p> Correction of overrun preexisting patch block including nsTransferable header change. </p> Ticket michael Tue, 20 Jan 2015 11:33:30 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:39 https://trac.torproject.org/projects/tor/ticket/9701#comment:39 <p> Replying to <a class="closed" href="https://trac.torproject.org/projects/tor/ticket/9701#comment:37" title="Comment 37 for Ticket #9701">mcs</a>: </p> <blockquote class="citation"> <p> We committed a follow up fix after a standalone test build failed on Mac OS: </p> </blockquote> <p> Thanks, the patch block in question was improperly overwritten during upload. </p> <p> The most recent patch correctly matches your follow up fix as well as the improperly overwritten block. <br /> </p> <blockquote class="citation"> <p> We did not attempt a Gitian-based build; hopefully all is well. </p> </blockquote> <p> A 32 hour gitian-build is under way and will be build time and high level run time tested accordingly. </p> Ticket michael Thu, 22 Jan 2015 11:57:12 GMT https://trac.torproject.org/projects/tor/ticket/9701#comment:40 https://trac.torproject.org/projects/tor/ticket/9701#comment:40 <p> Replying to <a class="closed" href="https://trac.torproject.org/projects/tor/ticket/9701#comment:39" title="Comment 39 for Ticket #9701">myself</a>: </p> <blockquote class="citation"> <p> Replying to <a class="closed" href="https://trac.torproject.org/projects/tor/ticket/9701#comment:37" title="Comment 37 for Ticket #9701">mcs</a>: </p> <blockquote class="citation"> <p> We did not attempt a Gitian-based build; hopefully all is well. </p> </blockquote> <p> A 32 hour gitian-build is under way and will be build time and high level run time tested accordingly. </p> </blockquote> <p> A local nightly gitian-build including <a href="https://trac.torproject.org/projects/tor/attachment/ticket/9701/msvb9701-283f7c6.patch">our patch</a> completed and high level testing validated the logic in question. </p> Ticket