-.\" $OpenBSD: link.2,v 1.29 2015/09/10 17:55:21 schwarze Exp $
+.\" $OpenBSD: link.2,v 1.30 2024/03/25 17:57:07 guenther Exp $
.\" $NetBSD: link.2,v 1.7 1995/02/27 12:34:01 cgd Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\"
.\" @(#)link.2 8.3 (Berkeley) 1/12/94
.\"
-.Dd $Mdocdate: September 10 2015 $
+.Dd $Mdocdate: March 25 2024 $
.Dt LINK 2
.Os
.Sh NAME
.It Bq Er EPERM
The file named by
.Fa name1
-is a directory and the effective
-user ID is not superuser,
-or the file system containing the file does not permit the use of
-.Fn link
-on a directory.
+is a directory.
.It Bq Er EPERM
The file named by
.Fa name1
-/* $OpenBSD: vfs_syscalls.c,v 1.363 2024/02/03 18:51:58 beck Exp $ */
+/* $OpenBSD: vfs_syscalls.c,v 1.364 2024/03/25 17:57:07 guenther Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
/*
struct vnode *vp;
struct nameidata nd;
int error, follow;
- int flags;
if (flag & ~AT_SYMLINK_FOLLOW)
return (EINVAL);
return (error);
vp = nd.ni_vp;
- flags = LOCKPARENT;
if (vp->v_type == VDIR) {
- flags |= STRIPSLASHES;
+ error = EPERM;
+ goto out;
}
- NDINITAT(&nd, CREATE, flags, UIO_USERSPACE, fd2, path2, p);
+ NDINITAT(&nd, CREATE, LOCKPARENT, UIO_USERSPACE, fd2, path2, p);
nd.ni_pledge = PLEDGE_CPATH;
nd.ni_unveil = UNVEIL_CREATE;
if ((error = namei(&nd)) != 0)
error = EEXIST;
goto out;
}
+
+ /* No cross-mount links! */
+ if (nd.ni_dvp->v_mount != vp->v_mount) {
+ VOP_ABORTOP(nd.ni_dvp, &nd.ni_cnd);
+ vput(nd.ni_dvp);
+ error = EXDEV;
+ goto out;
+ }
+
error = VOP_LINK(nd.ni_dvp, vp, &nd.ni_cnd);
out:
vrele(vp);
-/* $OpenBSD: fuse_vnops.c,v 1.67 2023/09/08 20:00:28 mvs Exp $ */
+/* $OpenBSD: fuse_vnops.c,v 1.68 2024/03/25 17:57:07 guenther Exp $ */
/*
* Copyright (c) 2012-2013 Sylvestre Gallon <ccna.syl@gmail.com>
*
error = ENOSYS;
goto out2;
}
- if (vp->v_type == VDIR) {
- VOP_ABORTOP(dvp, cnp);
- error = EPERM;
- goto out2;
- }
- if (dvp->v_mount != vp->v_mount) {
- VOP_ABORTOP(dvp, cnp);
- error = EXDEV;
- goto out2;
- }
if (dvp != vp && (error = vn_lock(vp, LK_EXCLUSIVE))) {
VOP_ABORTOP(dvp, cnp);
goto out2;
-/* $OpenBSD: nfs_serv.c,v 1.122 2023/03/08 04:43:09 guenther Exp $ */
+/* $OpenBSD: nfs_serv.c,v 1.123 2024/03/25 17:57:07 guenther Exp $ */
/* $NetBSD: nfs_serv.c,v 1.34 1997/05/12 23:37:12 fvdl Exp $ */
/*
error = 0;
goto nfsmout;
}
- if (vp->v_type == VDIR && (error = suser_ucred(cred)) != 0)
+ if (vp->v_type == VDIR)
goto out1;
NDINIT(&nd, CREATE, LOCKPARENT, UIO_SYSSPACE, NULL, procp);
-/* $OpenBSD: nfs_vnops.c,v 1.193 2023/04/26 10:00:37 beck Exp $ */
+/* $OpenBSD: nfs_vnops.c,v 1.194 2024/03/25 17:57:07 guenther Exp $ */
/* $NetBSD: nfs_vnops.c,v 1.62.4.1 1996/07/08 20:26:52 jtc Exp $ */
/*
info.nmi_v3 = NFS_ISV3(vp);
- if (dvp->v_mount != vp->v_mount) {
- pool_put(&namei_pool, cnp->cn_pnbuf);
- vput(dvp);
- return (EXDEV);
- }
error = vn_lock(vp, LK_EXCLUSIVE);
if (error != 0) {
VOP_ABORTOP(dvp, cnp);
-/* $OpenBSD: tmpfs_vnops.c,v 1.53 2023/09/08 20:00:28 mvs Exp $ */
+/* $OpenBSD: tmpfs_vnops.c,v 1.54 2024/03/25 17:57:07 guenther Exp $ */
/* $NetBSD: tmpfs_vnops.c,v 1.100 2012/11/05 17:27:39 dholland Exp $ */
/*
int error;
KASSERT(VOP_ISLOCKED(dvp));
-
- if (vp->v_type == VDIR) {
- VOP_ABORTOP(dvp, cnp);
- vput(dvp);
- return EPERM;
- }
-
KASSERT(dvp != vp);
- if (dvp->v_mount != vp->v_mount) {
- VOP_ABORTOP(dvp, cnp);
- vput(dvp);
- return EXDEV;
- }
-
dnode = VP_TO_TMPFS_DIR(dvp);
node = VP_TO_TMPFS_NODE(vp);
-/* $OpenBSD: ext2fs_vnops.c,v 1.91 2023/03/08 04:43:09 guenther Exp $ */
+/* $OpenBSD: ext2fs_vnops.c,v 1.92 2024/03/25 17:57:07 guenther Exp $ */
/* $NetBSD: ext2fs_vnops.c,v 1.1 1997/06/11 09:34:09 bouyer Exp $ */
/*
if ((cnp->cn_flags & HASBUF) == 0)
panic("ext2fs_link: no name");
#endif
- if (vp->v_type == VDIR) {
- VOP_ABORTOP(dvp, cnp);
- error = EISDIR;
- goto out2;
- }
- if (dvp->v_mount != vp->v_mount) {
- VOP_ABORTOP(dvp, cnp);
- error = EXDEV;
- goto out2;
- }
if (dvp != vp && (error = vn_lock(vp, LK_EXCLUSIVE))) {
VOP_ABORTOP(dvp, cnp);
goto out2;
-/* $OpenBSD: ufs_vnops.c,v 1.160 2024/02/03 18:51:59 beck Exp $ */
+/* $OpenBSD: ufs_vnops.c,v 1.161 2024/03/25 17:57:07 guenther Exp $ */
/* $NetBSD: ufs_vnops.c,v 1.18 1996/05/11 18:28:04 mycroft Exp $ */
/*
if ((cnp->cn_flags & HASBUF) == 0)
panic("ufs_link: no name");
#endif
- if (vp->v_type == VDIR) {
- VOP_ABORTOP(dvp, cnp);
- error = EPERM;
- goto out2;
- }
- if (dvp->v_mount != vp->v_mount) {
- VOP_ABORTOP(dvp, cnp);
- error = EXDEV;
- goto out2;
- }
if (dvp != vp && (error = vn_lock(vp, LK_EXCLUSIVE))) {
VOP_ABORTOP(dvp, cnp);
goto out2;