Changeset 5a5269d in mainline for kernel/generic/src/syscall/copy.c


Ignore:
Timestamp:
2019-07-02T12:03:55Z (5 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
98c4c16
Parents:
aca97582
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-07-02 12:03:55)
git-committer:
GitHub <noreply@…> (2019-07-02 12:03:55)
Message:

Change type of uspace pointers in kernel from pointer type to numeric (#170)

From kernel's perspective, userspace addresses are not valid pointers,
and can only be used in calls to copy_to/from_uspace().
Therefore, we change the type of those arguments and variables to
uspace_addr_t which is an alias for sysarg_t.

This allows the compiler to catch accidental direct accesses to
userspace addresses.

Additionally, to avoid losing the type information in code,
a macro uspace_ptr(type) is used that translates to uspace_addr_t.
I makes no functional difference, but allows keeping the type information
in code in case we implement some sort of static checking for it in the future.

However, ccheck doesn't like that, so instead of using uspace_ptr(char),
we use uspace_ptr_char which is defined as
#define uspace_ptr_char uspace_ptr(char).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/syscall/copy.c

    raca97582 r5a5269d  
    5959 * @return EOK on success or an error code from @ref errno.h.
    6060 */
    61 errno_t copy_from_uspace(void *dst, const void *uspace_src, size_t size)
     61errno_t copy_from_uspace(void *dst, uspace_addr_t uspace_src, size_t size)
    6262{
    6363        ipl_t ipl;
     
    6868
    6969        if (!KERNEL_ADDRESS_SPACE_SHADOWED) {
    70                 if (overlaps((uintptr_t) uspace_src, size,
     70                if (overlaps(uspace_src, size,
    7171                    KERNEL_ADDRESS_SPACE_START,
    7272                    KERNEL_ADDRESS_SPACE_END - KERNEL_ADDRESS_SPACE_START)) {
     
    8282         * Check whether the address is outside the address space hole.
    8383         */
    84         if (overlaps((uintptr_t) uspace_src, size, ADDRESS_SPACE_HOLE_START,
     84        if (overlaps(uspace_src, size, ADDRESS_SPACE_HOLE_START,
    8585            ADDRESS_SPACE_HOLE_END - ADDRESS_SPACE_HOLE_START))
    8686                return EPERM;
     
    110110 * @return 0 on success or an error code from @ref errno.h.
    111111 */
    112 errno_t copy_to_uspace(void *uspace_dst, const void *src, size_t size)
     112errno_t copy_to_uspace(uspace_addr_t uspace_dst, const void *src, size_t size)
    113113{
    114114        ipl_t ipl;
     
    119119
    120120        if (!KERNEL_ADDRESS_SPACE_SHADOWED) {
    121                 if (overlaps((uintptr_t) uspace_dst, size,
     121                if (overlaps(uspace_dst, size,
    122122                    KERNEL_ADDRESS_SPACE_START,
    123123                    KERNEL_ADDRESS_SPACE_END - KERNEL_ADDRESS_SPACE_START)) {
     
    133133         * Check whether the address is outside the address space hole.
    134134         */
    135         if (overlaps((uintptr_t) uspace_dst, size, ADDRESS_SPACE_HOLE_START,
     135        if (overlaps(uspace_dst, size, ADDRESS_SPACE_HOLE_START,
    136136            ADDRESS_SPACE_HOLE_END - ADDRESS_SPACE_HOLE_START))
    137137                return EPERM;
Note: See TracChangeset for help on using the changeset viewer.