Any single failed connection killed the whole daemon:
- A peer that resets before the accept completes (a port scanner, or a
simple "nc -z" probe) surfaces as an accept4() error such as
ECONNABORTED, which took the errout path and closed the listener.
- The per-connection error paths after a successful accept (setsockopt,
opening /dev/telnet, SIOCTELNET, opening the session device, spawning
the session) likewise exited the daemon instead of dropping the one
connection.
Either way, one bad or aborted connection and the telnet console is
dead until reboot - a trivial remote way to take out the NuttX console
on any reachable network. Verified on hardware: one "nc -zv" probe
permanently killed the listener.
Treat these as per-connection failures: drop the connection and keep
accepting. Genuinely unrecoverable accept4() errors (EBADF, ENOTSOCK,
EINVAL, EOPNOTSUPP - a bad listen socket) still exit loudly, and a
short pause on repeated transient failures avoids busy-spinning while
an interface is down. Daemon setup errors (socket/bind/listen) exit
as before.
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Ricard Rosson <ricard@groundbits.com>
When telnetd_daemon() starts without open standard streams - exactly
what happens when nsh_telnetstart() spawns "telnetd &" before the
console device exists (e.g. CONFIG_NSH_USBCONSOLE boards, where
nsh_initialize() runs before the USB console is connected) - socket()
returns a descriptor in the 0..2 range. The accept loop's own "go
silent" close(0)..close(2) then destroys the listen socket on the
first iteration: every subsequent accept4() fails with EBADF and the
daemon serves nothing.
Observed on hardware (RP2350, CDC-ACM console + CDC-NCM composite):
the daemon task was alive but port 23 refused every connection; the
thread list showed it looping on the failed accept. Duplicate the
descriptor above the standard-stream range before using it.
Assisted-by: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Ricard Rosson <ricard@groundbits.com>
Replace app-side includes of <debug.h> with <nuttx/debug.h> to use the
header from the NuttX tree explicitly after the header move.
Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
Fix dependency issue when signals are partially or fully enabled
Co-authored-by: guoshichao <guoshichao@xiaomi.com>
Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
Summary:
- This commit makes telnetd_daemon() in public so that we
can call it from applications.
- Also, adds new configs to support posix_spawnp()
Impact:
- telnetd only
Testing:
- Tested with sabre-6quad:netknsh (will be updated later)
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
Gregory Nutt is has submitted the SGA
Sebastien Lorquet has submitted the ICLA
as a result we can migrate the licenses to Apache.
Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
Gregory Nutt is the copyright holder for those files and he has submitted the
SGA as a result we can migrate the licenses to Apache.
Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
Recent change from Xiao Xiang enabled the SO_REUSEADDR socket option unconditionally. This, of course, causes link time failures if socket options are not enabled:
apps/netutils/telnetd/telnetd_daemon.c:182: undefined reference to 'setsockopt'.
Observed during build testing with configuration rddrone-uavcan144:nsh
1.Remove void cast for function because many place ignore the returned value witout cast
2.Replace void cast for variable with UNUSED macro
Change-Id: Ie644129a563244a6397036789c4c3ea83c4e9b09
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>