Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/client/dfs/dfs_internal.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* (C) Copyright 2019-2024 Intel Corporation.
* (C) Copyright 2026 Hewlett Packard Enterprise Development LP
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
Expand Down Expand Up @@ -419,4 +420,7 @@ update_stbuf_times(struct dfs_entry entry, daos_epoch_t max_epoch, struct stat *
int
lookup_rel_path(dfs_t *dfs, dfs_obj_t *root, const char *path, int flags, dfs_obj_t **_obj,
mode_t *mode, struct stat *stbuf, size_t depth);
int
follow_symlink(dfs_t *dfs, dfs_obj_t *parent, const char *value, int flags, dfs_obj_t **_obj,
mode_t *mode, struct stat *stbuf, size_t depth);
#endif /* __DFS_INTERNAL_H__ */
26 changes: 21 additions & 5 deletions src/client/dfs/lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@

#include "dfs_internal.h"

/* A symlink value is resolved from the directory holding the link. dfs has no notion of the
* process root that POSIX resolves an absolute value from, so such a value is rejected wherever
* the link sits and left to a caller that can resolve it, as dfuse and pil4dfs do with the kernel.
*/
int
follow_symlink(dfs_t *dfs, dfs_obj_t *parent, const char *value, int flags, dfs_obj_t **_obj,
mode_t *mode, struct stat *stbuf, size_t depth)
{
if (value[0] == '/') {
D_DEBUG(DB_TRACE, "Cannot follow absolute symlink value %s\n", value);
return EINVAL;
}

return lookup_rel_path(dfs, parent, value, flags, _obj, mode, stbuf, depth);
}

int
lookup_rel_path(dfs_t *dfs, dfs_obj_t *root, const char *path, int flags, dfs_obj_t **_obj,
mode_t *mode, struct stat *stbuf, size_t depth)
Expand Down Expand Up @@ -195,8 +211,8 @@ lookup_rel_path(dfs_t *dfs, dfs_obj_t *root, const char *path, int flags, dfs_ob
D_GOTO(err_obj, rc = ENOTSUP);
}

rc = lookup_rel_path(dfs, &parent, entry.value, flags, &sym, NULL,
NULL, depth + 1);
rc = follow_symlink(dfs, &parent, entry.value, flags, &sym, NULL,
NULL, depth + 1);
if (rc) {
D_DEBUG(DB_TRACE, "Failed to lookup symlink %s\n",
entry.value);
Expand Down Expand Up @@ -229,8 +245,8 @@ lookup_rel_path(dfs_t *dfs, dfs_obj_t *root, const char *path, int flags, dfs_ob
D_GOTO(err_obj, rc = ENOTSUP);
}

rc = lookup_rel_path(dfs, &parent, entry.value, flags, &sym, mode,
stbuf, depth + 1);
rc = follow_symlink(dfs, &parent, entry.value, flags, &sym, mode,
stbuf, depth + 1);
if (rc) {
D_DEBUG(DB_TRACE, "Failed to lookup symlink %s\n",
entry.value);
Expand Down Expand Up @@ -506,7 +522,7 @@ lookup_rel_int(dfs_t *dfs, dfs_obj_t *parent, const char *name, int flags, dfs_o
if (entry.value == NULL)
D_GOTO(err_obj, rc = EIO);
/* dereference the symlink */
rc = lookup_rel_path(dfs, parent, entry.value, flags, &sym, mode, stbuf, 0);
rc = follow_symlink(dfs, parent, entry.value, flags, &sym, mode, stbuf, 0);
if (rc) {
D_DEBUG(DB_TRACE, "Failed to lookup symlink %s\n", entry.value);
D_FREE(entry.value);
Expand Down
6 changes: 3 additions & 3 deletions src/client/dfs/obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ dfs_access(dfs_t *dfs, dfs_obj_t *parent, const char *name, int mask)

D_ASSERT(entry.value);

rc = lookup_rel_path(dfs, parent, entry.value, O_RDONLY, &sym, NULL, NULL, 0);
rc = follow_symlink(dfs, parent, entry.value, O_RDONLY, &sym, NULL, NULL, 0);
if (rc) {
D_DEBUG(DB_TRACE, "Failed to lookup symlink %s\n", entry.value);
D_GOTO(out, rc);
Expand Down Expand Up @@ -1214,7 +1214,7 @@ dfs_chmod(dfs_t *dfs, dfs_obj_t *parent, const char *name, mode_t mode)
if (S_ISLNK(entry.mode)) {
D_ASSERT(entry.value);

rc = lookup_rel_path(dfs, parent, entry.value, O_RDWR, &sym, NULL, NULL, 0);
rc = follow_symlink(dfs, parent, entry.value, O_RDWR, &sym, NULL, NULL, 0);
if (rc) {
D_ERROR("Failed to lookup symlink %s\n", entry.value);
D_FREE(entry.value);
Expand Down Expand Up @@ -1341,7 +1341,7 @@ dfs_chown(dfs_t *dfs, dfs_obj_t *parent, const char *name, uid_t uid, gid_t gid,
/** resolve symlink */
if (!(flags & O_NOFOLLOW) && S_ISLNK(entry.mode)) {
D_ASSERT(entry.value);
rc = lookup_rel_path(dfs, parent, entry.value, O_RDWR, &sym, NULL, NULL, 0);
rc = follow_symlink(dfs, parent, entry.value, O_RDWR, &sym, NULL, NULL, 0);
if (rc) {
D_DEBUG(DB_TRACE, "Failed to lookup symlink '%s': %d (%s)\n", entry.value,
rc, strerror(rc));
Expand Down
12 changes: 11 additions & 1 deletion src/client/dfuse/pil4dfs/dfs_dcache.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* (C) Copyright 2022-2024 Intel Corporation.
* (C) Copyright 2026 Hewlett Packard Enterprise Development LP
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
*/
Expand Down Expand Up @@ -674,8 +675,17 @@ dcache_find_insert_act(dfs_dcache_t *dcache, char *path, size_t path_len, dcache
name_len = 0;
while (name + name_len < path + path_len && name[name_len] != '/')
++name_len;
if (name_len == 0)
if (name_len == 0) {
/* An empty component would silently return a partial parent. The path is
* normalized by the caller, so this is a bug rather than a user error.
*/
if (name < path + path_len) {
D_ERROR("empty component in path " DF_PATH "\n", DP_PATH(path));
drec_decref(dcache, rec_tmp);
D_GOTO(out, rc = -DER_INVAL);
}
break;
}

key_prefix = &rec_tmp->dr_key_child_prefix[0];
parent = rec_tmp;
Expand Down
Loading
Loading