I spotted a bug in getgroups() function call in #MorphOS shared POSIX compatibil...
Harry Sintonen @harrysintonen@infosec.exchange
I spotted a bug in getgroups() function call in #MorphOS shared POSIX compatibility libc ixemul. In short: The function misbehaves when passed (0, NULL) and returns -1 with errno EFAULT rather than the number of groups. While I will fix the bug for the future, I also needed to figure out a way to mitigate this issue for installations that do not have the update.
Patching every single app that uses getgroups(0, NULL) would of course work, but it would be terrible amount of manual labor. One hack would be to create a define for the getgroups() that'd magically handle the situation. Rather than going for these, I figured out rather neat way to handle this instead:
Since ixemul function calls are calling a shared library functions via stubs, I instead patched the stub generation code for getgroups function. When the stub assembly is generated it now injects the following code before the actual branch to the function code:
cmp 3,0
bne 0,.L1
cmp 4,0
bne 0,.L1
li 4,1
.L1:
Effectively the above is #powerpc assembly for:
if (size == 0 && list == NULL) list = (gid_t *) 1;
This ensures that the function will always be called with non-zero list parameter, effectively working around the issue.
Is it a hack? Oh yes. Did I spend a huge amount of time actually patching other code manually before figuring out this hack? Oh yes.
It's still rather neat hack, even if a bit late to the game!