Skip to content

Telnet shell asserts if connection is closed #67637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jukkar opened this issue Jan 15, 2024 · 10 comments · Fixed by #78976
Closed

Telnet shell asserts if connection is closed #67637

jukkar opened this issue Jan 15, 2024 · 10 comments · Fixed by #78976
Assignees
Labels
area: Shell Shell subsystem bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@jukkar
Copy link
Member

jukkar commented Jan 15, 2024

Describe the bug

Some extra discussion about the issue can be found in PR #67596, basically telnet shell asserts if telnet connection is closed.
If asserts are disabled no visible error was seen, but according to the code in

void z_shell_write(const struct shell *sh, const void *data,

the internal variables in the z_shell_write() could contain invalid values which could corrupt internal state of the shell.

To Reproduce
Setup the network by executing tools/net-tools/net-setup.sh that is found in net-tools zephyr project.

west build -p -b native_sim samples/net/telnet/ -d ../build/telnet \
  -t run -- -DCONFIG_ASSERT=y -DCONFIG_NATIVE_UART_0_ON_STDINOUT=y \
  -DCONFIG_LOG_BACKEND_UART=y -DCONFIG_SHELL_LOG_BACKEND=n

and then execute echo x | telnet 192.0.2.1 from the host.

Expected behavior
The telnet connection is closed without any errors / crashes.

Impact
If the asserts are enabled, the crashing of the system is not necessary as we just closed the connection.
If the asserts are disabled, the internal state of the shell might cause corruption.

Logs and console output

*** Booting Zephyr OS build zephyr-v3.5.0-4132-gf37d150c1052 ***

uart:~$ ASSERTION FAIL [err == 0] @ WEST_TOPDIR/zephyr/subsys/shell/shell_ops.c:438
@ WEST_TOPDIR/zephyr/lib/os/assert.c:43
Exiting due to fatal error

Environment (please complete the following information):

  • OS: Linux
  • Commit SHA or Version used: zephyr-v3.5.0-4132-gf37d150c1052
@jukkar jukkar added bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug area: Shell Shell subsystem labels Jan 15, 2024
Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions bot added the Stale label Mar 16, 2024
@aescolar aescolar added priority: low Low impact/importance bug and removed priority: medium Medium impact/importance bug Stale labels Mar 19, 2024
Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions bot added the Stale label May 19, 2024
@jukkar jukkar removed the Stale label May 19, 2024
Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions bot added the Stale label Jul 19, 2024
@jukkar jukkar removed the Stale label Jul 19, 2024
Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions bot added the Stale label Sep 18, 2024
@kevinior
Copy link
Contributor

This issue is still present in the rewritten telnet server in 3.7.0:
ASSERTION FAIL [err == 0] @ WEST_TOPDIR/zephyr/subsys/shell/shell_ops.c:438

As a result we're having to maintain a patched version of the telnet server that returns 0 when the connection closes, to avoid crashing our whole application.

@jukkar jukkar removed the Stale label Sep 24, 2024
@jukkar
Copy link
Member Author

jukkar commented Sep 24, 2024

@kevinior if you have a patch for this, could you submit a PR for it?

@kevinior
Copy link
Contributor

@kevinior if you have a patch for this, could you submit a PR for it?

We just patched the telnet_write function to always return 0 and log some diagnostics about errors. I don't know if that would be an acceptable fix for others.

@jukkar
Copy link
Member Author

jukkar commented Sep 25, 2024

We just patched the telnet_write function to always return 0 and log some diagnostics about errors. I don't know if that would be an acceptable fix for others.

Yeah, that sounds a bit hackish to me. But you could try to send it still, the review could give ideas how to solve it better.

@kevinior
Copy link
Contributor

@jukkar OK, I've created a PR for the hackish fix.

@kevinior
Copy link
Contributor

kevinior commented Oct 9, 2024

@jukkar No responses to the PR so far

kevinior added a commit to kevinior/zephyr that referenced this issue Oct 10, 2024
The code in shell_ops.c that calls telnet_write will assert if it
returns non-zero. For a telnet shell it's normal that the
network might disconnect unexepectedly, so that should not
trigger an assert.

Fixes zephyrproject-rtos#67637

Link: zephyrproject-rtos#67637

Signed-off-by: Kevin ORourke <[email protected]>
@nashif nashif closed this as completed in 3399e06 Oct 11, 2024
coreboot-bot pushed a commit to coreboot/zephyr-cros that referenced this issue Oct 12, 2024
The code in shell_ops.c that calls telnet_write will assert if it
returns non-zero. For a telnet shell it's normal that the
network might disconnect unexepectedly, so that should not
trigger an assert.

Fixes #67637

(cherry picked from commit 3399e06)

Original-Link: zephyrproject-rtos/zephyr#67637
Original-Signed-off-by: Kevin ORourke <[email protected]>
GitOrigin-RevId: 3399e06
Cr-Build-Id: 8734380568354140561
Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8734380568354140561
Copybot-Job-Name: zephyr-main-copybot-downstream
Change-Id: I4f40ac58f0ee844e4dff85196727fd3b4f56939d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5925541
Commit-Queue: Jeremy Bettis <[email protected]>
Tested-by: ChromeOS Prod (Robot) <[email protected]>
Tested-by: Jeremy Bettis <[email protected]>
Reviewed-by: Jeremy Bettis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Shell Shell subsystem bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants