long-integerunsignedinteger-overflowcomparison-operatorsulong

Why does (ULONG_PTR)x > (ULONG_PTR)y comparison fail?


0x8A81FAA is less then 0x7FFFFFF0000 so why is it true?

pic

#if defined(_X86_)
#define ProbeForReadUnicodeStringFullBuffer(String)                                                          \
    if (((ULONG_PTR)((String).Buffer) & (sizeof(BYTE) - 1)) != 0) {                                   \
        ExRaiseDatatypeMisalignment();                                                            \
    } else if ((((ULONG_PTR)((String).Buffer) + ((String).MaximumLength)) < (ULONG_PTR)((String).Buffer)) ||     \
               (((ULONG_PTR)((String).Buffer) + ((String).MaximumLength)) > (ULONG_PTR)MM_USER_PROBE_ADDRESS)) { \
        ExRaiseAccessViolation();                                                                 \
    } else if (((String).Length) > ((String).MaximumLength)) {                                    \
        ExRaiseAccessViolation();                                                                 \
    }
#else
#define ProbeForReadUnicodeStringFullBuffer(String)                                                        \
    if (((ULONG_PTR)((String).Buffer) & (sizeof(WCHAR) - 1)) != 0) {                                  \
        DbgPrint("aaaaaa");\
        ExRaiseDatatypeMisalignment();                                                            \
    } else if ((((ULONG_PTR)((String).Buffer) + ((String).MaximumLength)) < (ULONG_PTR)((String).Buffer)) ||     \
               (((ULONG_PTR)((String).Buffer) + ((String).MaximumLength)) > (ULONG_PTR)MM_USER_PROBE_ADDRESS)) { \
            DbgPrint("bool = %d\n", (((ULONG_PTR)((String).Buffer) + ((String).MaximumLength)) < (ULONG_PTR)((String).Buffer))); \
            DbgPrint("bool2 = %d\n", (((ULONG_PTR)((String).Buffer) + ((String).MaximumLength)) > (ULONG_PTR)MM_USER_PROBE_ADDRESS)); \
            DbgPrint("fsdgfd = %d\n", ((ULONG_PTR)((String).Buffer) + ((String).MaximumLength)));\
            DbgPrint("asdasd = %llu\n", (ULONG_PTR)MM_USER_PROBE_ADDRESS);\
            DbgPrint("bbbbbbb : %d %d %llu\n", ((ULONG_PTR)((String).Buffer) + ((String).MaximumLength)), (ULONG_PTR)((String).Buffer), (ULONG_PTR)MM_USER_PROBE_ADDRESS);\
        ExRaiseAccessViolation();                                                                 \
    } else if (((String).Length) > ((String).MaximumLength)) {                                    \
    DbgPrint("cccccccc");\
        ExRaiseAccessViolation();                                                                 \
    }
#endif

Solution

  • Turns out if you change

    DbgPrint("fsdgfd = %d\n", ((ULONG_PTR)((String).Buffer) + ((String).MaximumLength)));\
    

    to

    DbgPrint("fsdgfd = %llu\n", ((ULONG_PTR)((String).Buffer) + ((String).MaximumLength)));\
    

    the value shows up as

    0xFFFFF8A020CB18EA

    after more research i figured out I don't even need a ProbeForRead as the pointer is a KernelMode pointer and there is no need to validate the kernelmode pointers, they are trusted.