This is an automated email from the ASF dual-hosted git repository.
rzo1 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/storm.git
The following commit(s) were added to refs/heads/master by this push:
new 6aa0066ab Apply worker file ownership and mode via an open descriptor
(#9006)
6aa0066ab is described below
commit 6aa0066abc713e1072604e27690a10563131a21b
Author: reiabreu <[email protected]>
AuthorDate: Mon Aug 24 11:59:42 2026 +0100
Apply worker file ownership and mode via an open descriptor (#9006)
* Apply worker file ownership and mode via an open descriptor
setup_permissions() opens each entry with O_NOFOLLOW, confirms via fstat
that it is still the same object fts_read() classified (matching device
and inode), and uses fchown/fchmod on that descriptor instead of lchown/
chmod by pathname.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
* Open worker tree entries with O_NONBLOCK to avoid blocking on a swapped
FIFO
O_NOFOLLOW rejects a symlink but not a FIFO, so if an entry is replaced by a
FIFO between fts_read() classifying it and the open, open(O_RDONLY) would
block
the launcher. O_NONBLOCK avoids that; it is a no-op for regular files and
directories, and the fstat device/inode check still rejects the swapped
object.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
---------
Co-authored-by: Claude Opus 4.8 <[email protected]>
---
.../native/worker-launcher/impl/worker-launcher.c | 40 ++++++++++++++++++++--
1 file changed, 37 insertions(+), 3 deletions(-)
diff --git a/storm-core/src/native/worker-launcher/impl/worker-launcher.c
b/storm-core/src/native/worker-launcher/impl/worker-launcher.c
index 53b8abef8..336f00880 100644
--- a/storm-core/src/native/worker-launcher/impl/worker-launcher.c
+++ b/storm-core/src/native/worker-launcher/impl/worker-launcher.c
@@ -505,12 +505,44 @@ static int copy_file(int input, const char* in_filename,
* If setgid_on_dir is FALSE, don't set sticky bit on group permission on the
directory.
*/
static int setup_permissions(FTSENT* entry, uid_t euser, int user_write,
boolean setgid_on_dir) {
- if (lchown(entry->fts_path, euser, launcher_gid) != 0) {
+ mode_t mode = entry->fts_statp->st_mode;
+ // O_NONBLOCK keeps the open from blocking if the entry has been replaced by
a
+ // FIFO between fts_read() classifying it and this open; it has no effect on
+ // regular files or directories, and fchown/fchmod on the descriptor still
work.
+ int open_flags = O_RDONLY | O_NOFOLLOW | O_CLOEXEC | O_NONBLOCK;
+ if ((mode & S_IFDIR) == S_IFDIR) {
+ open_flags = open_flags | O_DIRECTORY;
+ }
+ // Open the entry without following symlinks and apply the ownership and
+ // mode changes to that descriptor (fchown/fchmod) rather than by pathname,
+ // after confirming via fstat that it is still the same object fts_read()
+ // classified (same device and inode).
+ int fd = open(entry->fts_accpath, open_flags);
+ if (fd == -1) {
fprintf(ERRORFILE, "ERROR: Failure to exec app initialization process -
%s, fts_path=%s\n",
strerror(errno), entry->fts_path);
return -1;
}
- mode_t mode = entry->fts_statp->st_mode;
+ struct stat fd_stat;
+ if (fstat(fd, &fd_stat) != 0) {
+ fprintf(ERRORFILE, "ERROR: Failure to exec app initialization process -
%s, fts_path=%s\n",
+ strerror(errno), entry->fts_path);
+ close(fd);
+ return -1;
+ }
+ if (fd_stat.st_dev != entry->fts_statp->st_dev
+ || fd_stat.st_ino != entry->fts_statp->st_ino) {
+ fprintf(ERRORFILE, "ERROR: Directory entry changed during the walk, not
modifying it, fts_path=%s\n",
+ entry->fts_path);
+ close(fd);
+ return -1;
+ }
+ if (fchown(fd, euser, launcher_gid) != 0) {
+ fprintf(ERRORFILE, "ERROR: Failure to exec app initialization process -
%s, fts_path=%s\n",
+ strerror(errno), entry->fts_path);
+ close(fd);
+ return -1;
+ }
// Preserve user read and execute and set group read and write.
mode_t new_mode = (mode & (S_IRUSR | S_IXUSR)) | S_IRGRP | S_IWGRP;
if (user_write) {
@@ -523,11 +555,13 @@ static int setup_permissions(FTSENT* entry, uid_t euser,
int user_write, boolean
new_mode = new_mode | S_ISGID;
}
}
- if (chmod(entry->fts_path, new_mode) != 0) {
+ if (fchmod(fd, new_mode) != 0) {
fprintf(ERRORFILE, "ERROR: Failure to exec app initialization process -
%s, fts_path=%s\n",
strerror(errno), entry->fts_path);
+ close(fd);
return -1;
}
+ close(fd);
return 0;
}