Discussion:
[ast-developers] Patch request for interactive ksh bug: "cannot execute [Exec format error]"
lijo george
2017-09-25 10:24:41 UTC
Permalink
Hi all,

This issue has been observed on a Solaris test system with the stable
version (2012-08-01).
I've verified that this has been fixed in the alpha/beta versions. Here's a
sample test case.

Could someone let me know if there is a bug/patch for this.

Create two files: a2 and b2
$ cat a2
AAA
BBB
CCCC
-x-x- end of file -x-x-

$ cat b2
1234
5432
AAAA
987
-x-x- end of file -x-x-

start ksh and run the following from ksh
## this does not fail if this is run as a script

$ PS1='$' ksh
$ cat a2 | while read a ; do
$>grep $a b2
$>done
AAAA
grep: grep: cannot execute [Exec format error]
grep: grep: cannot execute [Exec format error]

It looks like posix_spawn is failing for the "grep" command, which cases
posix_spawn() to return EPERM.
This causes ksh to interpret this as a script, leading to the observed
"Exec format error". Slightly confused as to why this is failing as the
posix_spawnattr_setpgroup returns 0 while setting the process
group id.
The latest versions which uses the spawnvex calls fixes this issue, though
I haven't looked into how it has been fixed.

Here's the dtrace snippet and output I used to trace the flow

dtrace -o path_spawn.out -n 'pid$target::path_spawn:entry {
self->path=arg1;printf("%s, %d", copyinstr(arg1),arg5);ustack(); }' -n
'pid$target::path_spawn:return { printf("%s : %d",copyinstr(self->path),
arg1); ustack();self->arg1 = 0; }' -n 'pid$target::_spawnveg:entry {
self->path1=arg1;printf("%s, %d", copyinstr(arg1),arg4);ustack(); }' -n
'pid$target::_spawnveg:return { printf("%s : %d",copyinstr(self->path1),
arg1);ustack(); self->path=0; }' -n 'pid$target::posix_spawn:entry {
printf("%s",copyinstr(arg1)); }' -n 'pid$target::posix_spawn:return{
printf("%d",arg1); }' -n 'pid$target::posix_spawnattr_setpgroup:entry {
printf("%d", arg1); }' -n 'pid$target::posix_spawnattr_setpgroup:return {
printf("%d", arg1); }' -p <PID>

0 85182 path_spawn:entry /usr/bin/grep, 5717
ksh`path_spawn
ksh`sh_ntfork+0x4b4
ksh`sh_exec+0x527c
ksh`sh_exec+0x175c
ksh`sh_exec+0x5d30
ksh`sh_exec+0xa40
a.out`exfile+0xaac
a.out`sh_main+0xbdc
a.out`main+0x3c
a.out`_start+0x17c

0 85180 _spawnveg:entry /usr/bin/grep, 2858
ksh`_spawnveg
ksh`path_spawn+0x588
ksh`sh_ntfork+0x4b4
ksh`sh_exec+0x527c
ksh`sh_exec+0x175c
ksh`sh_exec+0x5d30
ksh`sh_exec+0xa40
a.out`exfile+0xaac
a.out`sh_main+0xbdc
a.out`main+0x3c
a.out`_start+0x17c

0 85184 _spawnveg:entry /usr/bin/grep, 2858
ksh`_spawnveg
ksh`path_spawn+0x588
ksh`sh_ntfork+0x4b4
ksh`sh_exec+0x527c
ksh`sh_exec+0x175c
ksh`sh_exec+0x5d30
ksh`sh_exec+0xa40
a.out`exfile+0xaac
a.out`sh_main+0xbdc
a.out`main+0x3c
a.out`_start+0x17c

0 85188 posix_spawnattr_setpgroup:entry 2858
0 85189 posix_spawnattr_setpgroup:return 0
0 85186 posix_spawn:entry /usr/bin/grep
0 85187 posix_spawn:return 0
0 85181 _spawnveg:return /usr/bin/grep : 2859
ksh`_spawnveg+0x68
ksh`path_spawn+0x588
ksh`sh_ntfork+0x4b4
ksh`sh_exec+0x527c
ksh`sh_exec+0x175c
ksh`sh_exec+0x5d30
ksh`sh_exec+0xa40
a.out`exfile+0xaac
a.out`sh_main+0xbdc
a.out`main+0x3c
a.out`_start+0x17c

0 85185 _spawnveg:return /usr/bin/grep : 2859
ksh`_spawnveg+0x68
ksh`path_spawn+0x588
ksh`sh_ntfork+0x4b4
ksh`sh_exec+0x527c
ksh`sh_exec+0x175c
ksh`sh_exec+0x5d30
ksh`sh_exec+0xa40
a.out`exfile+0xaac
a.out`sh_main+0xbdc
a.out`main+0x3c
a.out`_start+0x17c

0 85178 path_spawn:entry /usr/bin/grep, 5717
ksh`path_spawn
ksh`sh_ntfork+0x4b4
ksh`sh_exec+0x527c
ksh`sh_exec+0x175c
ksh`sh_exec+0x5d30
ksh`sh_exec+0xa40
a.out`exfile+0xaac
a.out`sh_main+0xbdc
a.out`main+0x3c
a.out`_start+0x17c

0 85182 path_spawn:entry /usr/bin/grep, 5717
ksh`path_spawn
ksh`sh_ntfork+0x4b4
ksh`sh_exec+0x527c
ksh`sh_exec+0x175c
ksh`sh_exec+0x5d30
ksh`sh_exec+0xa40
a.out`exfile+0xaac
a.out`sh_main+0xbdc
a.out`main+0x3c
a.out`_start+0x17c

0 85180 _spawnveg:entry /usr/bin/grep, 2858
ksh`_spawnveg
ksh`path_spawn+0x588
ksh`sh_ntfork+0x4b4
ksh`sh_exec+0x527c
ksh`sh_exec+0x175c
ksh`sh_exec+0x5d30
ksh`sh_exec+0xa40
a.out`exfile+0xaac
a.out`sh_main+0xbdc
0 85188 posix_spawnattr_setpgroup:entry 2858
0 85189 posix_spawnattr_setpgroup:return 0
0 85186 posix_spawn:entry /usr/bin/grep
0 85187 posix_spawn:return 1
0 85181 _spawnveg:return /usr/bin/grep : -1
ksh`_spawnveg+0x68
ksh`path_spawn+0x588
ksh`sh_ntfork+0x4b4
ksh`sh_exec+0x527c
ksh`sh_exec+0x175c
ksh`sh_exec+0x5d30
ksh`sh_exec+0xa40
a.out`exfile+0xaac
a.out`sh_main+0xbdc
a.out`main+0x3c
a.out`_start+0x17c

0 85185 _spawnveg:return /usr/bin/grep : -1
ksh`_spawnveg+0x68
ksh`path_spawn+0x588
ksh`sh_ntfork+0x4b4
ksh`sh_exec+0x527c
ksh`sh_exec+0x175c
ksh`sh_exec+0x5d30
ksh`sh_exec+0xa40
a.out`exfile+0xaac
a.out`sh_main+0xbdc
a.out`main+0x3c
a.out`_start+0x17c

Thanks,
Lijo

Loading...