-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C++: Fix barriers in invalid pointer deref #13725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C++: Fix barriers in invalid pointer deref #13725
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QL changes seem reasonable (though I won't pretend to have a deep understanding of all of them). Test results speak for themselves.
On DCA we lose 6 results, which appear to be false positives as well (as best I can tell).
7d0a2cb
to
c2e2525
Compare
c2e2525
to
cd19876
Compare
cd19876
to
af07efe
Compare
cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/InvalidPointerToDereference.qll
Fixed
Show fixed
Hide fixed
DCA looks good. We lose the same 6 results as we did on the very first DCA run (which both Geoffrey and I confirmed to be FPs) 🎉 |
cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/AllocationToInvalidPointer.qll
Outdated
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/AllocationToInvalidPointer.qll
Outdated
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/AllocationToInvalidPointer.qll
Outdated
Show resolved
Hide resolved
14c1143
to
6d949cb
Compare
cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/AllocationToInvalidPointer.qll
Outdated
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/AllocationToInvalidPointer.qll
Outdated
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/AllocationToInvalidPointer.qll
Outdated
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/AllocationToInvalidPointer.qll
Outdated
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/AllocationToInvalidPointer.qll
Show resolved
Hide resolved
58de7c3
to
2164069
Compare
I believe I understand the barrier changes to |
cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/InvalidPointerToDereference.qll
Outdated
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/InvalidPointerToDereference.qll
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/InvalidPointerToDereference.qll
Outdated
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/InvalidPointerToDereference.qll
Outdated
Show resolved
Hide resolved
…InvalidPointerToDereference.qll Co-authored-by: Jeroen Ketema <93738568+jketema@users.noreply.github.com>
cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/InvalidPointerToDereference.qll
Show resolved
Hide resolved
cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/InvalidPointerToDereference.qll
Show resolved
Hide resolved
Did we do a DCA run after we fixed the off-by-one issue? |
I haven't done one yet, but I suppose I might as well start one now, yeah 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM provided DCA comes back ok.
The DCA results are in: We still lose the 6 FPs as before, but we now gain a couple of new results that I'm investigating. So far (will update as I go along): WiresharkOne new result related to a complex loop that depends on the input being a multiple of 4 that looks like: for (i=ICQ5_CL_SESSIONID; i < size; i+=4 ) {
k = key+table_v5[i&0xff];
if ( i != 0x16 ) {
bfr[i] ^= (guchar)(k & 0xff);
bfr[i+1] ^= (guchar)((k & 0xff00)>>8); // <--- We now raise an alert here
}
if ( i != 0x12 ) {
bfr[i+2] ^= (guchar)((k & 0xff0000)>>16);
bfr[i+3] ^= (guchar)((k & 0xff000000)>>24);
}
} VimA very strange loop that changes the number of iterations, and does different things depending on the current value that's incremented 😭: for (pos.col = 0; pos.col < len; pos.col += width) {
if (vterm_screen_get_cell(screen, pos, &cell) == 0) {
width = 1;
CLEAR_POINTER(p + pos.col);
if (ga_grow(&ga, 1) == OK)
ga.ga_len += utf_char2bytes(' ',
(char_u *)ga.ga_data + ga.ga_len);
}
else width = cell.width;
cell2cellattr(&cell, &p[pos.col]);
if (width == 2)
// second cell of double-width character has the
// same attributes.
p[pos.col + 1] = p[pos.col]; // <--- We now raise an alert here
/* ... */
} NelsonThis alert LGTM, but it may be a FP because double* ptrComplex = (double*)ArrayOf::allocateArrayOf(NLS_DCOMPLEX, nbElements, stringVector(), false);
auto* strElements = (ArrayOf*)A.getDataPointer();
indexType q = 0;
for (indexType k = 0; k < nbElements; k = k + 1) {
ArrayOf element = strElements[k];
if (element.getDataClass() == NLS_CHAR) {
std::wstring str = element.getContentAsWideString();
bool wasConverted = false;
doublecomplex asComplex = stringToDoubleComplex(str, wasConverted);
if (wasConverted) {
ptrComplex[q] = asComplex.real();
ptrComplex[q + 1] = asComplex.imag();
} else {
ptrComplex[q] = std::nan("NaN");
ptrComplex[q + 1] = 0;
}
} else {
ptrComplex[k] = std::nan("NaN");
ptrComplex[k + 1] = 0; // <--- We now raise an alert here
}
} |
This PR fixes both the barriers in
cpp/invalid-pointer-deref
. That is, the first commit fixes the barrierInvalidPointerToDereference.qll
, and the fifth commit fixes the barrier inAllocationToInvalidPointer.qll
.Both barriers should now come with (very informal) correctness proofs.