-
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?
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.
That's right. That's what it is saying. It is no longer sufficient to say a function doesn't throw, you have to say how it doesn't throw (which kind of exception doesn't it throw). If they want to say it doesn't throw any you can just return the parent exception type.
The issue we got into with making memcpy nonthrowing is that it is true that it doesn't throw a C++ exception, but it absolutely throws a SEH exception. The mechanics in this PR force users to think about what it is they really want when they say a function throws or doesn't throw.
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.
Thanks.
I wonder if this is all somewhat overly complicated. In my understanding the following cases are interesting:
- C++ exceptions:
- Functions that may throw (this is the default, but are modelling of this in the IR is limited)
- Functions that do never throw a C++ exception, i.e., functions marked either as `noexcept or that are C functions (that we model)
- SEH exceptions:
- Functions that may throw (this is the default, and we want to improve the modelling in the IR here)
- Functions that always throw
Is this correct?
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 have a brief meeting. The conclusion was that my assessment above is correct. The proposal is do something simpler:
- Rename,
NonThrowing
to something likeNonCppThrowingFunction
and introduce a deprecatedNonThrowing
alias. - Introduce a new class
AlwaysSehThrowingFunction
which is used to model functions that always throw an SEH exception. - Deprecate the
Throwing
class.
We should also remove the use of the Throwing
class in the models, but we can only do that in the next phase when we update the IR (otherwise the IR breaks).
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.
Overhauled the PR, let me know if that works.
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.