Skip to content

Commit 6cfe2d4

Browse files
srd424poettering
authored andcommitted
Call stat again after changing ownership of created files, so we detect
reset setuid/setgid bits and reset them.
1 parent d246d6d commit 6cfe2d4

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

src/cadecoder.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3654,8 +3654,21 @@ static int ca_decoder_finalize_child(CaDecoder *d, CaDecoderNode *n, CaDecoderNo
36543654
}
36553655
if (r < 0)
36563656
return -errno;
3657-
}
3658-
}
3657+
3658+
/* on Linux, changing ownership can reset setuid/setgid bits. stat() the
3659+
file again so permission checking code below knows the new
3660+
state of affairs */
3661+
if (child->fd >= 0)
3662+
r = fstat(child->fd, &st);
3663+
else {
3664+
assert(dir_fd >= 0);
3665+
3666+
r = fstatat(dir_fd, name, &st, AT_SYMLINK_NOFOLLOW);
3667+
}
3668+
if (r < 0)
3669+
return -errno;
3670+
}
3671+
}
36593672

36603673
if (d->replay_feature_flags & CA_FORMAT_WITH_READ_ONLY) {
36613674

0 commit comments

Comments
 (0)