Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NAS-126719 / Add O_RESOLVE_NO_SYMLINKS #268

Open
wants to merge 1 commit into
base: truenas/13.1-stable
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions sys/kern/vfs_lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ __FBSDID("$FreeBSD$");
#define NAMEI_DIAGNOSTIC 1
#undef NAMEI_DIAGNOSTIC

FEATURE(rnosymlink, "supports RESOLVE_NO_SYMLINK");
FEATURE(rbeneath, "supports RESOLVE_BENEATH");

SDT_PROVIDER_DEFINE(vfs);
SDT_PROBE_DEFINE4(vfs, namei, lookup, entry, "struct vnode *", "char *",
"unsigned long", "bool");
Expand Down Expand Up @@ -1192,6 +1195,11 @@ lookup(struct nameidata *ndp)
error = ENOENT;
goto bad2;
}
if (cnp->cn_flags & RNOSYMLINK) {
/* Linux openat2() behavior for RESOLVE_NO_SYMLINKS */
error = ELOOP;
goto bad2;
}
if (dp->v_mount->mnt_flag & MNT_NOSYMFOLLOW) {
error = EACCES;
goto bad2;
Expand Down
2 changes: 2 additions & 0 deletions sys/kern/vfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ open2nameif(int fmode, u_int vn_open_flags)
res = ISOPEN | LOCKLEAF;
if ((fmode & O_RESOLVE_BENEATH) != 0)
res |= RBENEATH;
if ((fmode & O_RESOLVE_NO_SYMLINKS) != 0)
res |= RNOSYMLINK;
if ((fmode & O_EMPTY_PATH) != 0)
res |= EMPTYPATH;
if ((vn_open_flags & VN_OPEN_NOAUDIT) == 0)
Expand Down
1 change: 1 addition & 0 deletions sys/sys/fcntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ typedef __pid_t pid_t;
#define O_DSYNC 0x01000000 /* POSIX data sync */
#if __BSD_VISIBLE
#define O_EMPTY_PATH 0x02000000
#define O_RESOLVE_NO_SYMLINKS 0x04000000
#endif

/*
Expand Down
1 change: 1 addition & 0 deletions sys/sys/namei.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ int cache_fplookup(struct nameidata *ndp, enum cache_fpl_status *status,
#define LOCKSHARED 0x0100 /* Shared lock leaf */
#define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */
#define RBENEATH 0x100000000ULL /* No escape, even tmp, from start dir */
#define RNOSYMLINK 0x200000000ULL /* Do not follow any symbolic links */
#define MODMASK 0xf000001ffULL /* mask of operational modifiers */

/*
Expand Down