From: Paul Wise <pabs3@bonedaddy.net>
To: Florian Weimer <fweimer@redhat.com>
Cc: Libc-help <libc-help@sourceware.org>
Subject: Re: is this a bug in glibc or readpst?
Date: Sun, 06 Aug 2023 14:07:09 +0800 [thread overview]
Message-ID: <e4f6ce4730ee14445d67f0699aae180a227d766a.camel@bonedaddy.net> (raw)
In-Reply-To: <87ilitpv06.fsf@oldenburg.str.redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2543 bytes --]
On Fri, 2022-12-02 at 18:37 +0100, Florian Weimer wrote:
> Could you run it under strace -k, with debuginfo? Hopefully that will
> shed some light on the problem.
Finally got back to working on this.
With glibc 2.39+ freopen these calls happen, bug present:
lseek(3, -2138, SEEK_CUR) = 268198
openat(AT_FDCWD, "example.pst", O_RDONLY) = 4
dup3(4, 3, 0) = 3
close(4) = 0
With glibc 2.38 freopen these calls happen, bug absent:
openat(AT_FDCWD, "example.pst", O_RDONLY) = 4
dup3(4, 3, 0) = 3
close(4) = 0
With fclose+fopen these calls happen, bug absent:
close(3) = 0
openat(AT_FDCWD, "example.pst", O_RDONLY) = 3
With fflush+fclose+fopen these calls happen, bug present:
lseek(3, -2138, SEEK_CUR) = 268198
close(3) = 0
openat(AT_FDCWD, "example.pst", O_RDONLY) = 3
So the problem is that glibc freopen calls lseek on the existing file
descriptor, modifying the shared file description. So it seems like the
child process is interfering with the parent process file position.
Looking at the stack traces, the _IO_SYNC call introduced in the commit
0b727ed4d that I identified as triggering the readpst bug is definitely
the source of the lseek call.
lseek(3, -2138, SEEK_CUR) = 268198
> /lib/x86_64-linux-gnu/libc.so.6(lseek64+0x7) [0xf81b7]
> /lib/x86_64-linux-gnu/libc.so.6(_IO_file_sync+0x7e) [0x800ae]
> /lib/x86_64-linux-gnu/libc.so.6(freopen+0x8c) [0x7d95c]
> /usr/bin/readpst(pst_reopen+0x36) [0x102c6]
> /usr/bin/readpst(try_fork+0x88) [0x4398]
> /usr/bin/readpst(process+0x121) [0xa451]
> /usr/bin/readpst(main+0x555) [0x3cc5]
> /lib/x86_64-linux-gnu/libc.so.6(__libc_init_first+0x8a) [0x271ca]
> /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x85) [0x27285]
> /usr/bin/readpst(_start+0x21) [0x4061]
Based on the same thing happening with fflush+fclose+fopen, I'm not
entirely sure, but I think that this represents a POSIX compliance bug
in readpst that was papered over by the earlier behaviour of glibc.
Is my reasoning correct here?
For my notes:
strace -o strace/readpst -e trace='!read,write' --follow-forks --output-separately --stack-traces readpst -j 2 -D -M -b example.pst
--
bye,
pabs
https://bonedaddy.net/pabs3/
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2023-08-06 6:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-23 2:02 Paul Wise
2022-11-23 8:57 ` Florian Weimer
2022-11-24 0:06 ` Paul Wise
2022-12-02 17:37 ` Florian Weimer
2023-08-06 6:07 ` Paul Wise [this message]
2023-08-07 8:59 ` Florian Weimer
2023-08-07 11:00 ` Paul Wise
2023-08-07 11:46 ` Florian Weimer
2023-08-07 11:58 ` Paul Wise
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=e4f6ce4730ee14445d67f0699aae180a227d766a.camel@bonedaddy.net \
--to=pabs3@bonedaddy.net \
--cc=fweimer@redhat.com \
--cc=libc-help@sourceware.org \
/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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).