spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From JoshRosen <...@git.apache.org>
Subject [GitHub] spark pull request #20191: [SPARK-22997] Add additional defenses against use...
Date Tue, 09 Jan 2018 01:01:50 GMT
Github user JoshRosen commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20191#discussion_r160297024
  
    --- Diff: common/unsafe/src/main/java/org/apache/spark/unsafe/memory/UnsafeMemoryAllocator.java
---
    @@ -38,9 +38,20 @@ public MemoryBlock allocate(long size) throws OutOfMemoryError {
       public void free(MemoryBlock memory) {
         assert (memory.obj == null) :
           "baseObject not null; are you trying to use the off-heap allocator to free on-heap
memory?";
    +    assert (memory.pageNumber != MemoryBlock.FREED_IN_ALLOCATOR_PAGE_NUMBER) :
    +      "page has already been freed";
    +    assert ((memory.pageNumber == MemoryBlock.NO_PAGE_NUMBER)
    +            || (memory.pageNumber == MemoryBlock.FREED_IN_TMM_PAGE_NUMBER)) :
    +      "TMM-allocated pages must be freed via TMM.freePage(), not directly in allocator
free()";
    +
         if (MemoryAllocator.MEMORY_DEBUG_FILL_ENABLED) {
           memory.fill(MemoryAllocator.MEMORY_DEBUG_FILL_FREED_VALUE);
         }
         Platform.freeMemory(memory.offset);
    +    // As an additional layer of defense against use-after-free bugs, we mutate the
    +    // MemoryBlock to reset its pointer.
    +    memory.offset = 0;
    --- End diff --
    
    Yep, this will guarantee SIGSEGV instead of corruption.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message