|
From: Bart V. A. <bar...@gm...> - 2008-03-23 14:21:20
|
Hello Julian,
Can you please have a look at the following:
$ ls -l /var/run/nscd/passwd
-rw------- 1 root root 217016 2008-03-23 15:11 /var/run/nscd/passwd
$ ./vg-in-place --tool=none knode
...
--4396-- WARNING: Serious error when reading debug info
--4396-- When reading debug info from /var/run/nscd/passwd:
--4396-- can't open file to inspect ELF header
...
>From the output of strace -f knode:
...
[pid 4457] socket(PF_FILE, SOCK_STREAM, 0) = 10
[pid 4457] fcntl(10, F_SETFL, O_RDWR|O_NONBLOCK) = 0
[pid 4457] connect(10, {sa_family=AF_FILE,
path="/var/run/nscd/socket"}, 110) = 0
...
Thanks,
Bart.
|
|
From: Bart V. A. <bar...@gm...> - 2008-04-05 15:39:42
|
Hello,
I developed a patch to solve the issue explained below. Is it OK if I
commit this patch ?
The patch checks that a filename refers to a regular file before
trying to read ELF information
from the file, and ignores regular files for which Valgrind does not
have read access.
Bart.
Index: coregrind/m_debuginfo/debuginfo.c
===================================================================
--- coregrind/m_debuginfo/debuginfo.c (revision 7844)
+++ coregrind/m_debuginfo/debuginfo.c (working copy)
@@ -491,6 +491,8 @@
Int nread;
HChar buf1k[1024];
Bool debug = False;
+ SysRes statres;
+ struct vki_stat statbuf;
/* In short, figure out if this mapping is of interest to us, and
if so, try to guess what ld.so is doing and when/if we should
@@ -520,44 +522,27 @@
if (debug)
VG_(printf)("di_notify_mmap-2: %s\n", filename);
- /* XXXX begin KLUDGE */
- /* Skip filenames in /dev/. Don't even bother to try opening them.
- Why?
-
- Suppose the client opens and then mmaps the file specified by
- 'filename' and puts some kind of lock on it, so nobody else can
- open it. If we now try to open it to peer at the ELF header,
- the system can hang, because the VG_(open) call blocks.
- Precisely this happed when running Amarok, which opened and then
- mmap'd /dev/snd/pcmC0D0c.
-
- A clean(er) solution is to open the file with VKI_O_NONBLOCK, so
- that if it is locked, we simply fail immediately and don't hang
- the whole system. But "man 2 open" gives only a sketchy
- description of the resulting file semantics. So for the
- meantime, just skip files in /dev/ as (1) they are likely to be
- subject to wierd-ass locking stuff, and (2) they won't contain
- useful debug info anyway.
-
- But that's a kludge; in principle the same problem could occur
- with *any* file.
- */
- if (0 == VG_(strncmp)(filename, "/dev/", 5)) {
- if (debug)
- VG_(printf)("di_notify_mmap-2: skipping %s\n", filename);
+ /* Only try to read debug information from regular files. */
+ statres = VG_(stat)(filename, &statbuf);
+ if (statres.isError || ! VKI_S_ISREG(statbuf.st_mode))
return;
- }
- /* XXXX end KLUDGE */
- /* Peer at the first few bytes of the file, to see if it is an ELF
- object file. */
+ /* If the assert below ever fails, replace the VG_(stat)() call above */
+ /* by a VG_(lstat)() call. */
+ vg_assert(! VKI_S_ISLNK(statbuf.st_mode));
+
+ /* Peer at the first few bytes of the file, to see if it is an ELF */
+ /* object file. Ignore the file if we do not have read permission. */
VG_(memset)(buf1k, 0, sizeof(buf1k));
fd = VG_(open)( filename, VKI_O_RDONLY, 0 );
if (fd.isError) {
DebugInfo fake_di;
- VG_(memset)(&fake_di, 0, sizeof(fake_di));
- fake_di.filename = filename;
- ML_(symerr)(&fake_di, True, "can't open file to inspect ELF header");
+ if (fd.err != VKI_EACCES)
+ {
+ VG_(memset)(&fake_di, 0, sizeof(fake_di));
+ fake_di.filename = filename;
+ ML_(symerr)(&fake_di, True, "can't open file to inspect ELF header");
+ }
return;
}
nread = VG_(read)( fd.res, buf1k, sizeof(buf1k) );
On Sun, Mar 23, 2008 at 4:21 PM, Bart Van Assche
<bar...@gm...> wrote:
> Hello Julian,
>
> Can you please have a look at the following:
>
> $ ls -l /var/run/nscd/passwd
> -rw------- 1 root root 217016 2008-03-23 15:11 /var/run/nscd/passwd
> $ ./vg-in-place --tool=none knode
> ...
> --4396-- WARNING: Serious error when reading debug info
> --4396-- When reading debug info from /var/run/nscd/passwd:
> --4396-- can't open file to inspect ELF header
> ...
>
> From the output of strace -f knode:
> ...
> [pid 4457] socket(PF_FILE, SOCK_STREAM, 0) = 10
> [pid 4457] fcntl(10, F_SETFL, O_RDWR|O_NONBLOCK) = 0
> [pid 4457] connect(10, {sa_family=AF_FILE,
> path="/var/run/nscd/socket"}, 110) = 0
> ...
|
|
From: Bart V. A. <bar...@gm...> - 2008-04-06 07:34:28
|
On Sat, Apr 5, 2008 at 5:39 PM, Bart Van Assche
<bar...@gm...> wrote:
> Hello,
>
> I developed a patch to solve the issue explained below. Is it OK if I
> commit this patch ?
> The patch checks that a filename refers to a regular file before
> trying to read ELF information
> from the file, and ignores regular files for which Valgrind does not
> have read access.
The vg_assert() statement in the previous patch I sent did not make
sense -- this should be fixed in the patch below. The number of
regression test failures reported on my PC by make regtest is reduced
from 10 to 9 by this patch, and it is still possible to run Amarok
under Valgrind.
Bart.
Index: coregrind/m_debuginfo/debuginfo.c
===================================================================
--- coregrind/m_debuginfo/debuginfo.c (revision 7844)
+++ coregrind/m_debuginfo/debuginfo.c (working copy)
@@ -491,6 +491,8 @@
Int nread;
HChar buf1k[1024];
Bool debug = False;
+ SysRes statres;
+ struct vki_stat statbuf;
/* In short, figure out if this mapping is of interest to us, and
if so, try to guess what ld.so is doing and when/if we should
@@ -520,44 +522,29 @@
if (debug)
VG_(printf)("di_notify_mmap-2: %s\n", filename);
- /* XXXX begin KLUDGE */
- /* Skip filenames in /dev/. Don't even bother to try opening them.
- Why?
-
- Suppose the client opens and then mmaps the file specified by
- 'filename' and puts some kind of lock on it, so nobody else can
- open it. If we now try to open it to peer at the ELF header,
- the system can hang, because the VG_(open) call blocks.
- Precisely this happed when running Amarok, which opened and then
- mmap'd /dev/snd/pcmC0D0c.
-
- A clean(er) solution is to open the file with VKI_O_NONBLOCK, so
- that if it is locked, we simply fail immediately and don't hang
- the whole system. But "man 2 open" gives only a sketchy
- description of the resulting file semantics. So for the
- meantime, just skip files in /dev/ as (1) they are likely to be
- subject to wierd-ass locking stuff, and (2) they won't contain
- useful debug info anyway.
-
- But that's a kludge; in principle the same problem could occur
- with *any* file.
- */
- if (0 == VG_(strncmp)(filename, "/dev/", 5)) {
- if (debug)
- VG_(printf)("di_notify_mmap-2: skipping %s\n", filename);
+ /* Only try to read debug information from regular files. */
+ statres = VG_(stat)(filename, &statbuf);
+ /* If the assert below ever fails, replace the VG_(stat)() call above */
+ /* by a VG_(lstat)() call. */
+ vg_assert(statres.isError || ! VKI_S_ISLNK(statbuf.st_mode));
+ if (statres.isError || ! VKI_S_ISREG(statbuf.st_mode))
+ {
return;
}
- /* XXXX end KLUDGE */
- /* Peer at the first few bytes of the file, to see if it is an ELF
- object file. */
+
+ /* Peer at the first few bytes of the file, to see if it is an ELF */
+ /* object file. Ignore the file if we do not have read permission. */
VG_(memset)(buf1k, 0, sizeof(buf1k));
fd = VG_(open)( filename, VKI_O_RDONLY, 0 );
if (fd.isError) {
DebugInfo fake_di;
- VG_(memset)(&fake_di, 0, sizeof(fake_di));
- fake_di.filename = filename;
- ML_(symerr)(&fake_di, True, "can't open file to inspect ELF header");
+ if (fd.err != VKI_EACCES)
+ {
+ VG_(memset)(&fake_di, 0, sizeof(fake_di));
+ fake_di.filename = filename;
+ ML_(symerr)(&fake_di, True, "can't open file to inspect ELF header");
+ }
return;
}
nread = VG_(read)( fd.res, buf1k, sizeof(buf1k) );
|