-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Brodes/seh flow phase1 throwing models #18014
base: main
Are you sure you want to change the base?
Brodes/seh flow phase1 throwing models #18014
Conversation
…EH is not yet part of the IR generation to make this logic work.
/** | ||
* A function that is guaranteed to never throw. | ||
*/ | ||
abstract class NonThrowingFunction extends Function { } |
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.
You cannot just delete files that are not in non-implementation or internal directories. These will need to go through a deprecation period. Could you discuss with @MathiasVP what the correct approach should be here.
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.
Indeed, we have a 1-ish year deprecation period for non-internal QL things. So we need to:
- Mark this class as
deprecated
- Keep the functionality. i.e., extending
NonThrowingFunction
should do something equivalent to what it did before
And then it'll be deleted by someone in a PR a year from now.
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.
I was thinking about that after I submitted, fixed.
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.
Can't we just do:
private import Throwing as T
deprecated class NonThrowingFunction = T::NonThrowingFunction;
and write in the change note that (a) the class is deprecated, and (b) requires a new member to be implemented.
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.
Or is that too dirty?
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.
We can definitely do that, yes!
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.
We can do this, but I had avoided changes like this because any existing use of the old NonThrowingFunction would require the member predicate be defined, breaking any existing queries. I thought the point of deprecating vs deleting was to not completely break existing builds. If you are actually ok with that @jketema I'm ok with it.
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.
I suppose another option is to just make the deprecated version extend the new throwing function mechanic and set the exception type predicate to be any type (matching the prior intended behavior). I can do whatever, just please advise what is more acceptable to github standards.
*/ | ||
abstract predicate mayThrowException(boolean unconditional); | ||
final predicate mayRaiseException() { this.raisesException(false) } |
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.
Similarly, the mayThrowException
predicate will need to be kept for now and marked as deprecated.
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.
Need to rethink this generally for backwards compatibility given the original thing being deprecated is abstract. Stand by...
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.
Ok I decided to move back to the old mechanic. I switched because SEH doesn't really throw an exception per se. But it's fine, and easier to just keep it the way it was. The changes have been made, just waiting for the checks to pass.
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.
I'm seeing failures with some security/CWE tests, but I cannot recreate that locally. @MathiasVP is that a common discrepancy? can you maybe run the test locally as well? Thye all passed for me.
…rowException as well.
…ub.com/microsoft/codeql into brodes/seh_flow_phase1_throwing_models
…ds compatibility.
…ub.com/microsoft/codeql into brodes/seh_flow_phase1_throwing_models
…ption to be consistent with other backward compatibility changes.
Why do we need to deprecate Perhaps the stuff in |
This is because we want to distinguish between the kinds of exceptions that cannot be thrown. For example, I don't care specifically about how we distinguish between those two concepts. I agree that it's a bit unintuitive that you implement a Other API suggestions could be:
|
Co-authored-by: Mathias Vorreiter Pedersen <[email protected]>
@@ -106,6 +106,8 @@ private class MemcpyFunction extends ArrayFunction, DataFlowFunction, SideEffect | |||
not this.hasGlobalName(["bcopy", mempcpy(), "memccpy"]) and | |||
index = this.getParamDest() | |||
} | |||
|
|||
override TCxxException getExceptionType() { any() } |
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.
I find this confusing. Together with the NonThrowing
this seems to say that:
This function is non-throwing, but only in the case of C++ exceptions. So it may still throw a SEH exception.
Is that the correct reading?
Part of a phased approach to an overhaul of how exceptions are modeled and handled in IR, in order to handle both SEH (structured exception handling) and ordinary C++ exceptions. These two types of exceptions have subtly different mechanics and uses. Consequently, users cannot treat all exceptions as the same. E.g., a call to memset can raise an SEH exception but it would not raise an exception with C++ exceptions.
In this PR, I start by creating a new Throwing.qll library to provide metadata for any kind of exception, and a predicate to indicate if it is SEH or CXX. This change impacts models for NonThrowingFunctions, such as (as previously mentioned) memset. This PR, however, does not fully provide support to differentiate SEH and CXX exception handling in the IR. This will be addressed in future PRs.