[OmniOS-discuss] LX: real ksh93 broken

Ludovic Orban lorban at bitronix.be
Fri May 12 08:25:32 UTC 2017


The real root cause is a plain old overflow bug in ksh, happening at that
line:
 https://github.com/att/ast/blob/master/src/cmd/ksh93/sh/jobs.c#L1869

because of the way the BYTE macro has been written:
 https://github.com/att/ast/blob/master/src/cmd/ksh93/sh/jobs.c#L101

Check this small example:

#include <stdio.h>
#include <limits.h>

#define BYTE(n)         (((n)+CHAR_BIT-1)/CHAR_BIT)

int main()
{
int i = BYTE(INT_MAX);
printf("i = %d\n", i);
}

and here is what clang warns about when you try to compile it (both 64bit
and 32bit give the exact same result):

test.c:8:10: warning: overflow in expression; result is -2147483641 with
type 'int' [-Winteger-overflow]
        int i = BYTE(INT_MAX);
                ^
test.c:4:30: note: expanded from macro 'BYTE'
#define BYTE(n)         (((n)+CHAR_BIT-1)/CHAR_BIT)
                             ^
1 warning generated.

and when you execute it, you get:

i = -268435455

In the end, the fact that BYTE() returns a negative value completely messes
up the logic in job_alloc() that doesn't guard against that. From there on,
hell starts freezing over and ksh misbehaves randomly as it believes it
cannot allocate a job while it did.

After all, my opinion is that there's no bug in LX, no bug in OmniOS, but
defaulting to INT_MAX for zone.max-lwps is IMHO a mistake. It sounds more
logical to me to default to the global zone's value of
sysconf(_SC_CHILD_MAX).

--
Ludovic



On Thu, May 11, 2017 at 4:33 PM, Michael Rasmussen <mir at miras.org> wrote:

> On Thu, 11 May 2017 11:11:14 +0200
> Ludovic Orban <lorban at bitronix.be> wrote:
>
> >
> > Apparently, ksh isn't very happy when CHILD_MAX equals to MAX_INT, but
> > that's probably a ksh bug.
> >
> Could it be ksh interprets int as it was defined in the 32bit OS days
> int = 16bit = INT_MAX 32767 and expecting to receive a signed
> int?
>
> This is obviously wrong since ISO/IEC 9899 only requires an int to be
> at least 2^16 - 1. INT_MAX is defined in limits.h
>
> --
> Hilsen/Regards
> Michael Rasmussen
>
> Get my public GnuPG keys:
> michael <at> rasmussen <dot> cc
> http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xD3C9A00E
> mir <at> datanom <dot> net
> http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE501F51C
> mir <at> miras <dot> org
> http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xE3E80917
> --------------------------------------------------------------
> /usr/games/fortune -es says:
> Witch!  Witch!  They'll burn ya!
>                 -- Hag, "Tomorrow is Yesterday", stardate unknown
>
> _______________________________________________
> OmniOS-discuss mailing list
> OmniOS-discuss at lists.omniti.com
> http://lists.omniti.com/mailman/listinfo/omnios-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://omniosce.org/ml-archive/attachments/20170512/ab1d6fcc/attachment.html>


More information about the OmniOS-discuss mailing list