Skip to content

Commit

Permalink
Do not follow links when doing "chown"
Browse files Browse the repository at this point in the history
There is a potential issue with allowing a "chown" operation
to follow user-created links, so let's limit any use of that
function to "lchown" - which directs the "chown" operation to
NOT follow a link.

Signed-off-by: Ralph Castain <rhc@pmix.org>
  • Loading branch information
rhc54 committed Sep 7, 2023
1 parent dfab3b3 commit ae62cdf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/util/pmix_pty.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* All rights reserved.
* Copyright (c) 2018 Cisco Systems, Inc. All rights reserved
* Copyright (c) 2019-2020 Intel, Inc. All rights reserved.
* Copyright (c) 2021 Nanook Consulting. All rights reserved.
* Copyright (c) 2021-2023 Nanook Consulting. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -244,7 +244,7 @@ static int ptys_open(int fdm, char *pts_name)
gid = -1; /* group tty is not in the group file */
}
/* following two functions don't work unless we're root */
chown(pts_name, getuid(), gid);
lchown(pts_name, getuid(), gid); // DO NOT FOLLOW LINKS
chmod(pts_name, S_IRUSR | S_IWUSR | S_IWGRP);
fds = open(pts_name, O_RDWR);
if (fds < 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/util/pmix_shmem.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2021-2023 Triad National Security, LLC. All rights reserved.
* Copyright (c) 2022 Nanook Consulting. All rights reserved.
* Copyright (c) 2022-2023 Nanook Consulting. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
Expand Down Expand Up @@ -198,7 +198,7 @@ pmix_shmem_segment_chown(
) {
pmix_status_t rc = PMIX_SUCCESS;

if (chown(shmem->backing_path, owner, group) != 0) {
if (lchown(shmem->backing_path, owner, group) != 0) { // DO NOT FOLLOW LINKS
rc = PMIX_ERROR;
PMIX_ERROR_LOG(rc);
}
Expand Down

0 comments on commit ae62cdf

Please sign in to comment.