From: David van Moolenbroek Date: Fri, 15 Jul 2016 14:29:16 +0000 (+0000) Subject: VFS: forbid mknod(2) on symlinks X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/doc/howto.html?a=commitdiff_plain;h=refs%2Fchanges%2F41%2F3341%2F1;p=minix.git VFS: forbid mknod(2) on symlinks As imposed by POSIX. Extend a random test to verify this behavior. Change-Id: Ib70550cefaeb9efd54e22312425263a5606fb5e8 --- diff --git a/minix/servers/vfs/open.c b/minix/servers/vfs/open.c index 0a8f91af6..5fd23b0d9 100644 --- a/minix/servers/vfs/open.c +++ b/minix/servers/vfs/open.c @@ -520,7 +520,8 @@ int do_mknod(void) mode_bits = job_m_in.m_lc_vfs_mknod.mode; dev = job_m_in.m_lc_vfs_mknod.device; - lookup_init(&resolve, fullpath, PATH_NOFLAGS, &vmp, &vp); + /* If the path names a symbolic link, mknod() shall fail with EEXIST. */ + lookup_init(&resolve, fullpath, PATH_RET_SYMLINK, &vmp, &vp); resolve.l_vmnt_lock = VMNT_WRITE; resolve.l_vnode_lock = VNODE_WRITE; diff --git a/minix/tests/test61.c b/minix/tests/test61.c index e70605387..423ec7fe9 100644 --- a/minix/tests/test61.c +++ b/minix/tests/test61.c @@ -66,8 +66,12 @@ void dangling_slink(int sub_test, char const slink_to[PATH_MAX]) /* Cleanup created files */ if (unlink(slink_to) == -1) e(18); - if (unlink("a") == -1) e(19); - if (unlink("c") == -1) e(20); + if (unlink("c") == -1) e(19); + + /* Use the dangling symlink to test mknod(2) following symlinks */ + if (mknod("a", S_IFCHR | 0777, makedev(1, 1)) != -1) e(20); + if (errno != EEXIST) e(21); + if (unlink("a") == -1) e(22); exit(EXIT_SUCCESS); } else {