From: Trond Myklebust <trond.myklebust@fys.uio.no>
To: jblunck@suse.de
Cc: Miklos Szeredi <miklos@szeredi.hu>,
viro@ftp.linux.org.uk, linux-kernel@vger.kernel.org
Subject: Re: [RFC,PATCH] libfs dcache_readdir() and dcache_dir_lseek() bugfix
Date: Fri, 04 Nov 2005 11:27:21 -0500 [thread overview]
Message-ID: <1131121642.8806.42.camel@lade.trondhjem.org> (raw)
In-Reply-To: <20051104151104.GA22322@hasse.suse.de>
On Fri, 2005-11-04 at 16:11 +0100, jblunck@suse.de wrote:
> On Fri, Nov 04, Miklos Szeredi wrote:
>
> > > As I said: "Old glibc implementations (e.g. glibc-2.2.5) are
> > > lseeking after every call to getdents() ..."
> >
> > Hmm, why would it do that? This seems like it's glibc being stupid.
> >
>
> Well, glibc is that stupid and triggers the bug.
It is due to the kernel's 32-bit struct dirent being smaller than
glibc's 32-bit struct dirent (glibc has the extra ->d_type field).
Because the dirent record length depends on the filename length, the
exact expansion factor for the results of a call to getdents() may not
be precomputed.
glibc uses a heuristic in order to estimate the expansion size, and then
uses that to allocate an intermediate buffer in which to store the
results of the getdents syscall.
If the contents of said intermediate buffer still happen to overflow the
user-allocated buffer, then glibc calls lseek() in order to rewind the
file pointer to the next entry it wants to read (and screws any
filesystem that doesn't support lseek on directories).
This code appears still to be part of glibc, however it is rarely
triggered these days because glibc's implementation now defaults to
using the getdents64 syscall (if it exists) instead of the 32-bit
version. Since the kernel's struct dirent64 is the same size as the
glibc struct dirent64 (and larger than the 32-bit struct dirent), there
is never any chance of buffer overflow.
The new bug is rather that glibc will return EOVERFLOW, and try to
rewind your file pointer if your filesystem happens to return 64-bit
offsets to getdents64().
> > Unfortunately I can't since I don't have such old glibc.
>
> The testcase is similar to what "rm *" with the old glibc would do. It just
> a testcase to show where the problem is.
'rm -rf' on a large directory used to be a great way to trigger it.
Cheers,
Trond
next prev parent reply other threads:[~2005-11-04 16:27 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-04 11:38 jblunck
2005-11-04 11:51 ` Al Viro
2005-11-04 12:20 ` jblunck
2005-11-04 12:56 ` Miklos Szeredi
2005-11-04 13:18 ` jblunck
2005-11-04 13:31 ` Miklos Szeredi
2005-11-04 15:11 ` jblunck
2005-11-04 15:16 ` Jörn Engel
2005-11-04 15:34 ` jblunck
2005-11-04 15:45 ` Jörn Engel
2005-11-04 15:38 ` Miklos Szeredi
2005-11-04 15:32 ` Miklos Szeredi
2005-11-04 15:46 ` jblunck
2005-11-04 15:55 ` Miklos Szeredi
2005-11-04 16:04 ` jblunck
2005-11-04 16:19 ` Miklos Szeredi
2005-11-07 10:17 ` jblunck
2005-11-04 16:27 ` Al Viro
2005-11-04 16:27 ` Trond Myklebust [this message]
2005-11-04 16:39 ` Miklos Szeredi
2005-11-04 16:55 ` Rob Landley
2005-11-07 10:06 ` jblunck
2005-11-04 12:52 ` Jörn Engel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1131121642.8806.42.camel@lade.trondhjem.org \
--to=trond.myklebust@fys.uio.no \
--cc=jblunck@suse.de \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=viro@ftp.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®