Skip to contentSkip to conversation

"Switch !O_CREAT case to use of do_last()" causes segfault in glibc

DISCUSSION walt 2 participants 7 messages Mar 6, 2010 VFS

lore
Share & tools
lore

walt

author
#0 lore raw

Hi Al,
commit 1f36f774b22a0ceb7dd33eca626746c81a97b6a5

Author: Al Viro <[email protected]>
Date:   Sat Dec 26 10:56:19 2009 -0500

Switch !O_CREAT case to use of do_last()

... and now we have all intents crap well localized

This commit is triggering a segfault when I try to open a spreadsheet in openoffice:

Program received signal SIGSEGV, Segmentation fault. 0x00007ffff6d13129 in __readdir (dirp=0x0) at ../sysdeps/unix/readdir.c:45
45 ../sysdeps/unix/readdir.c: No such file or directory.
in ../sysdeps/unix/readdir.c
(gdb) bt

#0  0x00007ffff6d13129 in __readdir (dirp=0x0) at ../sysdeps/unix/readdir.c:45
#1  0x00007ffff1dc58b0 in ?? () from /usr/lib/libicuuc.so.42
#2  0x00007ffff1dc591d in ?? () from /usr/lib/libicuuc.so.42
#3  0x00007ffff1dc5d7e in uprv_tzname_4_2 () from /usr/lib/libicuuc.so.42
#4  0x00007fffd7f73601 in icu_4_2::TimeZone::initDefault() () from /usr/lib/libicui18n.so.42
#5  0x00007fffd7f738c5 in icu_4_2::TimeZone::createDefault() () from /usr/lib/libicui18n.so.42
#6  0x00007fffd7f6e5c9 in icu_4_2::Calendar::createInstance(icu_4_2::Locale const&, UErrorCode&) ()

from /usr/lib/libicui18n.so.42

Here is readdir.c:445 (from glibc-2.11):

#ifndef NOT_IN_libc
__libc_lock_lock (dirp->lock);
#endif

Thanks.

maintainer
#1 lore raw
Quoted 17 lines · walt

Hi Al,
commit 1f36f774b22a0ceb7dd33eca626746c81a97b6a5

Author: Al Viro <[email protected]>
Date:   Sat Dec 26 10:56:19 2009 -0500

Switch !O_CREAT case to use of do_last()

... and now we have all intents crap well localized

This commit is triggering a segfault when I try to open a spreadsheet in openoffice:

Program received signal SIGSEGV, Segmentation fault. 0x00007ffff6d13129 in __readdir (dirp=0x0) at ../sysdeps/unix/readdir.c:45
45 ../sysdeps/unix/readdir.c: No such file or directory.
in ../sysdeps/unix/readdir.c
(gdb) bt

Quoted 8 lines
#0  0x00007ffff6d13129 in __readdir (dirp=0x0) at ../sysdeps/unix/readdir.c:45
#1  0x00007ffff1dc58b0 in ?? () from /usr/lib/libicuuc.so.42
#2  0x00007ffff1dc591d in ?? () from /usr/lib/libicuuc.so.42
#3  0x00007ffff1dc5d7e in uprv_tzname_4_2 () from /usr/lib/libicuuc.so.42
#4  0x00007fffd7f73601 in icu_4_2::TimeZone::initDefault() () from /usr/lib/libicui18n.so.42
#5  0x00007fffd7f738c5 in icu_4_2::TimeZone::createDefault() () from /usr/lib/libicui18n.so.42
#6  0x00007fffd7f6e5c9 in icu_4_2::Calendar::createInstance(icu_4_2::Locale const&, UErrorCode&) ()

from /usr/lib/libicui18n.so.42

Very interesting. Could you give the relevant parts of strace (or reproduce it with something less monumental than openoffice)?

maintainer
#2 lore raw
Quoted 27 lines · Al Viro
Quoted 17 lines · walt

Hi Al,
commit 1f36f774b22a0ceb7dd33eca626746c81a97b6a5

Author: Al Viro <[email protected]>
Date:   Sat Dec 26 10:56:19 2009 -0500

Switch !O_CREAT case to use of do_last()

... and now we have all intents crap well localized

This commit is triggering a segfault when I try to open a spreadsheet in openoffice:

Program received signal SIGSEGV, Segmentation fault. 0x00007ffff6d13129 in __readdir (dirp=0x0) at ../sysdeps/unix/readdir.c:45
45 ../sysdeps/unix/readdir.c: No such file or directory.
in ../sysdeps/unix/readdir.c
(gdb) bt

Quoted 8 lines
#0  0x00007ffff6d13129 in __readdir (dirp=0x0) at ../sysdeps/unix/readdir.c:45
#1  0x00007ffff1dc58b0 in ?? () from /usr/lib/libicuuc.so.42
#2  0x00007ffff1dc591d in ?? () from /usr/lib/libicuuc.so.42
#3  0x00007ffff1dc5d7e in uprv_tzname_4_2 () from /usr/lib/libicuuc.so.42
#4  0x00007fffd7f73601 in icu_4_2::TimeZone::initDefault() () from /usr/lib/libicui18n.so.42
#5  0x00007fffd7f738c5 in icu_4_2::TimeZone::createDefault() () from /usr/lib/libicui18n.so.42
#6  0x00007fffd7f6e5c9 in icu_4_2::Calendar::createInstance(icu_4_2::Locale const&, UErrorCode&) ()

from /usr/lib/libicui18n.so.42

Quoted 2 lines

Very interesting. Could you give the relevant parts of strace (or reproduce it with something less monumental than openoffice)?

_Really_ interesting; it doesn't look like an oops - smells like an attempt to do opendir() that fails for some reason, goes unnoticed and resulting FILE * (i.e. NULL) is fed to readdir()?

What does it attempt to open?

author
#3 lore raw
Quoted 5 lines · Al Viro

_Really_ interesting; it doesn't look like an oops - smells like an attempt to do opendir() that fails for some reason, goes unnoticed and resulting FILE * (i.e. NULL) is fed to readdir()?

What does it attempt to open?

Ah, this may help:

open("/usr/share/zoneinfo/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 47 open("/usr/share/zoneinfo/MST7MDT", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 48 open("/usr/share/zoneinfo/MST7MDT/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOTDIR (Not a directory) --- SIGSEGV (Segmentation fault) @ 0 (0) ---

maintainer
#4 lore raw
Quoted 6 lines · walt
Quoted 4 lines · Al Viro

_Really_ interesting; it doesn't look like an oops - smells like an attempt to do opendir() that fails for some reason, goes unnoticed and resulting FILE * (i.e. NULL) is fed to readdir()?

Quoted 8 lines
Quoted 1 line

What does it attempt to open?

Ah, this may help:

open("/usr/share/zoneinfo/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 47 open("/usr/share/zoneinfo/MST7MDT", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 48 open("/usr/share/zoneinfo/MST7MDT/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOTDIR (Not a directory) --- SIGSEGV (Segmentation fault) @ 0 (0) ---

Oho... And what do you have in /usr/share/zoneinfo? I.e. what is MST7MDT?

BTW, icu is buggy, regardless of apparent bug introduced in the kernel - common/putil.c:searchForTZFile() does

    DIR* dirp = opendir(path);
...
    while((dirEntry = readdir(dirp)) != NULL) {

with no references to dirp in between (no checks for errors, etc.), so it'll segfault on any number of situations (e.g. directory in question being unreadable for you).

maintainer
#5 lore raw
In reply to walt
Quoted 6 lines · walt
Quoted 4 lines · Al Viro

_Really_ interesting; it doesn't look like an oops - smells like an attempt to do opendir() that fails for some reason, goes unnoticed and resulting FILE * (i.e. NULL) is fed to readdir()?

Quoted 6 lines
Quoted 1 line

What does it attempt to open?

Ah, this may help:

open("/usr/share/zoneinfo/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 47 open("/usr/share/zoneinfo/MST7MDT", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 48

Now that is interesting. Looks like it has managed to lose O_DIRECTORY check in the open without trailing slash and (properly) barfed with / added.

maintainer
#6 lore raw
Quoted 9 lines · Al Viro
Quoted 8 lines · walt
Quoted 5 lines · Al Viro

_Really_ interesting; it doesn't look like an oops - smells like an attempt to do opendir() that fails for some reason, goes unnoticed and resulting FILE * (i.e. NULL) is fed to readdir()?

What does it attempt to open?

Quoted 7 lines
Quoted 4 lines

Ah, this may help:

open("/usr/share/zoneinfo/", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 47 open("/usr/share/zoneinfo/MST7MDT", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 48

Now that is interesting. Looks like it has managed to lose O_DIRECTORY check in the open without trailing slash and (properly) barfed with / added.

OK, I can reproduce it. Give me a few, I'll see...

AAARGH.

Fix a dumb typo - use of & instead of &&

---

fs/namei.c +1 -1
index 3d9d2f9..48e60a1 100644
@@ -1656,7 +1656,7 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
 		if (path->dentry->d_inode->i_op->follow_link)
 			return NULL;
 		error = -ENOTDIR;
-		if (*want_dir & !path->dentry->d_inode->i_op->lookup)
+		if (*want_dir && !path->dentry->d_inode->i_op->lookup)
 			goto exit_dput;
 		path_to_nameidata(path, nd);
 		audit_inode(pathname, nd->path.dentry);