VirtualBox

Changeset 66424 in vbox


Ignore:
Timestamp:
Apr 5, 2017 9:27:55 AM (8 years ago)
Author:
vboxsync
Message:

Runtime/r0drv: rtStrFormatKernelAddress() for Linux

Location:
trunk/src/VBox
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/linux/Makefile

    r66415 r66424  
    9090        r0drv/linux/mpnotification-r0drv-linux.o \
    9191        r0drv/linux/process-r0drv-linux.o \
     92        r0drv/linux/rtStrFormatKernelAddress-r0drv-linux.o \
    9293        r0drv/linux/semevent-r0drv-linux.o \
    9394        r0drv/linux/semeventmulti-r0drv-linux.o \
     
    149150        generic/RTSemEventMultiWaitNoResume-2-ex-generic.o \
    150151        generic/RTTimerCreate-generic.o \
    151         generic/rtStrFormatKernelAddress-generic.o \
    152152        generic/errvars-generic.o \
    153153        generic/mppresent-generic.o \
  • trunk/src/VBox/HostDrivers/Support/linux/files_vboxdrv

    r66415 r66424  
    153153    ${PATH_ROOT}/src/VBox/Runtime/include/internal/thread.h=>include/internal/thread.h \
    154154    ${PATH_ROOT}/src/VBox/Runtime/include/internal/time.h=>include/internal/time.h \
    155     ${PATH_ROOT}/src/VBox/Runtime/generic/rtStrFormatKernelAddress-generic.cpp=>generic/rtStrFormatKernelAddress-generic.c \
    156155    ${PATH_ROOT}/src/VBox/Runtime/generic/RTAssertShouldPanic-generic.cpp=>generic/RTAssertShouldPanic-generic.c \
    157156    ${PATH_ROOT}/src/VBox/Runtime/generic/RTLogWriteStdErr-stub-generic.cpp=>generic/RTLogWriteStdErr-stub-generic.c \
     
    175174    ${PATH_ROOT}/src/VBox/Runtime/r0drv/power-r0drv.h=>r0drv/power-r0drv.h \
    176175    ${PATH_ROOT}/src/VBox/Runtime/r0drv/powernotification-r0drv.c=>r0drv/powernotification-r0drv.c \
     176    ${PATH_ROOT}/src/VBox/Runtime/r0drv/linux/rtStrFormatKernelAddress-r0drv-linux.c=>r0drv/linux/rtStrFormatKernelAddress-r0drv-linux.c \
    177177    ${PATH_ROOT}/src/VBox/Runtime/r0drv/linux/RTLogWriteDebugger-r0drv-linux.c=>r0drv/linux/RTLogWriteDebugger-r0drv-linux.c \
    178178    ${PATH_ROOT}/src/VBox/Runtime/r0drv/linux/assert-r0drv-linux.c=>r0drv/linux/assert-r0drv-linux.c \
  • trunk/src/VBox/Runtime/r0drv/linux/rtStrFormatKernelAddress-r0drv-linux.c

    r66423 r66424  
    3030*********************************************************************************************************************************/
    3131#define LOG_GROUP RTLOGGROUP_STRING
    32 #include <iprt/string.h>
     32#include "the-linux-kernel.h"
     33#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)
     34# include <linux/capability.h>
     35# include <linux/security.h>
     36#endif
    3337#include "internal/iprt.h"
    3438
     
    3943
    4044
    41 
    4245DECLHIDDEN(size_t) rtStrFormatKernelAddress(char *pszBuf, size_t cbBuf, RTR0INTPTR uPtr, signed int cchWidth,
    4346                                            signed int cchPrecision, unsigned int fFlags)
    4447{
    45 #ifndef DEBUG
    46     RT_NOREF(uPtr, cchWidth, cchPrecision);
     48#if !defined(DEBUG) && LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)
     49    bool fRestrict = false;
     50    if (kptr_restrict > 1)
     51        fRestrict = true;
     52    else if (kptr_restrict == 1)
     53    {
     54        const struct cred *cred = current_cred();
     55        if (   !has_capability_noaudit(current, CAP_SYSLOG)
     56# if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
     57            || !uid_eq(cred->euid, cred->uid)
     58            || !gid_eq(cred->egid, cred->gid)
     59# endif
     60            )
     61            fRestrict = true;
     62    }
     63
     64    if (fRestrict)
     65    {
     66        RT_NOREF(uPtr, cchWidth, cchPrecision);
    4767# if R0_ARCH_BITS == 64
    48     static const char s_szObfuscated[] = "0xXXXXXXXXXXXXXXXX";
     68        static const char s_szObfuscated[] = "0xXXXXXXXXXXXXXXXX";
    4969# else
    50     static const char s_szObfuscated[] = "0xXXXXXXXX";
     70        static const char s_szObfuscated[] = "0xXXXXXXXX";
    5171# endif
    52     size_t      cbSrc  = sizeof(s_szObfuscated);
    53     const char *pszSrc = s_szObfuscated;
    54     if (!(fFlags & RTSTR_F_SPECIAL))
    55     {
    56         pszSrc += 2;
    57         cbSrc  -= 2;
     72        size_t      cbSrc  = sizeof(s_szObfuscated);
     73        const char *pszSrc = s_szObfuscated;
     74        if (!(fFlags & RTSTR_F_SPECIAL))
     75        {
     76            pszSrc += 2;
     77            cbSrc  -= 2;
     78        }
     79        if (cbSrc <= cbBuf)
     80        {
     81            memcpy(pszBuf, pszSrc, cbSrc);
     82            return cbSrc;
     83        }
     84        AssertFailed();
     85        memcpy(pszBuf, pszSrc, cbBuf);
     86        pszBuf[cbBuf - 1] = '\0';
     87        return cbBuf - 1;
    5888    }
    59     if (cbSrc <= cbBuf)
    60     {
    61         memcpy(pszBuf, pszSrc, cbSrc);
    62         return cbSrc;
    63     }
    64     AssertFailed();
    65     memcpy(pszBuf, pszSrc, cbBuf);
    66     pszBuf[cbBuf - 1] = '\0';
    67     return cbBuf - 1;
    68 
    69 #else  /* DEBUG */
     89#endif  /* DEBUG && LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38) */
    7090    Assert(cbBuf >= 64);
    7191    return RTStrFormatNumber(pszBuf, uPtr, 16, cchWidth, cchPrecision, fFlags);
    72 #endif /* DEBUG */
    7392}
    74 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette