-
-
Notifications
You must be signed in to change notification settings - Fork 249
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
UAF with detoasted pgx::datum::Array
s
#971
Comments
Some of the problem here is that for an And we may not necessarily want to simply apply the lifetime of the Array as a constraint to the underlying strings, either, though that would be a plausible fix. A simple way to fix it would be to elevate the constraints on the bounds of the various functions involved here until they say "the data returned must be an owned form", but I am willing to guess that's not exactly desired, as it would involve a huge overhead for the no-op (and entirely valid, if frivolous) #[pg_extern]
fn echo<'a>(a: Array<&'a str>) -> Array<&'a str> {
a
} |
Thinking about it, it could be required instead that the data, on leaving an Array, is in an owned form, and tightening the lifetime bounds so as to enforce this. This would allow borrowing strings from the Array with low overhead (e.g. if someone wants to just count them up or something like that), but prevent the drop handling from affecting extracting the data from the Array into a Vec, since that's really the transformation we want to preserve. |
I did some tampering with the current Array implementation. Even adding a new lifetime param to ArrayIterator doesn't do much to inhibit this. This seems to be a classic example of the LendingIterator problem, which the current impl of GATs does not fully solve. A cheap way of solving this is to make the bound on Another way to stop this would be reflecting that kind of difference internally: change our implementations to add something like a |
Looking at addressing this in some manner in #1149. Basically, we don't free the backing detoasted array pointer and the outstanding I'd prefer the example code here just not compile, but I don't think our FromDatum framework is robust enough to express this kind of borrowing throughout. I'm going to keep this issue open as we probably want to come back and actually solve this at compile-time. |
This function demonstrates a use after free if the Array was originally toasted:
To create such a situation in Postgres:
Using an owned
String
instead of a&str
doesn't have this problem since the String is a copy inside Rust allocated memory. Off the top of my head I'm not sure how to fix it.The text was updated successfully, but these errors were encountered: