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 2123066 - ksh segfault when PWD is unset.
Summary: ksh segfault when PWD is unset.
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 9
Classification: Red Hat
Component: ksh
Version: 9.0
Hardware: All
OS: Linux
medium
medium
Target Milestone: rc
: ---
Assignee: Vincent Mihalkovič
QA Contact: Karel Volný
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-08-31 16:29 UTC by Paulo Andrade
Modified: 2023-11-07 10:07 UTC (History)
1 user (show)

Fixed In Version: ksh-1.0.0~beta.1-3.el9
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-11-07 08:37:11 UTC
Type: Bug
Target Upstream Version:
Embargoed:
pm-rhel: mirror+


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github ksh93/ksh/commit/11177d448dadc7f8300e1db60c4ea5bdd61f13e0 0 None None None 2023-05-24 16:35:27 UTC
Red Hat Issue Tracker RHELPLAN-132887 0 None None None 2022-08-31 16:30:22 UTC
Red Hat Product Errata RHBA-2023:6561 0 None None None 2023-11-07 08:37:13 UTC

Description Paulo Andrade 2022-08-31 16:29:07 UTC
Minimal reproducer:

$ unset PWD
$ $(cd)

  The crash is simple. Testing in Fedora with the same ksh version:

Program received signal SIGSEGV, Segmentation fault.
0x00005555555d2227 in test_stat (name=0x0, buff=buff@entry=0x7fffffffb890) at /usr/src/debug/ksh-1.0.0~beta.1-1.fc35.x86_64/src/cmd/ksh93/bltins/test.c:716
716		if(*name==0)
711	/*
712	 * do an fstat() for /dev/fd/n, otherwise stat()
713	 */
714	static int test_stat(const char *name,struct stat *buff)
715	{
716		if(*name==0)
717		{
718			errno = ENOENT;
719			return(-1);
720		}

  A blind patch would be the pseudo patch:

-		if(*name==0)
+		if(name && *name==0)

but this likely would cause problems elsewhere.

(gdb) p pwdnod
$1 = (Namval_t *) 0x5555556ce220
(gdb) p pwdnod.nvalue
$2 = {cp = 0x0, ip = 0x0, c = 0 '\000', i = 0, u = 0, lp = 0x0, pidp = 0x0, llp = 0x0, s = 0, sp = 0x0, dp = 0x0, ldp = 0x0, array = 0x0, np = 0x0, up = 0x0, rp = 0x0, funp = 0x0, nrp = 0x0, bfp = 0x0}

This should only happen when PWD is not set, and in the code:

"""
	/*
	 * If sh_subshell() in subshell.c cannot use fchdir(2) to restore the PWD using a saved file descriptor,
	 * we must fork any virtual subshell now to avoid the possibility of ending up in the wrong PWD on exit.
	 */
	if(shp->subshell && !shp->subshare)
	{
#if _lib_fchdir
		if(!test_inode(nv_getval(pwdnod),e_dot))
#endif
			sh_subfork();
	}
	/*
"""

in src/cmd/ksh93/bltins/cd_pwd.c

  The PWD environment variable is set again when the 'cd' command finishes,
as noted in:

$ cd --man 
...

  When cd is successful, the PWD environment variable will be set to the name
  of an absolute pathname that does not contain any .. components corresponding
  to the new directory. The environment variable OLDPWD will be set to the
  previous value of PWD. If the new directory is found by searching the
  directories named by CDPATH, or if directory is -, or if the two operand form
  is used, the new value of PWD will be written to standard output.
...

  A patch should require deciding what to do to remediate the issue;
possibly setting again PWD to the current directory (if it is available).

Comment 2 Lukáš Zaoral 2023-05-24 16:35:28 UTC
This is a request to backport the following upstream commit: https://github.com/ksh93/ksh/commit/11177d448dadc7f8300e1db60c4ea5bdd61f13e0

Comment 10 errata-xmlrpc 2023-11-07 08:37: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 (ksh 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-2023:6561


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