DF-2716 / fix.diff
--- a/sys/kern/vfs_nlookup.c +++ b/sys/kern/vfs_nlookup.c @@ -647,11 +647,18 @@ * Optimize by passing-in NULL for any prior components, which may * allow the code to bypass the naccess() call. * + * NOTE: Whether the current component is the last one must be + * determined with islastelement(), which skips trailing slashes. + * Testing *nptr != '/' misclassifies the parent directory of a leaf + * followed by a trailing '/' as an intermediate directory and drops + * the NLC_STICKY / NLC_APPENDONLY feedback flags, bypassing the + * sticky-bit and append-only directory deletion restrictions. + * * naccess() is optimized to avoid having to lock the nch or get * the related vnode if cached perms are sufficient. */ dflags = 0; - if (*nptr == '/' || (saveflag & NLC_MODIFYING_MASK) == 0) { + if (islastelement(nptr) == 0 || (saveflag & NLC_MODIFYING_MASK) == 0) { error = naccess(nd, &nd->nl_nch, &nl_gen, NLC_EXEC, nd->nl_cred, NULL, 0); } else { |