MWI: Fix missing O_CLOEXEC in botfs.openSecure() and other issues#55411
Merged
timothyb89 merged 4 commits intomasterfrom Jun 6, 2025
Merged
MWI: Fix missing O_CLOEXEC in botfs.openSecure() and other issues#55411timothyb89 merged 4 commits intomasterfrom
botfs.openSecure() and other issues#55411timothyb89 merged 4 commits intomasterfrom
Conversation
This fixes various issues in botfs's `openSecure` implementation for Linux, particularly: - Added missing `O_CLOEXEC` flag to `openat2()` flags - Added EINTR retry loop to follow the stdlib's `OpenFile()` implementation. - Remove `O_CREATE` from `ReadFlags`, and convert it to a pseudo-enum so we can accurately predict intent (see next item) - Pass `0` mode to `openat2()` when reading (see above) - Renamed confusingly named `OpenMode` to `OpenFlags`, because it corresponds to flags, not file modes. - Fixed coincidentally correct misuse of `unix.O_RDONLY` Note that while removing `O_CREATE` from read flags is technically a breaking change, we still automatically files downstream as needed. This results in a "new" debug-level log, but not any actual behavior change.
espadolini
approved these changes
Jun 4, 2025
| return os.NewFile(uintptr(fd), filepath.Base(path)), nil | ||
| // os.File.Close() appears to close wrapped files sanely, so rely on that | ||
| // rather than relying on callers to use unix.Close(fd) | ||
| return os.NewFile(uintptr(fd), filepath.Base(path)), nil |
Contributor
There was a problem hiding this comment.
nit: the .Name() of a file opened with os.OpenFile (and thus openStandard, I guess) is the unmodified path passed to OpenFile, do we have to modify the name here?
Contributor
Author
There was a problem hiding this comment.
Good catch, I don't think name is actually used at all so it's a harmless change. I also caught a note in the godoc for os.NewFile() about it potentially returning a nil in some cases, so I've also added a check to convert that into an error.
zmb3
approved these changes
Jun 4, 2025
strideynet
approved these changes
Jun 4, 2025
Contributor
|
@timothyb89 See the table below for backport results.
|
This was referenced Jun 6, 2025
timothyb89
added a commit
that referenced
this pull request
Jun 6, 2025
…sues (#55411) Backport of #55411 for branch/v16 --- * MWI: Fix missing O_CLOEXEC in `botfs.openSecure()` and other issues This fixes various issues in botfs's `openSecure` implementation for Linux, particularly: - Added missing `O_CLOEXEC` flag to `openat2()` flags - Added EINTR retry loop to follow the stdlib's `OpenFile()` implementation. - Remove `O_CREATE` from `ReadFlags`, and convert it to a pseudo-enum so we can accurately predict intent (see next item) - Pass `0` mode to `openat2()` when reading (see above) - Renamed confusingly named `OpenMode` to `OpenFlags`, because it corresponds to flags, not file modes. - Fixed coincidentally correct misuse of `unix.O_RDONLY` Note that while removing `O_CREATE` from read flags is technically a breaking change, we still automatically files downstream as needed. This results in a "new" debug-level log, but not any actual behavior change. * Fix lint * Simplify mode conditional, fix comments * Handle potentially nil file returns from `os.OpenFile`
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Jun 10, 2025
…sues (#55411) (#55504) Backport of #55411 for branch/v16 --- * MWI: Fix missing O_CLOEXEC in `botfs.openSecure()` and other issues This fixes various issues in botfs's `openSecure` implementation for Linux, particularly: - Added missing `O_CLOEXEC` flag to `openat2()` flags - Added EINTR retry loop to follow the stdlib's `OpenFile()` implementation. - Remove `O_CREATE` from `ReadFlags`, and convert it to a pseudo-enum so we can accurately predict intent (see next item) - Pass `0` mode to `openat2()` when reading (see above) - Renamed confusingly named `OpenMode` to `OpenFlags`, because it corresponds to flags, not file modes. - Fixed coincidentally correct misuse of `unix.O_RDONLY` Note that while removing `O_CREATE` from read flags is technically a breaking change, we still automatically files downstream as needed. This results in a "new" debug-level log, but not any actual behavior change. * Fix lint * Simplify mode conditional, fix comments * Handle potentially nil file returns from `os.OpenFile`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes various issues in botfs's
openSecureimplementation for Linux, particularly:O_CLOEXECflag toopenat2()flagsOpenFile()implementation.O_CREATEfromReadFlags, and convert it to a pseudo-enum so we can accurately predict intent (see next item)0mode toopenat2()when reading (see above)OpenModetoOpenFlags, because it corresponds to flags, not file modes.unix.O_RDONLYNote that while removing
O_CREATEfrom read flags is technically a breaking change, we still automatically files downstream as needed. This results in a "new" debug-level log, but not any actual behavior change.changelog: The
tbotclient now ensures theO_CLOEXECflag is used when opening files on Linux hosts