Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/perl5Public

Clone dirhandles without fchdir#23019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ap merged 4 commits intobleadfromleont/thread-dirhandle
May 28, 2025
Merged

Clone dirhandles without fchdir#23019

ap merged 4 commits intobleadfromleont/thread-dirhandle
May 28, 2025

Conversation

Leont
Copy link
Contributor

@LeontLeont commentedFeb 20, 2025
edited
Loading

This is a WIP for fixing#23010 based on@ilmari's suggestion. There currently are two problems with it.

  1. It doesn't have a Configure check yet forfdopendir
  2. t/op/threads-dirh.t fails because it's assuming that the dirhandles in different threads are independent. Given that the same isn't true of filehandles, I think this is the wrong thing to aim at anyway.

vasi reacted with heart emoji
@tonycoz
Copy link
Contributor

I think it's one reasonable fix, though I think it would be an entry in incompatible changes in perldelta.

I'm not sure it's safe for multiple threads to readdir() from the same underlying fd: It's UB for both parent and child of a fork() to read from their corresponding copies of theDIR, which is the closest case I can think of to this, so I'm not sure this will be thread safe.

From my testing with simple test code, glibc gets confused about the telldir() position for the new handle.

One option might be toopenat(orig_dir_fd, ".", O_DIRECTORY | ...) which, assuming no permission change on., should give us an independent handle, which can be positioned like we do in the current code.

Of course, the simplest option is to just not pass theDIR * into the new interpreter, which resolves the original issue in#10387, but is as backward (in)compatible as this change.

@Leont
Copy link
ContributorAuthor

I'm not sure it's safe for multiple threads to readdir() from the same underlying fd: It's UB for both parent and child of a fork() to read from their corresponding copies of the DIR, which is the closest case I can think of to this, so I'm not sure this will be thread safe.

It's not, but the same is true across forks. The same is also true across threads for filehandles, really. This all falls firmly in "doctor it hurts when I poke into my eyeballs" IMO.

@ap
Copy link
Contributor

ap commentedApr 24, 2025

Any movement here?

@Leont
Copy link
ContributorAuthor

Any movement here?

I suspect I know how to write the missing parts in a fairly short time, but I'm not sure I'd be comfortable including it this late in the release cycle

@ap
Copy link
Contributor

ap commentedMay 22, 2025

Note that@vinc17fr has justposted to oss-security regarding#23010.

@LeontLeontforce-pushed theleont/thread-dirhandle branch 2 times, most recently fromfa1e010 toa8f1068CompareMay 23, 2025 13:48
jkeenan
jkeenan previously requested changesMay 23, 2025
@LeontLeontforce-pushed theleont/thread-dirhandle branch froma8f1068 toe521195CompareMay 23, 2025 15:06
@LeontLeont marked this pull request as ready for reviewMay 23, 2025 15:06
@@ -199,6 +199,7 @@ d_fd_macros='define'
d_fd_set='define'
d_fdclose='undef'
d_fdim='undef'
d_fdopendir='undef'
Copy link
Contributor

@khwilliamsonkhwilliamsonMay 23, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

ShouldHAS_FDOPENDIR be added tometaconfig.h

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I suspect not, but@Tux would know for sure

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

As far as I can tell it only matters when regenerating Configure from metaconfig anyway. So I propose we leave it out for now and if it turns out to be necessary Tux can add it later when he comes back from his vacation.

@LeontLeontforce-pushed theleont/thread-dirhandle branch frome521195 to7327645CompareMay 23, 2025 20:20
@ap
Copy link
Contributor

ap commentedMay 27, 2025

Given that Windows has its own logic for dirhandle dup’ing, thatfdopendir is in POSIX same asfchdir is (and apparentlyfdopendir is actually the older one), and that both appear to be widely supported in mainstream Unixes, it seems that deleting thefchdir implementation would not shift our platform support posture materially, if at all. Only some obscure platforms may be affected.

I’ve discussed with@book and we agreed to drop thefchdir logic. We haven’t been able to reach@haarg so maybe he’ll object, but please amend the patch accordingly so it’s ready to go if he agrees, since we’re already late on the point release. (If he objects it will be easy enough to just use the current state of the patch.)

@haarg
Copy link
Contributor

I concur that preserving thefchdir code path seems like a bad idea.

@LeontLeontforce-pushed theleont/thread-dirhandle branch from7327645 to9a3e1edCompareMay 27, 2025 19:43
These tests makes assumptions that are only true for the current fchdirbased implementation of dirhandle cloning. In particular that the cloneddirhandle is entirely separate from the original. This is notappropriate for the upcoming fdopendir based implementation.
This uses fdopendir and dup to dirhandles. Unlike the fchdir approachthese handles share descriptor position among threads.
This is no longer needed now that the fdopendir implementation exists.
@LeontLeontforce-pushed theleont/thread-dirhandle branch from9a3e1ed toc8d71d0CompareMay 27, 2025 19:46
@apap merged commit5c2e757 intobleadMay 28, 2025
67 checks passed
@apap deleted the leont/thread-dirhandle branchMay 28, 2025 00:30
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@khwilliamsonkhwilliamsonkhwilliamson left review comments

@jkeenanjkeenanjkeenan left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@Leont@tonycoz@ap@haarg@jkeenan@khwilliamson

[8]ページ先頭

©2009-2025 Movatter.jp