-/* $OpenBSD: kern_unveil.c,v 1.51 2021/09/09 13:02:36 claudio Exp $ */
+/* $OpenBSD: kern_unveil.c,v 1.52 2022/01/09 10:28:07 claudio Exp $ */
/*
* Copyright (c) 2017-2019 Bob Beck <beck@openbsd.org>
size_t i = 0;
char c;
- *perms = 0;
+ *perms = UNVEIL_USERSET;
while ((c = permissions[i++]) != '\0') {
switch (c) {
case 'r':
if (ni->ni_vp != NULL && ni->ni_vp->v_type == VDIR) {
/* We are matching a directory terminal component */
uv = unveil_lookup(ni->ni_vp, pr, NULL);
- if (uv == NULL) {
+ if (uv == NULL || (uv->uv_flags & UNVEIL_USERSET) == 0) {
#ifdef DEBUG_UNVEIL
printf("unveil: %s(%d) no match for vnode %p\n",
pr->ps_comm, pr->ps_pid, ni->ni_vp);
#endif
+ if (uv != NULL)
+ ni->ni_unveil_match = uv;
goto done;
}
if (!unveil_flagmatch(ni, uv->uv_flags)) {
pr->ps_comm, pr->ps_pid, ni->ni_vp);
#endif
pr->ps_acflag |= AUNVEIL;
- if (uv->uv_flags & UNVEIL_USERSET)
+ if (uv->uv_flags & UNVEIL_MASK)
return EACCES;
else
return ENOENT;
#endif
/*
* If dir has user set restrictions fail with
- * EACCES. Otherwise, use any covering match
- * that we found above this dir.
+ * EACCES or ENOENT. Otherwise, use any covering
+ * match that we found above this dir.
*/
if (uv->uv_flags & UNVEIL_USERSET) {
pr->ps_acflag |= AUNVEIL;
- return EACCES;
+ if (uv->uv_flags & UNVEIL_MASK)
+ return EACCES;
+ else
+ return ENOENT;
}
/* start backtrack from this node */
ni->ni_unveil_match = uv;
pr->ps_comm, pr->ps_pid, uv->uv_vp);
#endif
pr->ps_acflag |= AUNVEIL;
- return EACCES;
+ if (uv->uv_flags & UNVEIL_MASK)
+ return EACCES;
+ else
+ return ENOENT;
}
#ifdef DEBUG_UNVEIL
printf("unveil: %s(%d) check cover for vnode %p, uv_cover %zd\n",
-/* $OpenBSD: namei.h,v 1.48 2021/09/02 12:35:23 claudio Exp $ */
+/* $OpenBSD: namei.h,v 1.49 2022/01/09 10:28:07 claudio Exp $ */
/* $NetBSD: namei.h,v 1.11 1996/02/09 18:25:20 christos Exp $ */
/*
#define UNVEIL_WRITE 0x02
#define UNVEIL_CREATE 0x04
#define UNVEIL_EXEC 0x08
-#define UNVEIL_USERSET 0x0F
+#define UNVEIL_USERSET 0x10
+#define UNVEIL_MASK 0x0F
#endif /* !_SYS_NAMEI_H_ */