-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-31940: Reject faulty lchown implementations #4267
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-31940: Reject faulty lchown implementations #4267
Conversation
54aeb10 to
ad495d0
Compare
fruch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't argue with running tests :)
vstinner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dislike checking once in configure, since the platform used to build Python can be different than the platform used to run Python. There is a similar issue for Linux vendors using different kernel versions to build packages than the kernel used in the latest version of the distro.
IMHO the right fix is to check at runtime (in Python, not in configure) if os.lchmod() works: a check in shutil and another check in test_shutil (to skip tests).
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
|
@Haypo can you point us in the direction of such type of runtime checks ? are there existing similar runtime checks as you're suggesting ? |
|
@fruch I think I can do something similar to what I proposed here: https://bugs.python.org/issue31940#msg305528 just need to fix up the tests to not use |
Some examples:
|
|
if lchown it's not working on alpine as expected, why keep using it ? I guess it can fail in more use cases. and disabling in compile time sounds a safer option to me. skipping tests mean some things are not working on alpine, and no one would attended to it, cause all tests are passing... |
You may build Python on Debian with a working lchmod and run it on Alpine which has a broken lchmod: bug. You may build Python on Alphine with a broken lchmod and run it on Debian which has a working lchmod: if you disable lchmod, you miss the feature on Debian. configure is not the right place to implement the check. It should be done at runtime. The os module is designed to a thin wrapper of OS functions. shutil is more a high-level module handling low-level stuff for the user. |
|
@Haypo that actually doesn't work today, for example on ubuntu xenial (debian) there is no That said, I'm looking for ways to improve this that don't involve |
|
Notably this block probably also need to be applied to Lines 2794 to 2817 in ad455cd
|
|
I suggest to leave this PR unchanged, since I'm not sure anymore that a runtime check is the best option (see the discussion on the issue). If you want to implement runtime checks, please open a new PR. |
|
@Haypo cool, I'm going to wait to pursue that further until I hear back on the issue, in the meantime, here's the start of that idea (passing the same set of tests, but there's much more that can be done I assume): asottile@61095aa |
|
seems like you guys were busy, while I was sleeping :) @Haypo, thanks for keeping an open mind, I'm impressed. canadian/cross compiling is a major pain (I come from a background of lots of embedded work). and I think that distribution/package owner that will try those types of crazy mixtures is bound to a world of pain. (lchmod will be the least of his problems) I'll put my vote on users experience over "crazy" distribution/package owners. even that in cases of linux headers and versions it's can be a tricker question as you suggest, cause user can do all kinds of mixtures there. But in our case users can't swap glibc version, or even implementations of libc that easily. |
My examples are not theorical, but issues that I saw in practice. People are already doing that. Maybe not with different Linux distributions, but at least with different versions of the same distribution. Another example: we provide a single binary for all Windows versions, so we load some functions at runtime and check if there are available on the current Windows versions. Python also checks the Windows version at many places. Another example: we also provide a single binary for all macOS versions. For example, the poll() function of macOS is regulary broken, so we implement some checks at runtime... |
|
I just started seeing this same issue on Gentoo+musl as well. It's quite fortuitous for me that this thread was already ongoing! So, are folks still deciding whether to do run-time or compile-time checks?
So, I think I'd vote for compile-time as well. |
|
I think @vstinner already agreed to first do a compile time, and make the runtime in different PR |
|
what is the next step ? we need someone from core-dev to approve ? |
|
Looks like if @vstinner was OK with it as-is for now, we need their review status changed? |
|
I think the idea was to leave this one open for consideration (in case others agreed that a compile time check is ok) and make a separate runtime PR (which'll actually get included) -- I haven't had time to finish my runtime approach yet though I've gotten encouraging remarks on the WIP commit: asottile@61095aa |
rm-you
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comments are about docs and style, I think the code is fine (though in some cases really hard for me to parse due to lack of indentation).
| @@ -0,0 +1,2 @@ | |||
| Detect faulty ``lchmod`` implementation to fix ``shutil.copystat`` on alpine | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be useful to say "on Alpine linux and other distributions using musl libc", because the issue is actually related to the musl implementation, I believe. This affects me on Gentoo+musl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, I did hit this on gentoo musl as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh shoot, I totally forgot about this patch -- I need to revive my other approach 😨
| fi | ||
|
|
||
|
|
||
| # on alpine, lchmod raises errno EOPNOTSUPP on symlinks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, technically not just Alpine, it's a musl libc thing.
| else | ||
| if test "$cross_compiling" = yes; then : | ||
| ac_cv_have_lchmod=cross | ||
| else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this else for the inner if-block? Should it be indented one level, along with an extra level for the cat command below it?
Actually, It looks like there's a ton of nested stuff below that isn't indented -- it makes it hard to read, but I don't know if that is a style thing I'm not used to since I haven't worked specifically in configure files much...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configure is entirely machine generated, the actual code is in configure.am
|
|
||
| fi | ||
| if test "$ac_cv_have_lchmod" = yes ; then | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra newlines for a reason? Also, not indented?
| fi | ||
|
|
||
|
|
||
| # on alpine, lchmod raises errno EOPNOTSUPP on symlinks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another mention of just Alpine, same suggestion as above.
|
@asottile Ok, that wasn't quite how I read it, but I guess that's fine. Honestly either one will solve the problem, and if you're willing to get the work done for the other method then hooray! 🎉 |
|
@asottile any news on this one ? |
|
Here's the other attempt at this: #4783 |
|
Figured I'd bump here too since the other PR hasn't gotten any attention. Here's the runtime implementation of this: #4783 -- a review on that would help greatly with moving this forward :) |
|
Closing this in favor of #4783 -- please review that! |
Verified by compiling with alpine using the following Dockerfile and test script:
Before
After
https://bugs.python.org/issue31940