Subject: Re: PR 36963
To: Jordan Gordeev <jgordeev@dir.bg>
From: Jan Danielsson <jan.m.danielsson@gmail.com>
List: tech-kern
Date: 09/19/2007 15:16:47
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Jordan Gordeev wrote:
> One good way to collect more information would be to use ktrace or truss.

I used this program:
- ------------------
#include <stdio.h>
#include <dirent.h>
#include <string.h>

int main(void)
{
	DIR *dirp = opendir(".");
	if (dirp != NULL)
	{
		puts("Success!");
		(void)closedir(dirp);
	}
	else
	{
		puts("Error!");
	}
	return 0;
}
- ------------------

   I compiled it, and stored it in /tmp/permtest. (Don't mind the
#include <string.h>).

   This is the complete session, and dumps:

nl102-238-202# su - pkgsrc
$ ls -l
ls: .: Permission denied
$ pwd
/home/pkgsrc
$ whoami
pkgsrc
$ user info pkgsrc
login   pkgsrc
passwd  *
uid     1001
groups  users
change  NEVER
class
gecos
dir     /home/pkgsrc
shell   /bin/ksh
expire  NEVER
$ ktrace -f /tmp/fail.out -t A /tmp/permtest
Error!

   Here I simply switched to a full screen session, and logged in and
out my normal "jan" user, switched back to X, but did *nothing* else.

$ ls -l
total 152
- -rwx------     1 pkgsrc  users    219 Sep  8 20:51 checkout_pkgsrc
- -rwx------     1 pkgsrc  users    282 Jun 18 04:31 checkout_wip
- -rwx------     1 pkgsrc  users    173 Sep  8 20:51 update_pkgsrc
- -rwx------     1 pkgsrc  users    158 Jun 18 05:15 update_wip
drwxr-xr-x  1797 pkgsrc  users  68608 Aug 11 16:41 wip
$ ktrace -f /tmp/success.out -t A /tmp/permtest
Success!

   Here I switched to my normal user "jan" (It shouldn't matter, but I'm
mentioning it for the record) to run "kdump".

$ kdump -x /tmp/fail.out
 10426      1 ktrace   EMUL  "netbsd"
 10426      1 ktrace   CALL
execve(0x7f7fffffeeb5,0x7f7fffffed68,0x7f7fffffed78)
 10426      1 ktrace   NAMI  "/tmp/permtest"
 10426      1 ktrace   NAMI  "/usr/libexec/ld.elf_so"
 10426      1 ktrace   ARG   "/tmp/permtest"
 10426      1 ktrace   ENV   "_=/usr/bin/ktrace"
 10426      1 ktrace   ENV   "PAGER=more"
 10426      1 ktrace   ENV
"PATH=/home/pkgsrc/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/pkg/bin:/usr/pkg/sbin:/usr/g\
	ames:/usr/local/bin:/usr/local/sbin"
 10426      1 ktrace   ENV   "SHELL=/bin/ksh"
 10426      1 ktrace   ENV   "EDITOR=vi"
 10426      1 ktrace   ENV   "SU_FROM=root"
 10426      1 ktrace   ENV   "USER=pkgsrc"
 10426      1 ktrace   ENV   "HOME=/home/pkgsrc"
 10426      1 ktrace   ENV   "TERM=screen"
 10426      1 ktrace   ENV   "EXINIT=set autoindent"
 10426      1 ktrace   ENV   "LOGNAME=pkgsrc"
 10426      1 permtest EMUL  "netbsd"
 10426      1 permtest RET   execve JUSTRETURN
 10426      1 permtest CALL  mmap(0,0x8000,3,0x1002,0xffffffff,0,0)
 10426      1 permtest RET   mmap 140187698954240/0x7f7ffdff8000
 10426      1 permtest CALL  open(0x7f7ffde0a82e,0,0x7f7ffde0a82e)
 10426      1 permtest NAMI  "/etc/ld.so.conf"
 10426      1 permtest RET   open -1 errno 2 No such file or directory
 10426      1 permtest CALL  open(0x7f7fffffe5d8,0,0xfefefefeff31302d)
 10426      1 permtest NAMI  "/usr/lib/libc.so.12"
 10426      1 permtest RET   open 3
 10426      1 permtest CALL  __fstat30(3,0x7f7fffffe508)
 10426      1 permtest RET   __fstat30 0
 10426      1 permtest CALL  mmap(0,0x1000,1,1,3,0x7f7f00000000,0)
 10426      1 permtest RET   mmap 140187698950144/0x7f7ffdff7000
 10426      1 permtest CALL  munmap(0x7f7ffdff7000,0x1000)
 10426      1 permtest RET   munmap 0
 10426      1 permtest CALL
mmap(0,0x207000,5,0x14000002,3,0x7f7f00000000,0)
 10426      1 permtest RET   mmap 140187693744128/0x7f7ffdb00000
 10426      1 permtest CALL
mmap(0x7f7ffdceb000,0xb000,3,0x12,3,0x7f7f00000000,0xeb000)
 10426      1 permtest RET   mmap 140187695755264/0x7f7ffdceb000
 10426      1 permtest CALL
mmap(0x7f7ffdcf6000,0x11000,3,0x1012,0xffffffff,0x7f7f00000000,0)
 10426      1 permtest RET   mmap 140187695800320/0x7f7ffdcf6000
 10426      1 permtest CALL  mprotect(0x7f7ffdbeb000,0x100000,0)
 10426      1 permtest RET   mprotect 0
 10426      1 permtest CALL  close(3)
 10426      1 permtest RET   close 0
 10426      1 permtest CALL
__sysctl(0x7f7fffffecb0,2,0x7f7ffdcfa320,0x7f7fffffeca8,0,0)
 10426      1 permtest MIB   1.81
 10426      1 permtest GIO   read 64 bytes
	000   ff ed bd ba da f6 a8 0a  6f 50 d1 93 da 18 dc c3 ........oP......
	010   af 7d 55 b7 aa 93 9e 85  71 9d d4 51 a4 c5 35 94 .}U.....q..Q..5.
	020   eb 03 11 ac 73 bf 67 94  6b 0d f6 0b 32 62 9d 4f ....s.g.k...2b.O
	030   c8 e5 b2 1e d2 71 69 ed  5b d6 e2 86 a8 02 61 cb .....qi.[.....a.
 10426      1 permtest RET   __sysctl 0
 10426      1 permtest CALL  open(0x400a99,4,0x7f7fffffed98)
 10426      1 permtest NAMI  "."
 10426      1 permtest RET   open 3
 10426      1 permtest CALL  fcntl(3,2,1)
 10426      1 permtest RET   fcntl 0
 10426      1 permtest CALL  __fstat30(3,0x7f7fffffec50)
 10426      1 permtest RET   __fstat30 0
 10426      1 permtest CALL
__sysctl(0x7f7fffffe240,2,0x7f7fffffe25c,0x7f7fffffe250,0,0)
 10426      1 permtest MIB   6.7
 10426      1 permtest GIO   read 4 bytes
	000   00 10 00 00                                      ....
 10426      1 permtest RET   __sysctl 0
 10426      1 permtest CALL  readlink(0x7f7ffdbd92ac,0x7f7fffffe270,0x3f)
 10426      1 permtest NAMI  "/etc/malloc.conf"
 10426      1 permtest RET   readlink -1 errno 2 No such file or directory
 10426      1 permtest CALL  mmap(0,0x1000,3,0x1002,0xffffffff,0,0)
 10426      1 permtest RET   mmap 140187698950144/0x7f7ffdff7000
 10426      1 permtest CALL  break(0x500eb8)
 10426      1 permtest RET   break 0
 10426      1 permtest CALL  break(0x501eb8)
 10426      1 permtest RET   break 0
 10426      1 permtest CALL  break(0x502000)
 10426      1 permtest RET   break 0
 10426      1 permtest CALL  break(0x503000)
 10426      1 permtest RET   break 0
 10426      1 permtest CALL  break(0x504000)
 10426      1 permtest RET   break 0
 10426      1 permtest CALL
__sysctl(0x7f7fffffe320,2,0x7f7ffdd05a60,0x7f7fffffe318,0,0)
 10426      1 permtest MIB   6.7
 10426      1 permtest GIO   read 4 bytes
	000   00 10 00 00                                      ....
 10426      1 permtest RET   __sysctl 0
 10426      1 permtest CALL  fstatvfs1(3,0x7f7fffffe380,2)
 10426      1 permtest RET   fstatvfs1 -1 errno 13 Permission denied
 10426      1 permtest CALL  close(3)
 10426      1 permtest RET   close 0
 10426      1 permtest CALL  __fstat30(1,0x7f7fffffeb80)
 10426      1 permtest RET   __fstat30 0
 10426      1 permtest CALL  break(0x514000)
 10426      1 permtest RET   break 0
 10426      1 permtest CALL  ioctl(1,TIOCGETA,0x7f7fffffebf0)
 10426      1 permtest GIO   fd 1 read 44 bytes
	000   06 23 00 00 03 00 00 00  00 0b 00 00 cf 05 00 20 .#..............
	010   04 ff ff 7f 17 15 12 ff  03 1c 1a 19 11 13 16 0f ................
	020   01 00 14 ff 00 96 00 00  00 96 00 00             ............
 10426      1 permtest RET   ioctl 0
 10426      1 permtest CALL  write(1,0x504000,7)
 10426      1 permtest GIO   fd 1 wrote 7 bytes
	000   45 72 72 6f 72 21 0a                             Error!.
 10426      1 permtest RET   write 7
 10426      1 permtest CALL  exit(0)


$ kdump -x /tmp/success.out
 27795      1 ktrace   EMUL  "netbsd"
 27795      1 ktrace   CALL
execve(0x7f7fffffeeb8,0x7f7fffffed68,0x7f7fffffed78)
 27795      1 ktrace   NAMI  "/tmp/permtest"
 27795      1 ktrace   NAMI  "/usr/libexec/ld.elf_so"
 27795      1 ktrace   ARG   "/tmp/permtest"
 27795      1 ktrace   ENV   "_=/usr/bin/ktrace"
 27795      1 ktrace   ENV   "PAGER=more"
 27795      1 ktrace   ENV
"PATH=/home/pkgsrc/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/pkg/bin:/usr/pkg/sbin:/usr/g\
	ames:/usr/local/bin:/usr/local/sbin"
 27795      1 ktrace   ENV   "SHELL=/bin/ksh"
 27795      1 ktrace   ENV   "EDITOR=vi"
 27795      1 ktrace   ENV   "SU_FROM=root"
 27795      1 ktrace   ENV   "USER=pkgsrc"
 27795      1 ktrace   ENV   "HOME=/home/pkgsrc"
 27795      1 ktrace   ENV   "TERM=screen"
 27795      1 ktrace   ENV   "EXINIT=set autoindent"
 27795      1 ktrace   ENV   "LOGNAME=pkgsrc"
 27795      1 permtest EMUL  "netbsd"
 27795      1 permtest RET   execve JUSTRETURN
 27795      1 permtest CALL  mmap(0,0x8000,3,0x1002,0xffffffff,0,0)
 27795      1 permtest RET   mmap 140187698954240/0x7f7ffdff8000
 27795      1 permtest CALL  open(0x7f7ffde0a82e,0,0x7f7ffde0a82e)
 27795      1 permtest NAMI  "/etc/ld.so.conf"
 27795      1 permtest RET   open -1 errno 2 No such file or directory
 27795      1 permtest CALL  open(0x7f7fffffe5d8,0,0xfefefefeff31302d)
 27795      1 permtest NAMI  "/usr/lib/libc.so.12"
 27795      1 permtest RET   open 3
 27795      1 permtest CALL  __fstat30(3,0x7f7fffffe508)
 27795      1 permtest RET   __fstat30 0
 27795      1 permtest CALL  mmap(0,0x1000,1,1,3,0x7f7f00000000,0)
 27795      1 permtest RET   mmap 140187698950144/0x7f7ffdff7000
 27795      1 permtest CALL  munmap(0x7f7ffdff7000,0x1000)
 27795      1 permtest RET   munmap 0
 27795      1 permtest CALL
mmap(0,0x207000,5,0x14000002,3,0x7f7f00000000,0)
 27795      1 permtest RET   mmap 140187693744128/0x7f7ffdb00000
 27795      1 permtest CALL
mmap(0x7f7ffdceb000,0xb000,3,0x12,3,0x7f7f00000000,0xeb000)
 27795      1 permtest RET   mmap 140187695755264/0x7f7ffdceb000
 27795      1 permtest CALL
mmap(0x7f7ffdcf6000,0x11000,3,0x1012,0xffffffff,0x7f7f00000000,0)
 27795      1 permtest RET   mmap 140187695800320/0x7f7ffdcf6000
 27795      1 permtest CALL  mprotect(0x7f7ffdbeb000,0x100000,0)
 27795      1 permtest RET   mprotect 0
 27795      1 permtest CALL  close(3)
 27795      1 permtest RET   close 0
 27795      1 permtest CALL
__sysctl(0x7f7fffffecb0,2,0x7f7ffdcfa320,0x7f7fffffeca8,0,0)
 27795      1 permtest MIB   1.81
 27795      1 permtest GIO   read 64 bytes
	000   42 59 ed e0 08 b3 f1 af  80 02 b6 93 38 4b fa da BY..........8K..
	010   e2 1e 26 a4 a8 57 3f 46  61 98 7f f5 0d 01 1c 1a ..&..W?Fa.......
	020   d3 64 34 8b 19 f4 91 6c  e7 c2 96 3c 8a 42 4b 50 .d4....l...<.BKP
	030   93 4f 33 ff 6a 36 8d 16  7d 33 64 24 69 65 9d 5e .O3.j6..}3d$ie.^
 27795      1 permtest RET   __sysctl 0
 27795      1 permtest CALL  open(0x400a99,4,0x7f7fffffed98)
 27795      1 permtest NAMI  "."
 27795      1 permtest RET   open 3
 27795      1 permtest CALL  fcntl(3,2,1)
 27795      1 permtest RET   fcntl 0
 27795      1 permtest CALL  __fstat30(3,0x7f7fffffec50)
 27795      1 permtest RET   __fstat30 0
 27795      1 permtest CALL
__sysctl(0x7f7fffffe240,2,0x7f7fffffe25c,0x7f7fffffe250,0,0)
 27795      1 permtest MIB   6.7
 27795      1 permtest GIO   read 4 bytes
	000   00 10 00 00                                      ....
 27795      1 permtest RET   __sysctl 0
 27795      1 permtest CALL  readlink(0x7f7ffdbd92ac,0x7f7fffffe270,0x3f)
 27795      1 permtest NAMI  "/etc/malloc.conf"
 27795      1 permtest RET   readlink -1 errno 2 No such file or directory
 27795      1 permtest CALL  mmap(0,0x1000,3,0x1002,0xffffffff,0,0)
 27795      1 permtest RET   mmap 140187698950144/0x7f7ffdff7000
 27795      1 permtest CALL  break(0x500eb8)
 27795      1 permtest RET   break 0
 27795      1 permtest CALL  break(0x501eb8)
 27795      1 permtest RET   break 0
 27795      1 permtest CALL  break(0x502000)
 27795      1 permtest RET   break 0
 27795      1 permtest CALL  break(0x503000)
 27795      1 permtest RET   break 0
 27795      1 permtest CALL  break(0x504000)
 27795      1 permtest RET   break 0
 27795      1 permtest CALL
__sysctl(0x7f7fffffe320,2,0x7f7ffdd05a60,0x7f7fffffe318,0,0)
 27795      1 permtest MIB   6.7
 27795      1 permtest GIO   read 4 bytes
	000   00 10 00 00                                      ....
 27795      1 permtest RET   __sysctl 0
 27795      1 permtest CALL  fstatvfs1(3,0x7f7fffffe380,2)
 27795      1 permtest RET   fstatvfs1 0
 27795      1 permtest CALL  break(0x505000)
 27795      1 permtest RET   break 0
 27795      1 permtest CALL  __fstat30(1,0x7f7fffffeb80)
 27795      1 permtest RET   __fstat30 0
 27795      1 permtest CALL  break(0x515000)
 27795      1 permtest RET   break 0
 27795      1 permtest CALL  ioctl(1,TIOCGETA,0x7f7fffffebf0)
 27795      1 permtest GIO   fd 1 read 44 bytes
	000   06 23 00 00 03 00 00 00  00 0b 00 00 cf 05 00 20 .#..............
	010   04 ff ff 7f 17 15 12 ff  03 1c 1a 19 11 13 16 0f ................
	020   01 00 14 ff 00 96 00 00  00 96 00 00             ............
 27795      1 permtest RET   ioctl 0
 27795      1 permtest CALL  write(1,0x505000,9)
 27795      1 permtest GIO   fd 1 wrote 9 bytes
	000   53 75 63 63 65 73 73 21  0a                      Success!.
 27795      1 permtest RET   write 9
 27795      1 permtest CALL  close(3)
 27795      1 permtest RET   close 0
 27795      1 permtest CALL  exit(0)



   Again, the reason I'm looking at opendir() specifically is because I
have yet to find an example when the problem shows itself when I open a
file or anything of the sort. When the problem is there, I can "cat"
files *without* any problem, but only if I specify the file name
_exactly_. So, "cat foo" will work, but "cat fo*" will *not*. (Because
the shell performs an opendir() or related call?).


   I'm beginning to run out of ideas. I'm fairly certain that there's a
problem with enumerating files/directories (opendir() fails). This
problem will show up sooner or later, and the only way I've figured out
to make it go away is  by logging out my "jan" user (which belongs to
wheel). And then it only goes away temporarily. It always comes back;
but I haven't figured out any systematic way to do this (other than just
using my computer for random tasks for a few minutes).

- --
Kind regards,
Jan Danielsson

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (NetBSD)

iD8DBQFG8SE/uPlHKFfKXTYRCnjRAJ98zv/qdBPL79fr2HH9bUhZH+nl0ACglKaj
0iHfWhZryM5TJ7fPBQOEhlU=
=btM/
-----END PGP SIGNATURE-----