RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1895387 - telnet crashes on stack overflow due to infinite recursion
Summary: telnet crashes on stack overflow due to infinite recursion
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: telnet
Version: 8.3
Hardware: All
OS: Linux
medium
high
Target Milestone: rc
: 8.0
Assignee: Michal Ruprich
QA Contact: Patrik Moško
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-11-06 14:44 UTC by Renaud Métrich
Modified: 2024-03-25 16:58 UTC (History)
3 users (show)

Fixed In Version: telnet-0.17-76.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-05-18 15:38:11 UTC
Type: Bug
Target Upstream Version:
Embargoed:
pm-rhel: mirror+


Attachments (Terms of Use)
Possible patch (330 bytes, patch)
2020-11-12 15:27 UTC, Michal Ruprich
no flags Details | Diff

Description Renaud Métrich 2020-11-06 14:44:45 UTC
Description of problem:

When telnet's output is piped to some external process and that process exits, telnet gets a SIGPIPE and starts entering a recursion in signal handling, causing it to exhaust the stack then corrupt it.

This is present since RHEL6.


Version-Release number of selected component (if applicable):

telnet-0.17-73.el8_1.1.x86_64


How reproducible:

Always


Steps to Reproduce:

1. Execute "telnet localhost | cat"

  $ telnet localhost | cat

2. Kill "cat"

  # kill -9 <pid of cat>

Actual results:

cat dies, causing SIGPIPE to be received by telnet and telnet entering infinite recursion in signal handling code.


Expected results:

telnet not dying in segfault

Comment 2 Michal Ruprich 2020-11-09 12:15:29 UTC
Another reproducer is like this:
# telnet localhost | cat
(login)
# yes
y
y
y
...
(segfault)

Comment 3 Petr Sklenar 2020-11-11 11:25:53 UTC
qe triage:
reproducer is +- clear
but what should be new behavior? error message and end? warning and continue (2x cmd like cat, the first is killed ? )

# lets expect 22 is running sshd

telnet localhost 22 | cat &
kill -9 `pidof cat`

OLD: telnet crashed as coredumpctl list dump telnet
NEW: whats expected here ? telnet ends with error message?

Comment 4 Michal Ruprich 2020-11-11 13:23:57 UTC
Hi Petr,

I think that I would like to achieve the same behaviour that you get when you kill the server side. For instance if you run telnet without the pipeline and then kill the login process from another terminal, you get this:
# telnet localhost
Trying ::1...
Connected to localhost.
Escape character is '^]'.

Kernel 4.18.0-240.10.el8.x86_64 on an x86_64
ci-vm-10-0-137-223 login: Connection closed by foreign host.

I am working on this but still I am unsure how to fix this correctly.

Comment 5 Patrik Moško 2020-11-11 16:09:55 UTC
Scoped, as per discussion with Michal, setting ITM to 10.

I can see few potential ways of reproducing this so there shouldn't be any issue with providing reliable test.

Comment 6 Michal Ruprich 2020-11-12 15:26:09 UTC
So I get the gist of the problem here. Before the signal handler for SIGPIPE is set, sigsetjmp(peerdied, 1) is set on line 2509 in commands.c. When SIGPIPE is delivered by the system, function deadpeer is the handler and it calls the siglongjmp(peerdier, -1) so it should jump right after the sigsetjmp. The problem is that there is a buffer that tries to flush itself out before ending. But the other end is still broken so the SIGPIPE is raised again. That goes into a loop, calling the handler over and over.

The problem here might probably be in the signal() system call. It does not restore the default behaviour after signal has been raised. The sigsetjmp function is called before setting up the signal for SIGPIPE so I thought that the default behaviour for SIGPIPE should be restored when the jump is performed but it is not. I think that the solution should be to simply revert the handling to default directly in the handler so that if telnet tries to empty some buffer after the pipe is gone, it should die on the default SIGPIPE behaviour.

Comment 7 Michal Ruprich 2020-11-12 15:27:32 UTC
Created attachment 1728798 [details]
Possible patch

Comment 20 errata-xmlrpc 2021-05-18 15:38:11 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (telnet bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:1799

Comment 21 Red Hat Bugzilla 2023-09-15 00:50:49 UTC
The needinfo request[s] on this closed bug have been removed as they have been unresolved for 500 days


Note You need to log in before you can comment on or make changes to this bug.