Bug 2053503

Summary: Please change struct stk sktref field type from short to int [rhel-7.9.z]
Product: Red Hat Enterprise Linux 7 Reporter: Paulo Andrade <pandrade>
Component: kshAssignee: Vincent Mihalkovič <vmihalko>
Status: CLOSED ERRATA QA Contact: Karel Volný <kvolny>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.9CC: amkulkar, kpfleming, svashisht
Target Milestone: rcKeywords: Reopened, Triaged, ZStream
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: ksh-20120801-144.el7_9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2116372 (view as bug list) Environment:
Last Closed: 2022-08-09 11:51:28 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2116372    

Description Paulo Andrade 2022-02-11 12:52:07 UTC
Copy&paste of the requested patch:

"""
diff -up ksh-20120801/src/lib/libast/misc/stk.c.orig ksh-20120801/src/lib/libast/misc/stk.c
--- ksh-20120801/src/lib/libast/misc/stk.c.orig	2022-01-31 16:06:11.923069379 -0300
+++ ksh-20120801/src/lib/libast/misc/stk.c	2022-01-31 16:06:54.896802455 -0300
@@ -76,7 +76,7 @@ struct frame
 struct stk
 {
 	_stk_overflow_	stkoverflow;	/* called when malloc fails */
-	short		stkref;	/* reference count; */
+	int		stkref;	/* reference count; */
 	short		stkflags;	/* stack attributes */
 	char		*stkbase;	/* beginning of current stack frame */
 	char		*stkend;	/* end of current stack frame */
"""

  In bz#2007364 we had ksh patched to use the stack robustness
patch. It "almost" corrected the problem for a customer.

  Unfortunately, it still kept crashing on average once every
day. Customer is experimenting with a "guess" package with the
above patch, and it is already more than 2 days without a crash.
So, it should have had some side effect.
  Optionally, the code could be reviewed to check when the stkref
field is increased/decreased and catch a wrap around before it
happens.

Comment 3 Vincent Mihalkovič 2022-03-01 15:39:53 UTC
The requested patch is related to this change https://github.com/ksh93/ksh/commit/56805b25af24f454cdd477609bcddc984628bc01#diff-743671e15792442098dcd4e1d0800309eafe0f038f7d07bb9074034b83298d85R79,
from upstream commit https://github.com/ksh93/ksh/commit/56805b25af24f454cdd477609bcddc984628bc01:
"... Make the stack more resilient by extending the stack reference
  counter 'stkref' from (signed) short to unsigned int. On modern
  systems with 32-bit ints, this extends the maximum number of
  elements on a stack from 2^15-1==32767 to 2^32-1==4294967295.
  The ref counter can never be negative, so there is no reason for
  signedness. sizeof(int) is defined as the size of a single CPU
  word, so this should not affect performance at all.
     On a 16-bit system (not that ksh still compiles there), this
  doubles the max number of entries to 2^16-1=65535."

So I slightly modified requested patch (I used unsigned int instead of int):
Here is scratch-build: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=43451843
and private-branch: http://pkgs.devel.redhat.com/cgit/rpms/ksh/commit/?h=private-vmihalko-rhel-7.9-bz2053503&id=339ae13cafcae16f0ec43dc48898610c568270b6

Comment 16 errata-xmlrpc 2022-08-09 11:51:28 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-2022:5938