[Toybox] Private security report: Two reproducible memory-corruption bugs in Toybox DHCPv6

Rob Landley rob at landley.net
Fri Oct 2 06:09:26 UTC 2026


And I got permission to cc the list...

On 9/29/26 06:26, Nikhil Nagpure wrote:
> Hello Rob,
> 
> I hope you're doing well!
> 
> I've been exploring Toybox's source code and found two reproducible
> memory-corruption issues in the pending DHCPv6 implementation.

There's a reason the code's in pending and not in defconfig. :)

https://codeberg.org/landley/toybox/src/branch/master/toys/pending/README

> I'd be happy to share the exact tested revisions, complete sanitizer
> output, and minimal reproducers so you can verify both findings. Please let
> me know your preferred channel for receiving the detailed reports and way
> to resolve these bugs.

My very vague plan is to do extensive cleanup on both commands along the 
lines of https://landley.net/toybox/cleanup.html but they're not 
blockers for the 1.0 release (because you don't need them in the $PATH 
to boot/rebuild mkroot, run mcm-buildall.sh, or build linux from scratch 
12.4). So they're "nice to have" but not "blocking 1.0" like the sh.c.

> A little about me: I'm a computer science graduate specializing in
> cybersecurity and digital forensics, and I'm actively working to deepen my
> experience in Linux, systems programming, infrastructure, and security
> engineering. I've been getting more involved in open source recently, and
> I'm genuinely excited to learn from experienced maintainers, contribute
> meaningful fixes, and work on real-world systems security problems.

Cool.

A completely random example of the kind of cleanup this command needs, 
based on opening dhcpd.c, hitting page down a few times, and seeing what 
was under the cursor:

   switch (flag) {
   case DHCP_NUM32:
     options_list[count].len = sizeof(uint32_t);
     options_list[count].val = xmalloc(sizeof(uint32_t));
     strtou32(valstr, &convtmp);
     memcpy(options_list[count].val, &convtmp, sizeof(uint32_t));
     break;
   case DHCP_NUM16:
     options_list[count].len = sizeof(uint16_t);
     options_list[count].val = xmalloc(sizeof(uint16_t));
     strtou32(valstr, &convtmp);
     memcpy(options_list[count].val, &convtmp, sizeof(uint16_t));
     break;
   case DHCP_NUM8:
     options_list[count].len = sizeof(uint8_t);
     options_list[count].val = xmalloc(sizeof(uint8_t));
     strtou32(valstr, &convtmp);
     memcpy(options_list[count].val, &convtmp, sizeof(uint8_t));
     break;

what are those #defined constants...

#define DHCP_NUM8           (1<<8)
#define DHCP_NUM16          (1<<9)
#define DHCP_NUM32          DHCP_NUM16 | DHCP_NUM8

Ok, all of that is basically (off the top of my head, not tested):

if ((temp = flag>>8)&3) {
   options_list[count].len = temp = ((char[]){1, 2, 4})[--temp];
   options.list[count].val = xmalloc(temp);
   strtou32(valstr, &convtmp);
   memcpy(options_list[count].val, &convtmp, temp);
}

Which is still twice the size it needs to be because why are we doing 
&convtmp (should that just be toybuf) and why the HELL is it mallocing 
such TINY AMOUNTS OF MEMORY and then dereferencing a pointer to it when 
the pointer is bigger than the memory... But that transform presumably 
cuts out a chunk of repetitive code without changing the behavior, 
modulo thinkos.

It probably needs hundreds of passes of doing that, and the end result 
should shrink as much as ifconfig did in the cleanup.html page.

(Oh, and both of the above only work little endian. Could we maybe just 
ASSIGN the values instead of doing memcpy on an integer value please?)

> I'm also actively exploring professional opportunities to grow and learn in
> cybersecurity, Linux, infrastructure, and DevSecOps. If you happen to know
> of any relevant opportunities, projects, or communities where someone with
> my background could contribute and grow, I'd be very grateful for any
> pointers. Regardless, I'd love to keep learning and contributing to
> projects like Toybox.
> 
> Thank you for your time and for maintaining Toybox. I'm looking forward to
> sharing the detailed findings and hopefully contributing further!

Don't worry about any security leaks for pending code, if it's in 
pending they get to keep the pieces. I'm happier having this kind of 
discussion on the mailing list. (Can I post this reply there?)

> Best regards,
> Nikhil Nagpure
> github.com/5h4d0wn1k

Thanks,

Rob


More information about the Toybox mailing list