public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Possible truncation of the cookie in telldir/seekdir.
@ 2019-08-30 10:44 Marcin Mielniczuk
  2019-08-30 11:38 ` Florian Weimer
  0 siblings, 1 reply; 2+ messages in thread
From: Marcin Mielniczuk @ 2019-08-30 10:44 UTC (permalink / raw)
  To: libc-help

Hi,

On 32-bit OSes readdir64 will internally call the getdents64. There the
value for dirent64::d_off will be taken from unsigned long
linux_dirent::d_off, which is off64_t (the same as int64_t) and assigned
to __dirstream::filepos, which is off_t. On 32-bit systems, off_t is the
same as int32_t and long. Therefore, telldir will return a truncated
value. This can be reproduced, for instance, when cross-compiling to
arm-unknown-linux-gnueabi.

This means that (1) the value returned in dirent64::d_off may not match
the one returned by telldir (2) if we use seekdir with the value from
dirent64::d_off, a silent lossy conversion may happen and the stream may
be incorrectly seeked. According to POSIX, telldir & seekdir should use
a long, so this can't be fixed by simply using off64_t everywhere.

Is this a known issue? I see that IBM "circumvented" this problem in the
AIX libc by adding seekdir64 and telldir64.
Btw. on my system there's no manpage describing readdir64. Is this intended?

Regards,
Marcin

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Possible truncation of the cookie in telldir/seekdir.
  2019-08-30 10:44 Possible truncation of the cookie in telldir/seekdir Marcin Mielniczuk
@ 2019-08-30 11:38 ` Florian Weimer
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Weimer @ 2019-08-30 11:38 UTC (permalink / raw)
  To: Marcin Mielniczuk; +Cc: libc-help

* Marcin Mielniczuk:

> On 32-bit OSes readdir64 will internally call the getdents64. There the
> value for dirent64::d_off will be taken from unsigned long
> linux_dirent::d_off, which is off64_t (the same as int64_t) and assigned
> to __dirstream::filepos, which is off_t. On 32-bit systems, off_t is the
> same as int32_t and long. Therefore, telldir will return a truncated
> value. This can be reproduced, for instance, when cross-compiling to
> arm-unknown-linux-gnueabi.
>
> This means that (1) the value returned in dirent64::d_off may not match
> the one returned by telldir (2) if we use seekdir with the value from
> dirent64::d_off, a silent lossy conversion may happen and the stream may
> be incorrectly seeked. According to POSIX, telldir & seekdir should use
> a long, so this can't be fixed by simply using off64_t everywhere.

Correct.  It's a known issue.

  <https://sourceware.org/bugzilla/show_bug.cgi?id=23960>

We know how to fix it, by allocating sufficiently small cookie values in
userspace.  But we haven't implemented that yet.

> Btw. on my system there's no manpage describing readdir64. Is this intended?

No, it's something that needs to be fixed by the linux-man project.

Thanks,
Florian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-08-30 11:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-30 10:44 Possible truncation of the cookie in telldir/seekdir Marcin Mielniczuk
2019-08-30 11:38 ` Florian Weimer

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).