3 ms·
The article references http://www.opensource.apple.com/source/Libc/Libc-1044.40.1/gen/fts.c http://www.opensource.apple.com/source/Libc/Libc-1044.40.1/g... but
by userbinator 11y ago
The article references http://www.opensource.apple.com/source/Libc/Libc-1044.40.1/gen/fts.c http://www.opensource.apple.com/source/Libc/Libc-1044.40.1/g... but there's nothing that particularly stands out as being the bug at a quick glance and it is designed to handle arbitrarily deep hierarchies; nonetheless this looks like an off-by-one to me (in fts_alloc):
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.
- deleted 11y ago[deleted]
- pixelbeat 11y agoThere have been a couple of recent changes to the latest GNU version of that related to flexible array members: https://github.com/coreutils/gnulib/blame/master/lib/fts.c#L1901 https://github.com/coreutils/gnulib/blame/master/lib/fts.c#L... https://github.com/coreutils/gnulib/commit/49078a78 https://github.com/coreutils/gnulib/commit/49078a78
- just_curioussss 11y agoThis part is also suspicious: 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/include/fts.h https://opensource.apple.com/source/Libc/Libc-1044.40.1/incl...
- userbinator 11y agoALIGNBYTES is probably 3 or 7, depending on what ALIGN does, but the +2 seems like a bug to me. I think the intended layout is [FTSENT][name][0][optional [possible alignment padding][struct stat]] which means that +2 should really be a +1. The total memory allocated should be 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?)
- deleted 11y ago[deleted]
- just_curioussss 11y agoI found a couple different definitions: https://opensource.apple.com/source/OpenSSH/OpenSSH-95/openssh/defines.h https://opensource.apple.com/source/OpenSSH/OpenSSH-95/opens... https://opensource.apple.com/source/xnu/xnu-792.13.8/bsd/ppc/param.h https://opensource.apple.com/source/xnu/xnu-792.13.8/bsd/ppc... https://opensource.apple.com/source/sendmail/sendmail-32/sendmail/libsm/local.h?txt https://opensource.apple.com/source/sendmail/sendmail-32/sen... They align toward the higher address.
- anonbanker 11y agoso the +2 is indeed out of bounds?
- just_curioussss 11y agoDepending on the value of namelen, and the padding at the end of the struct FTSENT, struct p->fts_statp will occupy one byte out of bounds of the allocated memory. 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.
- raimue 11y agoInterestingly, this is actually the Libc code of OS X 10.10.5 Yosemite. Source code for OS X 10.11 El Capitan has not yet been released by Apple.