public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: libc-alpha@sourceware.org,
	 "Andreas K . Huettel" <dilfridge@gentoo.org>,
	 Paul Eggert <eggert@cs.ucla.edu>
Subject: Re: [PATCH v5 1/5] linux: Use getdents64 on non-LFS readdir
Date: Mon, 20 Feb 2023 14:31:14 +0100	[thread overview]
Message-ID: <875ybwh3a5.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20230127172834.391311-2-adhemerval.zanella@linaro.org> (Adhemerval Zanella's message of "Fri, 27 Jan 2023 14:28:30 -0300")

* Adhemerval Zanella:

> diff --git a/sysdeps/unix/sysv/linux/dirstream.h b/sysdeps/unix/sysv/linux/dirstream.h
> index 3cb313b410..adcf8234f1 100644
> --- a/sysdeps/unix/sysv/linux/dirstream.h
> +++ b/sysdeps/unix/sysv/linux/dirstream.h
> @@ -18,6 +18,7 @@
>  #ifndef	_DIRSTREAM_H
>  #define	_DIRSTREAM_H	1
>  
> +#include <dirent.h>
>  #include <sys/types.h>
>  
>  #include <libc-lock.h>
> @@ -41,6 +42,10 @@ struct __dirstream
>  
>      int errcode;		/* Delayed error code.  */
>  
> +#if !defined __OFF_T_MATCHES_OFF64_T || !defined __INO_T_MATCHES_INO64_T
> +    struct dirent tdp;
> +#endif

I don't quite see how this can work given that d_name in the struct may
not be large enough.  The new member needs a comment to explain its
purpose.

> diff --git a/sysdeps/unix/sysv/linux/readdir.c b/sysdeps/unix/sysv/linux/readdir.c
> index 4a4c00ea07..cd0ccaf33a 100644
> --- a/sysdeps/unix/sysv/linux/readdir.c
> +++ b/sysdeps/unix/sysv/linux/readdir.c
> @@ -21,42 +21,71 @@
>  #if !_DIRENT_MATCHES_DIRENT64
>  #include <dirstream.h>
>  
> +/* Translate the DP64 entry to the non-LFS one in the translation entry
> +   at dirstream DS.  Return true is the translation was possible or
> +   false if either an internal field can not be represented in the non-LFS
> +   entry or if the name is too long.  */
> +static bool
> +dirstream_entry (struct __dirstream *ds, const struct dirent64 *dp64)
> +{
> +  /* Check for overflow.  */
> +  if (!in_off_t_range (dp64->d_off) || !in_ino_t_range (dp64->d_ino))
> +    return false;
> +
> +  /* And if name is too large.  */
> +  if (dp64->d_reclen - offsetof (struct dirent64, d_name) > NAME_MAX)
> +    return false;

Sorry, I don't think this is the direction we should be going.  In
readdir_r, we at least delay the NAME_MAX error to the end of the
directory.  This just adds another rare case where 32-bit code fails and
64-bit code works.

struct dirent is always shorter than struct dirent64, right?  It should
be possible to do the translation in-place.  Or turn tdp into a pointer
and reallocate as needed.

However, I think we should fix only readdir64, not readdir.  It's simply
not possible to fix readdir fully because of d_ino, so applications
which use readdir instead of readdir64 will remain buggy even with this
change.

What do you think?

Thanks,
Florian


  parent reply	other threads:[~2023-02-20 13:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-27 17:28 [PATCH v5 0/5] Fix opendir regression on some FS Adhemerval Zanella
2023-01-27 17:28 ` [PATCH v5 1/5] linux: Use getdents64 on non-LFS readdir Adhemerval Zanella
2023-01-27 17:38   ` Andreas Schwab
2023-02-20 13:31   ` Florian Weimer [this message]
2023-02-20 17:55     ` Florian Weimer
2023-03-01 16:34       ` Adhemerval Zanella Netto
2023-01-27 17:28 ` [PATCH v5 2/5] linux: Set internal DIR filepos as off64_t (BZ #23960, BZ #24050) Adhemerval Zanella
2023-02-20 18:39   ` Florian Weimer
2023-03-01 17:40     ` Adhemerval Zanella Netto
2023-01-27 17:28 ` [PATCH v5 3/5] linux: Add __readdir64_unlocked Adhemerval Zanella
2023-01-27 17:28 ` [PATCH v5 4/5] linux: Add __old_readdir64_unlocked Adhemerval Zanella
2023-01-27 17:28 ` [PATCH v5 5/5] linux: Use getdents64 on readdir64 compat implementation Adhemerval Zanella
2023-02-09 20:14 ` [PATCH v5 0/5] Fix opendir regression on some FS Andreas K. Huettel
2023-02-09 20:14 ` Andreas K. Huettel

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=875ybwh3a5.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=dilfridge@gentoo.org \
    --cc=eggert@cs.ucla.edu \
    --cc=libc-alpha@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).