Changeset 0941e9ae in mainline


Ignore:
Timestamp:
2012-11-05T20:17:17Z (12 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
94795812
Parents:
082b7f1
Message:

Test for addition overflow of area's base and size.

Location:
kernel/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/macros.h

    r082b7f1 r0941e9ae  
    130130            | ((((uint64_t) (up)) & UINT32_C(0xffffffff)) << 32))
    131131
     132/* Test for result wrap-around into positive numbers. */
     133#define overflows_add(a, b) \
     134        (((a) + (b) < (a)) && ((a) + (b)))
     135
    132136/** Pseudorandom generator
    133137 *
  • kernel/generic/src/mm/as.c

    r082b7f1 r0941e9ae  
    299299        ASSERT((addr % PAGE_SIZE) == 0);
    300300        ASSERT(mutex_locked(&as->lock));
     301        ASSERT(!overflows_add(addr, P2SZ(count)));
    301302       
    302303        /*
     
    513514        if (size == 0)
    514515                return NULL;
    515        
     516
    516517        size_t pages = SIZE2FRAMES(size);
    517518       
     
    531532                }
    532533        }
     534
     535        if (overflows_add(*base, size))
     536                return NULL;
    533537
    534538        if (!check_area_conflicts(as, *base, pages, guarded, NULL)) {
     
    810814                /*
    811815                 * Growing the area.
     816                 */
     817
     818                if (overflows_add(address, P2SZ(pages)))
     819                        return EINVAL;
     820
     821                /*
    812822                 * Check for overlaps with other address space areas.
    813823                 */
Note: See TracChangeset for help on using the changeset viewer.