Skip to content
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

SSH crashes FN device when trying to close a session #621

Open
markjfisher opened this issue Jun 27, 2023 · 0 comments
Open

SSH crashes FN device when trying to close a session #621

markjfisher opened this issue Jun 27, 2023 · 0 comments

Comments

@markjfisher
Copy link
Contributor

Using netcat with ssh to a machine, when the session completes, the fujinet crashes:

21:04:25.731 > [2023/06/27 21:04:23.975347, 1] ssh_packet_userauth_failure:  Access denied for 'password'. Authentication that can continue: publickey,password
21:04:25.732 > [2023/06/27 21:04:23.975978, 2] ssh_packet_userauth_failure:  Access denied for 'password'. Authentication that can continue: publickey,password
21:04:25.733 > NetworkProtocolSSH::open() - Unable to authorise with given password, error: Access denied for 'password'. Authentication that can continue: publickey,password.
21:04:25.738 >
21:04:25.738 > assert failed: heap_caps_free heap_caps.c:351 (heap != NULL && "free() target pointer is outside heap areas")
21:04:25.739 >
21:04:25.739 >
21:04:25.739 > Backtrace: 0x4008425d:0x3ffd9ab0 0x40092d55:0x3ffd9ad0 0x40099ef9:0x3ffd9af0 0x400852f7:0x3ffd9c20 0x40099f29:0x3ffd9c40 0x40217cba:0x3ffd9c60 0x401d0066:0x3ffd9c80 0x400e0344:0x3ffd9cb0 0x400de862:0x3ffd9cf0 0x400ef14d:0x3ffd9d10 0x400ef26b:0x3ffd9d50 0x400d2ca4:0x3ffd9d70 0x40096b15:0x3ffd9d90
21:04:25.887 >
21:04:25.887 >   #0  0x4008425d:0x3ffd9ab0 in panic_abort at /home/fenrock/.platformio/packages/framework-espidf/components/esp_system/panic.c:423
21:04:25.887 >   #1  0x40092d55:0x3ffd9ad0 in esp_system_abort at /home/fenrock/.platformio/packages/framework-espidf/components/esp_system/esp_system.c:153
21:04:25.887 >   #2  0x40099ef9:0x3ffd9af0 in __assert_func at /home/fenrock/.platformio/packages/framework-espidf/components/newlib/assert.c:78
21:04:25.887 >   #3  0x400852f7:0x3ffd9c20 in heap_caps_free at /home/fenrock/.platformio/packages/framework-espidf/components/heap/heap_caps.c:351 (discriminator 1)
21:04:25.887 >   #4  0x40099f29:0x3ffd9c40 in free at /home/fenrock/.platformio/packages/framework-espidf/components/newlib/heap.c:39
21:04:25.887 >   #5  0x40217cba:0x3ffd9c60 in ssh_free at lib/libssh/src/session.c:310 (discriminator 1)
21:04:25.887 >   #6  0x401d0066:0x3ffd9c80 in NetworkProtocolSSH::open(EdUrlParser*, cmdFrame_t*) at lib/network-protocol/SSH.cpp:154
21:04:25.887 >   #7  0x400e0344:0x3ffd9cb0 in sioNetwork::sio_open() at lib/device/sio/network.cpp:120
21:04:25.887 >   #8  0x400de862:0x3ffd9cf0 in sioNetwork::sio_process(unsigned long, unsigned char) at lib/device/sio/network.cpp:799
21:04:25.887 >   #9  0x400ef14d:0x3ffd9d10 in systemBus::_sio_process_cmd() at lib/bus/sio/sio.cpp:233
21:04:25.887 >   #10 0x400ef26b:0x3ffd9d50 in systemBus::service() at lib/bus/sio/sio.cpp:341
21:04:25.887 >   #11 0x400d2ca4:0x3ffd9d70 in fn_service_loop(void*) at src/main.cpp:324 (discriminator 1)
21:04:25.887 >   #12 0x40096b15:0x3ffd9d90 in vPortTaskWrapper at /home/fenrock/.platformio/packages/framework-espidf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154

The above is a log for when the password is wrong, which closes the session at the end, so it's easy to reproduce. Also happens after a successful connection, then terminating the connection.

The part that's failing is trying to free memory for the known_hosts file, which I didn't implement.
So there are logs mentioning it trying to use the known hosts earlier:

21:04:20.506 > [2023/06/27 21:04:18.751251, 1] ssh_known_hosts_read_entries:  Failed to open the known_hosts file '': No such file or directory
21:04:20.507 > [2023/06/27 21:04:18.751907, 1] ssh_known_hosts_read_entries:  Failed to open the known_hosts file '': No such file or directory

And the code mentioned above is trying to safely free the memory, but clearly something is wrong:

// line 310 session.c:
  SAFE_FREE(session->opts.knownhosts);

which is mentioned in the crash log.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant