Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RandomAccessReferenceMap.update() can randomly corrupt the map #37

Closed
meg23 opened this issue Nov 13, 2014 · 8 comments
Closed

RandomAccessReferenceMap.update() can randomly corrupt the map #37

meg23 opened this issue Nov 13, 2014 · 8 comments

Comments

@meg23
Copy link

meg23 commented Nov 13, 2014

From cyounk...@gmail.com on August 06, 2009 15:33:16

What steps will reproduce the problem? You have a ARM set up like this:
direct1 <=> "AAAA"

You do this:
newSet = new Set()
newSet.add(newDirect)
newSet.add(direct1)
ARM.update(newSet)

update() clears the old mappings, but tries to preserve them if the same
direct objects are referenced in the new set. Here's how this could go awry:

  • update() clears both maps
  • update() can't find newDirect in the old mapping, so it calls
    getUniqueRandomReference(), which randomly returns "AAAA". It checks that
    "AAAA" is not in the current mapping, and it's not (It was just cleared).
  • update() sets the mapping newDirect <=> "AAAA"
  • update() then looks at direct1, sees that it is in the old mapping, and
    sets it in the new mapping direct1 <=> "AAAA", corrupting the indirect to
    direct mapping which is now "AAAA" -> direct1

How to fix it:

  • Change getUniqueRandomReference to take in a list of invalid indirect
    keys and ensure the generated one is not in that list
  • Preserve the old indirect to direct map in update()
  • Pass in the keys of the old indirect to direct map to
    getUniqueRandomReference What version of the product are you using? On what operating system? SVN revision 574 .

Original issue: http://code.google.com/p/owasp-esapi-java/issues/detail?id=27

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From chrisisbeef on December 01, 2009 23:28:24

I believe, and correct me if I am wrong here, that the chances of this happening are
so far fetched that the amount of work to mitigate this nullify the benefit of going
through this work.

Also, with how impropable this situation is, is it worth affecting the performance of
an otherwise performant object?

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From chrisisbeef on December 01, 2009 23:55:02

Labels: -Priority-Medium Priority-Low

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From cyounk...@gmail.com on December 02, 2009 15:46:58

Well, I guess it depends on whether or not you want this thing to actually work reliably.

These are unchecked insertions, so the probability of a collision is the # of
elements in the map / the keyspace of the map keys. Multiply this by the number of
insertions to get roughly the probability of a collision on an update(). It's small
problems like this that are extremely elusive and hard to track down.

In the report I stated how to fix it. It would take at most 10 minutes to change and
test.

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From manico.james@gmail.com on October 31, 2010 22:59:29

Younkins is right IMO. I'll fix this before 2.0.

Owner: manico.james
Labels: -Priority-Low Priority-High Milestone-Release2.0

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From manico.james@gmail.com on October 31, 2010 23:01:43

Status: Accepted

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From chrisisbeef on November 20, 2010 13:16:56

Labels: Component-Other

@meg23
Copy link
Author

meg23 commented Nov 13, 2014

From manico.james@gmail.com on May 28, 2012 20:20:12

Owner: chrisisbeef

kwwall pushed a commit that referenced this issue Jan 16, 2019
* Concurrency Test for AbstractAccessReferenceMap

SThis test case consistently illustrates the race condition resulting from
concurrent invocations of addDirectReference.

* AbstractAccessReferenceMap Sync Updates

Synchronizing all public access methods to this wrapper class.

* AbstractAccessReferenceMap Class Documentation

Updating class documentation to provide an example of multi-interaction
synchronization syntax.

* AbstractAccessMap field updates to use HashMap

With primary synchronization being pushed to the class API level, there
really is no benefit to maintaining the overhead of ConcurrentHashMap
fields.  The thread-safety guaranteed by the ConcurrentHashMap is
superceeded by the public API of the abstract class, and should never
actually be leveraged.

This assumes that all sub-classes with extended public API continue the
use of class-level synchronization.

* AbstractAccessReferenceMapTest Extension

Adding method which shows that it is possible to create a corrupted direct
-> Indirect to Indirect -> Direct Object relationship when using the
public update(Set) API.

* AbstractAccessReferenceMap.update Logic Update

Altering the logic of update behavior to avoid the possibility of the same
indirect object being associated with multiple direct instances.
@kwwall
Copy link
Contributor

kwwall commented Jan 16, 2019

Closed via PR #469

@kwwall kwwall closed this as completed Jan 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants