From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.bonedaddy.net (smtp.bonedaddy.net [45.33.94.42]) by sourceware.org (Postfix) with ESMTPS id 2EEB53858D1E for ; Sun, 6 Aug 2023 06:09:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2EEB53858D1E Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=bonedaddy.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bonedaddy.net Received: by smtp.bonedaddy.net (Postfix, from userid 10001) id 6B221302055; Sun, 6 Aug 2023 02:03:24 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bonedaddy.net; s=mail; t=1691301804; bh=cyIv4BzsW4CJXWeL9rh8FDi2GQo8Sb6MzjjJuciPmxk=; h=Subject:From:To:Cc:In-Reply-To:References:Date; b=CSsLMbNYLdH3NgwrA/m8O4SAa6XJoJ0zvO0Nq2BaomPz7nY6mkfuOT/GwgctyzNTA vWcYwg0AcVYNa23Jz2wFKRKjz9P5UoqQO7hQ10YNiGgfM4epd9WHpyKU0DFnKuqSJH tXRGA1Awlh7Xc7pKQ6m/ccN4Kt6MnYk2RDVUGZAE6qfdoXWcftyED1Vyxi0lHlHBQC Wz7GZEz3So8uIQbbNjkcQL9ENR8hLLHi7pgKw+LvaFDqcGvos/IwwF3zWsR3zyq1YF evAo6UZa6B7l+QNCuU2hYZOGRjhmEiuKMJuZy9L9T7QSCxOp+5veb/VnU1+OmBGpMm k2yfBJRx4EwgQ== Message-ID: Subject: Re: is this a bug in glibc or readpst? From: Paul Wise To: Florian Weimer Cc: Libc-help In-Reply-To: <87ilitpv06.fsf@oldenburg.str.redhat.com> References: <2cefc4fa95dd439c2581f4f06d520c004cd33708.camel@bonedaddy.net> <875yf6nj43.fsf@oldenburg.str.redhat.com> <87ilitpv06.fsf@oldenburg.str.redhat.com> Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-8WyFrBwFcrLHTxCJKpCI" Date: Sun, 06 Aug 2023 14:07:09 +0800 MIME-Version: 1.0 User-Agent: Evolution 3.48.4-1 X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --=-8WyFrBwFcrLHTxCJKpCI Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 2022-12-02 at 18:37 +0100, Florian Weimer wrote: > Could you run it under strace -k, with debuginfo?=C2=A0 Hopefully that wi= ll > 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) =3D 268198 openat(AT_FDCWD, "example.pst", O_RDONLY) =3D 4 dup3(4, 3, 0) =3D 3 close(4) =3D 0 With glibc 2.38 freopen these calls happen, bug absent: openat(AT_FDCWD, "example.pst", O_RDONLY) =3D 4 dup3(4, 3, 0) =3D 3 close(4) =3D 0 With fclose+fopen these calls happen, bug absent: close(3) =3D 0 openat(AT_FDCWD, "example.pst", O_RDONLY) =3D 3 =20 With fflush+fclose+fopen these calls happen, bug present: lseek(3, -2138, SEEK_CUR) =3D 268198 close(3) =3D 0 openat(AT_FDCWD, "example.pst", O_RDONLY) =3D 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) =3D 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? =20 For my notes: strace -o strace/readpst -e trace=3D'!read,write' --follow-forks --outpu= t-separately --stack-traces readpst -j 2 -D -M -b example.pst =20 --=20 bye, pabs https://bonedaddy.net/pabs3/ --=-8WyFrBwFcrLHTxCJKpCI Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEYQsotVz8/kXqG1Y7MRa6Xp/6aaMFAmTPOIkACgkQMRa6Xp/6 aaNXvw/8CrdhkY/zrSLfXcoImTed+hZFQCeZ96iZrli4tW17j2urtCCIkNNhY0yh eKdWsspzaSRQ2NbpYERJA8nvaFZJQg6tr2KE18nWOUTkkYBJkKx2APHjqqjFMPKN 2xVLxDrb8s5xTgY1V3plAdeIUJeFEClgTlC+X0j/BiMHafZ6nRlfHUKNQKuktDXl 6vyneX8gqfbnpaEtEzdFW/lSPCNmBAvzDNuyw43AtitgePSnv6071I5hKvf1RCnM UMuTBWQ3UGm9qhOITFOt/IrzJv08QvIxeDr9cEQEEWn2P9suXXsD+bR2FIZ05NwQ 1ReVHVZbshsAX7dx6d3fNPCQlCBMCDpgSCNeMLamOEYAOFmGXC0RBYXyqzaftjjM LJu+vS2qLVErSqX/J0AlR4nqN7eGn5JiqP6D281dICEMxDxE6Tsxj7/77oG0o9u4 xQyKfGw7nJ+UmVoG4/9s2YJiMBFdZyj/HwJ1QrrwJE2zo+UZfMk+8OfsOndixNCk KMjF/FkALuuYhSLJjgxQKdKP7MjgPOh7pZMDWTW6RDk/r/K55XQVuETywCn3jjNo d/BCsNl5+ZAVzvt6srf29wrIuBnvNpmzcQ65vbBgtAekz8ndfacI0EC1QSmfg4yd 51+v/e94J+5Oh9s4Ds57fESMIyvqeglrgIK2XcqmAwuwJdgRDUo= =GAO7 -----END PGP SIGNATURE----- --=-8WyFrBwFcrLHTxCJKpCI--