public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/104161] Potential Security Vulnerability: remove_all and symbolic link
Date: Wed, 04 Oct 2023 11:28:31 +0000	[thread overview]
Message-ID: <bug-104161-4-lyUxyeaRuh@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-104161-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104161

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:e20b1c711f70d8d251d45694c50c02e66a4d9f7b

commit r11-11036-ge20b1c711f70d8d251d45694c50c02e66a4d9f7b
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sun Jan 23 21:45:16 2022 +0000

    libstdc++: Avoid symlink race in filesystem::remove_all [PR104161]

    This adds a new internal flag to the filesystem::directory_iterator
    constructor that makes it fail if the path is a symlink that resolves to
    a directory. This prevents filesystem::remove_all from following a
    symlink to a directory, rather than deleting the symlink itself.

    We can also use that new flag in recursive_directory_iterator to ensure
    that we don't follow symlinks if the follow_directory_symlink option is
    not set.

    This also moves an error check in filesystem::remove_all after the while
    loop, so that errors from the directory_iterator constructor are
    reproted, instead of continuing to the filesystem::remove call below.

    libstdc++-v3/ChangeLog:

            PR libstdc++/104161
            * acinclude.m4 (GLIBCXX_CHECK_FILESYSTEM_DEPS): Check for
            fdopendir.
            * config.h.in: Regenerate.
            * configure: Regenerate.
            * src/c++17/fs_dir.cc (_Dir): Add nofollow flag to constructor
            and pass it to base class constructor.
            (directory_iterator): Pass nofollow flag to _Dir constructor.
            (fs::recursive_directory_iterator::increment): Likewise.
            * src/c++17/fs_ops.cc (do_remove_all): Use nofollow option for
            directory_iterator constructor. Move error check outside loop.
            * src/filesystem/dir-common.h (_Dir_base): Add nofollow flag to
            constructor and when it's set use ::open with O_NOFOLLOW and
            O_DIRECTORY.
            * src/filesystem/dir.cc (_Dir): Add nofollow flag to constructor
            and pass it to base class constructor.
            (directory_iterator): Pass nofollow flag to _Dir constructor.
            (fs::recursive_directory_iterator::increment): Likewise.
            * src/filesystem/ops.cc (remove_all): Use nofollow option for
            directory_iterator constructor. Move error check outside loop.

    (cherry picked from commit c8bd4dc8212e43b2f9af08b80df97f90cdb0df4f)

  parent reply	other threads:[~2023-10-04 11:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-21 11:47 [Bug c++/104161] New: " adrien.devresse at metamorphe dot engineering
2022-01-21 13:02 ` [Bug libstdc++/104161] " redi at gcc dot gnu.org
2022-01-21 14:27 ` adrien.devresse at metamorphe dot engineering
2022-01-25 21:09 ` cvs-commit at gcc dot gnu.org
2022-01-26  0:30 ` redi at gcc dot gnu.org
2022-01-27  1:51 ` jistone at redhat dot com
2022-01-27  8:29 ` redi at gcc dot gnu.org
2022-02-04 23:50 ` cvs-commit at gcc dot gnu.org
2022-02-08 13:40 ` cvs-commit at gcc dot gnu.org
2023-10-04 11:28 ` cvs-commit at gcc dot gnu.org [this message]
2023-10-04 11:28 ` cvs-commit at gcc dot gnu.org
2023-10-04 11:28 ` cvs-commit at gcc dot gnu.org
2023-10-04 11:33 ` redi at gcc dot gnu.org

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=bug-104161-4-lyUxyeaRuh@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.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).