Thread Tools Display Modes
10-13-12, 04:49 AM   #1
Jarod24
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jul 2012
Posts: 66
Detecting tainted code

I was just thinking about how Blizzard might be detecting tainted code and then i came up with this simple approach that addon developers could do this sort of thing in their own code.

I'm probably re-inventing the wheel here since this must have been thought of before.
I have not found any need to use something like this in my own addons, was just dabbling with some code.

Code:
--Declaration of the original function
function foo()
	print("This is my orignial un-tainted function");
end
local foo_address = tostring(foo); --Remember locally the address of the original function.

--This will create a new function, overwriting the orignal
function bar() 
	print("Original: "..foo_address);
	
	foo = function() print("This is a tainted function") end;
	print("New: "..tostring(foo));
end
Has anyone had the need for this sort of taint-detection in their addon?

The crux is that the "foo_address" is done right after the original function's declaration and that it's local; thereby not modifiable by external code.
__________________
Author of IfThen, Links in Chat
  Reply With Quote
10-13-12, 03:12 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
I haven't really had any need for this sort of thing. The usual approach of keeping everything as a local that doesn't need to be global works fine as nobody can modify it without going into your code and changing it themselves. At that point, any taint detection is a moot point.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
10-14-12, 09:05 AM   #3
Farmbuyer
A Cyclonian
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 43
Originally Posted by Jarod24 View Post
The crux is that the "foo_address" is done right after the original function's declaration and that it's local; thereby not modifiable by external code.
And...? What's the point of foo_address? You can't do anything with machine addresses inside a script.

More generally, what would you do when taint is detected?

- Print an error and refuse to call the function? That's what happens by default already.
- Avoid the "new" function pointer and call the original? Why not do that to begin with?
  Reply With Quote
10-15-12, 09:36 AM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Originally Posted by Farmbuyer View Post
And...? What's the point of foo_address? You can't do anything with machine addresses inside a script.
Pointer addresses can always be used to visually compare and see if any two pointers refer to the same address (functionally, no different than FuncA==FuncB). This is the same as any other by-reference value type.



Originally Posted by Farmbuyer View Post
More generally, what would you do when taint is detected?
- Print an error and refuse to call the function? That's what happens by default already.
This only happens with the protected Blizzard functions, not ones defined by addons.



Note the OP posted this as prototype code, not necessarily meant for actual use, but to explain a process in place by Blizzard. The actual code in place is in C code that checks the current execution taint instead of if the function pointer stored has changed. This is why hooksecurefunc() works, as the hook function points to secure C code rather than a Lua function. The execution taint updates status every table index (including global environment) and function call.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 10-15-12 at 10:26 AM.
  Reply With Quote
10-17-12, 06:28 PM   #5
Farmbuyer
A Cyclonian
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 43
Originally Posted by SDPhantom View Post
Pointer addresses can always be used to visually compare and see if any two pointers refer to the same address (functionally, no different than FuncA==FuncB). This is the same as any other by-reference value type.
Exactly. There's no point in storing it as a string. Just compare the function references.


Note the OP posted this as prototype code, not necessarily meant for actual use, but to explain a process in place by Blizzard. The actual code in place is in C code that checks the current execution taint instead of if the function pointer stored has changed.
Yes, I know. I've glanced through stock Lua 5 source and think I know how their taint tracker could be implemented. That doesn't answer my question: what would you do next if you detect a change? What's the practical point of this?
  Reply With Quote
10-18-12, 02:09 AM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Originally Posted by Farmbuyer View Post
That doesn't answer my question: what would you do next if you detect a change?
That's still up to whoever decides to use this method. It's more of "proof of concept" rather than functional code.



Originally Posted by Farmbuyer View Post
What's the practical point of this?
There isn't one that I can see. This has been hinted at already.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Detecting tainted code

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off