> In what scenario would a function call be insecure? When malware or a
> debugger calls it outside the regular program flow?
When it is called without knowing the token.
The idea is the compiler generates a random token when it creates the
executable. Every known call to that function will setup the token to
be tested by the called function. If you call through a pointer to the
function's address, you won't have the token setup except by something
like random luck or a brute-force attack. And, because of that
possibility, I think the better solution would be for the OS loader to
do some load-time linking on the binary and introduce random values for
each secure function, so that every time the binary is loaded, it has
a new set of random values.
> If so, couldn't the said program check the CMP instruction of a function
> to get access to the secure token? Or better yet, stop it from jumping
> to the insecure part?
It would require the code be loaded into and running from an execute-only
block of memory. By doing that, no external application would be able to
gain access to the raw binary/machine code to be able to determine the
token, and the front-end could be created in such a way that only a proper
landing point, with a proper token or not, would be valid entry into the
function.
Different kinds of tokens could be created. However, I think for speed
reasons the need to test a 64-bit value would be sufficient. The odds of
happening onto the exact 64-bit random value assigned during this binary's
launch ... it's just unlikely.