OS X 10.11 buffer overflow with deep filesystem hierarchy
cxsecurity.com
cxsecurity.com
len = sizeof(FTSENT) + namelen;
if (!ISSET(FTS_NOSTAT))
len += sizeof(struct stat) + ALIGNBYTES;
if ((p = malloc(len)) == NULL)
return (NULL);
/* Copy the name plus the trailing NULL. */
memmove(p->fts_name, name, namelen + 1);
It's a pretty minor bug, since I'd bet the chances of it causing a major exploitable vulnerability are quite low. A theoretical attacker can only control somewhat coarsely where a single byte with the value 0 can be written, and this is in userspace. Most of the time it probably lands in unused padding, and otherwise in an invalid address which causes a segfault.https://github.com/coreutils/gnulib/blame/master/lib/fts.c#L...
p->fts_statp = (struct stat )ALIGN(p->fts_name + namelen + 2);*
Unless ALIGN aligns the pointer towards the lower address( which would be weird ), that +2 might get out of bounds depending on how many bytes is ALIGNBYTES.
Please correct me if I'm wrong.
Edit:
This is the header that defines the struct FTSENT:
https://opensource.apple.com/source/Libc/Libc-1044.40.1/incl...
sizeof(FTSENT) + namelen + 1 + (padding + sizeof(struct stat))
(I Googled 'site:opensource.apple.com "#define ALIGNBYTES" inurl:.h' and got my query rewritten without the quotes and the dots in the domain name. No, I did NOT mean to search for anything else. Then I browsed to the 2nd page and got the "we detected suspicious activity" CAPTCHA. WTF?)https://opensource.apple.com/source/OpenSSH/OpenSSH-95/opens...
https://opensource.apple.com/source/xnu/xnu-792.13.8/bsd/ppc...
https://opensource.apple.com/source/sendmail/sendmail-32/sen...
They align toward the higher address.
The comment made in the code is incorrect:
Since the fts_name field is declared to be of size 1, the fts_name pointer is namelen + 2 before the first possible address of the stat structure.
namelen + 1 is the first possible address for the stat structure.
Even with just namelen+1 you can still get undefined behavior. This is because if namelen is shorter than the padding of the object struct FTSENT, the beginning of the next object struct stat, will overlap with the previous object.
The correct solution is to make sure that the next object begins after the first one, and still remains inside of the allocated block. This is a good example, why the struct hack just isn't worth it, and it itself is arguably undefined behavior.
To allocate it all, remove the struct hack and simply call the malloc three times, once for each struct and then for the string. If one allocation is required, then allocate enough memory for all three objects separated by enough alignment padding. Doing this will allocate a couple of bytes more which is a couple percent overall, but at least your code will be correct. Since they don't pack the struct thus loosing bytes for internal padding anyway, I can't understand why the usage of the struct hack.
[1] I especially liked this blog: http://photos.imgix.com/racking-mac-pros
[2] https://simbimbo.wordpress.com/2015/07/24/well-im-at-it-agai...
commercial ZIP software however usually limits the maximum depth and file path name to the lowest common denominator which is 250 chars for compatibility with Windows, some software will have a "unix" mode in which the max limit is increased to 1024.
They do not refuse, they cannot include it from a legal point of view.
Where exactly the border lies between and not linking is a grey area, legally, that hasn't become clearer with GPL3.
It wouldn't surprise me to see bash go from the standard install, too. Apple is slowly removing all GPL code from its OS.
I use ZSH as my main shell on OS X. I find it superior to bash in almost every way (especially with oh-my-zsh) except in ubiquity. Even so, I have no problem using bash if that's all that's available, the two shells are fairly compatible.
Tivoization was another issue, especially with Apple's tendency to lock down their platform.
Or are they worried about something else, like the patent clauses?
Apple refuse to do this. No one know for sure but the common suspicion is that they want to avoid competition by locking users to a single platform where apple has a artificial created monopoly.
One could be accused to think that the core products of Apple is the devices that they sells. What clause in GPLv3 require that they give devices out for free?
If you believe Linux is that much better, well, you really ought to follow your distribution's security announcement list. Nobody in the general computing space has a track record which entitles them to cast aspersions at the competition.
Also, this bug does not prove that the whole user space is completely broken. Many people use it daily without ever hitting these bugs. If you go looking for issues, you'll find them, just as you'll find them on Linux but in different places. Not to say this doesn't suck and we shouldn't fix them, but it's hardly proof of anything.
Considering handling paths is one of the most fundamental functions of the Unix tools and C library, having buffer overflows there is quite damning.