From: Brian Warner Date: Wed, 11 Jan 2012 09:04:44 +0000 (-0800) Subject: retrieve.py: unconditionally check share-hash-tree. Fixes #1654. X-Git-Tag: allmydata-tahoe-1.9.1~5 X-Git-Url: https://git.rkrishnan.org/vdrive/%22file:/frontends/%22doc.html/statistics?a=commitdiff_plain;h=9b4b03a474a2c9050c8347459ab6698839be7288;p=tahoe-lafs%2Ftahoe-lafs.git retrieve.py: unconditionally check share-hash-tree. Fixes #1654. Add Kevan's unit test, update known_issues.rst --- diff --git a/docs/known_issues.rst b/docs/known_issues.rst index 441df80f..e564e2b8 100644 --- a/docs/known_issues.rst +++ b/docs/known_issues.rst @@ -17,6 +17,7 @@ want to read `the "historical known issues" document`_. Known Issues in Tahoe-LAFS v1.9.0, released 31-Oct-2011 ======================================================= + * `Integrity Failure during Mutable Downloads`_ * `Potential unauthorized access by JavaScript in unrelated files`_ * `Potential disclosure of file through embedded hyperlinks or JavaScript in that file`_ * `Command-line arguments are leaked to other local users`_ @@ -26,6 +27,46 @@ Known Issues in Tahoe-LAFS v1.9.0, released 31-Oct-2011 ---- +Integrity Failure during Mutable Downloads +-------------------------------------------------------------- + +Under certain circumstances, the integrity-verification code of the mutable +downloader could be bypassed. Clients who receive carefully crafted shares +(from attackers) will emit incorrect file contents, and the usual +share-corruption errors would not be raised. This only affects mutable files +(not immutable), and only affects downloads that use doctored shares. It is +not persistent: the threat is resolved once you upgrade your client to a +version without the bug. However, read-modify-write operations (such as +directory manipulations) performed by vulnerable clients could cause the +attacker's modifications to be written back out to the mutable file, making +the corruption permanent. + +The attacker's ability to manipulate the file contents is limited. They can +modify FEC-encoded ciphertext in all but one share. This gives them the +ability to blindly flip bits in roughly 2/3rds of the file (for the default +k=3 encoding parameter). Confidentiality remains intact, unless the attacker +can deduce the file's contents by observing your reactions to corrupted +downloads. + +This bug was introduced in 1.9.0, as part of the MDMF-capable downloader, and +affects both SDMF and MDMF files. It was not present in 1.8.3. + +*how to manage it* + +There are three options: + +* Upgrade to 1.9.1, which fixes the bug +* Downgrade to 1.8.3, which does not contain the bug +* If using 1.9.0, do not trust the contents of mutable files (whether SDMF or + MDMF) that the 1.9.0 client emits, and do not modify directories (which + could write the corrupted data back into place, making the damage + persistent) + + +.. _#1654: https://tahoe-lafs.org/trac/tahoe-lafs/ticket/1654 + +---- + Potential unauthorized access by JavaScript in unrelated files -------------------------------------------------------------- diff --git a/src/allmydata/mutable/retrieve.py b/src/allmydata/mutable/retrieve.py index 0e507704..0d9c60e2 100644 --- a/src/allmydata/mutable/retrieve.py +++ b/src/allmydata/mutable/retrieve.py @@ -804,17 +804,14 @@ class Retrieve: # successful, then bht[0] will contain the root for the # shnum, which will be a leaf in the share hash tree, which # will allow us to validate the rest of the tree. - if self.share_hash_tree.needed_hashes(reader.shnum, - include_leaf=True) or \ - self._verify: - try: - self.share_hash_tree.set_hashes(hashes=sharehashes[1], - leaves={reader.shnum: bht[0]}) - except (hashtree.BadHashError, hashtree.NotEnoughHashesError, \ - IndexError), e: - raise CorruptShareError(reader.peerid, - reader.shnum, - "corrupt hashes: %s" % e) + try: + self.share_hash_tree.set_hashes(hashes=sharehashes[1], + leaves={reader.shnum: bht[0]}) + except (hashtree.BadHashError, hashtree.NotEnoughHashesError, \ + IndexError), e: + raise CorruptShareError(reader.peerid, + reader.shnum, + "corrupt hashes: %s" % e) self.log('share %d is valid for segment %d' % (reader.shnum, segnum)) diff --git a/src/allmydata/test/test_mutable.py b/src/allmydata/test/test_mutable.py index 980e8451..496ccd3a 100644 --- a/src/allmydata/test/test_mutable.py +++ b/src/allmydata/test/test_mutable.py @@ -1,4 +1,3 @@ - import os, re, base64 from cStringIO import StringIO from twisted.trial import unittest @@ -2752,6 +2751,155 @@ class Problems(GridTestMixin, unittest.TestCase, testutil.ShouldFailMixin): self.failUnlessEqual(data, CONTENTS)) return d + def test_1654(self): + # test that the Retrieve object unconditionally verifies the block + # hash tree root for mutable shares. The failure mode is that + # carefully crafted shares can cause undetected corruption (the + # retrieve appears to finish successfully, but the result is + # corrupted). When fixed, these shares always cause a + # CorruptShareError, which results in NotEnoughSharesError in this + # 2-of-2 file. + self.basedir = "mutable/Problems/test_1654" + self.set_up_grid(num_servers=2) + cap = uri.from_string(TEST_1654_CAP) + si = cap.get_storage_index() + + for share, shnum in [(TEST_1654_SH0, 0), (TEST_1654_SH1, 1)]: + sharedata = base64.b64decode(share) + storedir = self.get_serverdir(shnum) + storage_path = os.path.join(storedir, "shares", + storage_index_to_dir(si)) + fileutil.make_dirs(storage_path) + fileutil.write(os.path.join(storage_path, "%d" % shnum), + sharedata) + + nm = self.g.clients[0].nodemaker + n = nm.create_from_cap(TEST_1654_CAP) + # to exercise the problem correctly, we must ensure that sh0 is + # processed first, and sh1 second. NoNetworkGrid has facilities to + # stall the first request from a single server, but it's not + # currently easy to extend that to stall the second request (mutable + # retrievals will see two: first the mapupdate, then the fetch). + # However, repeated executions of this run without the #1654 fix + # suggests that we're failing reliably even without explicit stalls, + # probably because the servers are queried in a fixed order. So I'm + # ok with relying upon that. + d = self.shouldFail(NotEnoughSharesError, "test #1654 share corruption", + "ran out of peers", + n.download_best_version) + return d + + +TEST_1654_CAP = "URI:SSK:6jthysgozssjnagqlcxjq7recm:yxawei54fmf2ijkrvs2shs6iey4kpdp6joi7brj2vrva6sp5nf3a" + +TEST_1654_SH0 = """\ +VGFob2UgbXV0YWJsZSBjb250YWluZXIgdjEKdQlEA46m9s5j6lnzsOHytBTs2JOo +AkWe8058hyrDa8igfBSqZMKO3aDOrFuRVt0ySYZ6oihFqPJRAAAAAAAAB8YAAAAA +AAAJmgAAAAFPNgDkK8brSCzKz6n8HFqzbnAlALvnaB0Qpa1Bjo9jiZdmeMyneHR+ +UoJcDb1Ls+lVLeUqP2JitBEXdCzcF/X2YMDlmKb2zmPqWfOw4fK0FOzYk6gCRZ7z +AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +AAAAAAAAAAAAAAAAAAAAAAAAAAAA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