r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[!REBOL3]

BrianH
9-Oct-2011
[9680]
blah: module [] [hidden hidden-stuff: "something you want" a: func 
[code /stuff] [stuff: hidden-stuff code]]
blah/a func [] [do something to get access to hidden-stuff]
Ladislav
9-Oct-2011
[9681x2]
OK, fine, an example that looks meaningful to you.
So, do I assume correctly, that I cannot examine the BLAH module 
to get the HIDDEN-STUFF value?
BrianH
9-Oct-2011
[9683]
It's just a placeholder. If you have a PROTECT/hide exploit, that's 
interesting too but off-topic.
Ladislav
9-Oct-2011
[9684]
Does not matter, it is just an assumption, I am just asking whether 
you don't mind me making it.
BrianH
9-Oct-2011
[9685x3]
Right. Let me make that more explicit:

import module [] [hidden hidden-stuff: "something you want" export 
a: func [code /stuff] [stuff: hidden-stuff code]]
In those circumstances a reference to :a is copied to lib/a, but 
there is no reference to the module saved except the PROTECT/hide 
reference to hidden-stuff in the block of :a.
Or rather it's copied to system/contexts/user/a, but the point remains 
the same.
Ladislav
9-Oct-2011
[9688x2]
Yes, OK. So, now, let me cite:


The reason for this is so that functions can prevent access to their 
context from leaking to code *that the function calls* that could 
be exploited while the function is running.
 - don't you see, that your purported reason fails?
Why it fails: because, even knowing the bound version of the 'stuff 
variable does not help me to get the HIDDEN-STUFF, so, the purported 
reason does not exist
BrianH
9-Oct-2011
[9690]
a func [] [do something to get access to hidden-stuff]


The function a doesn't exclude functions from its arguments and it 
refers to its argument with a word rather than a get-word, so it 
can be tricked into running code while it is running. That means 
its context is valid while the exploit code is running.
Ladislav
9-Oct-2011
[9691]
So, once again, your example demonstrating the existence of the (purported 
and nonexistent) reason failed.
BrianH
9-Oct-2011
[9692x2]
The 'stuff word isn't hidden, but it isn't leaked while the function 
is running. That means that the exploit code only has access to the 
:a function value.
So, come up with some exploit code (that doesn't use STACK because 
we're assuming SECURE 'debug works). This is a real problem.
Ladislav
9-Oct-2011
[9694]
Do I understand correctly, that this is what you propose as demonstrating 
the reason for the functions not being accepted by BIND?

a: func [] [do something to get access to hidden-stuff]
BrianH
9-Oct-2011
[9695]
No, you added a : there. The function is being passed to a as an 
argument.
Ladislav
9-Oct-2011
[9696]
aha, sorry, now I see.
BrianH
9-Oct-2011
[9697x2]
a func [] [print get bind 'stuff :a]
I had to go though the mezzanine code pretty carefully to consider 
what happens when functions are passed as arguments to the mezzanine 
functions. Some functions like REPLACE and ARRAY were modified to 
take advantage of that trick pretty nicely.
Ladislav
9-Oct-2011
[9699]
OK, but nothing of that kind applies to the case of BIND [...] 'some-variable
BrianH
9-Oct-2011
[9700x2]
True, which is why I was convinced by that particular argument :)
then the ban on BIND to a function-context-bound word when the function 
isn't running has no security benefit
 :)
Ladislav
9-Oct-2011
[9702]
Yes, it only prevents some meaningful uses
BrianH
9-Oct-2011
[9703]
Especially ones where the bound words are leaked intentionally to 
provide access to the context. It sounds worthy of a wish ticket 
in CureCode.
Ladislav
9-Oct-2011
[9704]
Unfortunately, the whole issue may be quite long to present completely
BrianH
9-Oct-2011
[9705]
I'll write it up, if it's OK to copy some of your arguments from 
above into the ticket.
Ladislav
9-Oct-2011
[9706x2]
Anything
So, for the case of BIND [...] function the main difference is, that 
it cannot be done regardless of whether the function is running or 
not, which can be considered a security measure, then.
BrianH
9-Oct-2011
[9708]
Yup. And BODY-OF returning an unbound copy prevents code like this:
	print get second body-of :a

PROTECT/hide doesn't affect existing bindings, so you need to be 
careful about leaking those too.
BrianH
10-Oct-2011
[9709]
Initial version of the ticket made: http://issue.cc/r3/1893
Ladislav
10-Oct-2011
[9710]
Supporting comment added.
Henrik
11-Oct-2011
[9711x2]
would it not be practical if REMOVE-EACH could /SKIP ?
nevermind. please ignore request.
Ladislav
11-Oct-2011
[9713]
remove-each [value skip] my-block [...]
Henrik
11-Oct-2011
[9714]
ladislav, yes, saw it just now. :-)
Andreas
12-Oct-2011
[9715x2]
The only function in R3 that operates that way is TRANSCODE, so as 
long as it doesn't choke on overlong combinations

#{c0ae} is an overlong encoding for #"." (#{2e}).

>> invalid-utf? #{c0ae}
== #{C0AE}

>> transcode #{c0ae}
== [® #{}]

>> transcode #{2e}
== [. #{}]
So for words, transcode is behaving strange. On the other hand, for 
strings ({"} is #{22}):

>> transcode #{22c0ae22}
== ["." #{}]
BrianH
12-Oct-2011
[9717]
So, on R3 INVALID-UTF? flags overlong encodings? Sorry I missed that. 
Better fix the R2/Forward version accordingly.
Andreas
12-Oct-2011
[9718]
No, it doesn't.
BrianH
12-Oct-2011
[9719]
And we could use a ticket for the TRANSCODE bugs.
Andreas
12-Oct-2011
[9720]
Or at least, it behaves the same as in R2.
BrianH
12-Oct-2011
[9721x2]
INVALID-UTF? returns the series at the position of the first invalid 
sequence. If it doesn't flag it returns none.
If it is returning anything other than none for an overlong form, 
it is screening for overlong forms.
Andreas
12-Oct-2011
[9723]
It is only in this particular case.
BrianH
12-Oct-2011
[9724]
Other overlong forms are not being screened for, but one form is? 
That would also be worth a ticket.
Andreas
12-Oct-2011
[9725x3]
No, that's nothing to do with overlong forms, but with PARSE in combination 
with bitsets being broken.
Which definitely is worth a ticket.
>> parse/all #{f0} reduce [charset [#{d0}]]
== true
BrianH
12-Oct-2011
[9728]
I'm talking about the R3 version, which is a native that doesn't 
use PARSE. Do you think it's a related bug?
Andreas
12-Oct-2011
[9729]
Mixed up R2 and R3 here.