-/* $OpenBSD: kern_unveil.c,v 1.7 2018/07/29 23:53:04 beck Exp $ */
+/* $OpenBSD: kern_unveil.c,v 1.8 2018/07/30 00:34:57 deraadt Exp $ */
/*
* Copyright (c) 2017-2018 Bob Beck <beck@openbsd.org>
}
void
-unveil_free_traversed_vnodes(struct nameidata *ndp) {
+unveil_free_traversed_vnodes(struct nameidata *ndp)
+{
if (ndp->ni_tvpsize) {
size_t i;
+
for (i = 0; i < ndp->ni_tvpend; i++)
vrele(ndp->ni_tvp[i]); /* ref for being in list */
free(ndp->ni_tvp, M_PROC, ndp->ni_tvpsize * sizeof(struct vnode *));
}
void
-unveil_save_traversed_vnode(struct nameidata *ndp, struct vnode *vp) {
+unveil_save_traversed_vnode(struct nameidata *ndp, struct vnode *vp)
+{
if (ndp->ni_tvpsize == 0) {
ndp->ni_tvp = mallocarray(MAXPATHLEN, sizeof(struct vnode *),
M_PROC, M_WAITOK);
*/
if (pr->ps_uvshrink) {
size_t i = 0, j;
+
while (i < pr->ps_uvvcount) {
if (uv[i].uv_vp == NULL) {
pr->ps_uvncount -= unveil_delete_names(&uv[i]);
if (pr->ps_uvpcwd) {
printf("unveil: %s(%d): did not nuke cwd because %p != %p\n",
p->p_p->ps_comm, p->p_p->ps_pid, vp, pr->ps_uvpcwd->uv_vp);
- }
- else
+ } else
printf("unveil: %s(%d): cwd is null\n",
p->p_p->ps_comm, p->p_p->ps_pid);
-
}
#endif
*/
if (ndp->ni_tvpsize) {
size_t i;
+
for (i = 0; i < ndp->ni_tvpend; i++) {
struct vnode *vp = ndp->ni_tvp[i];
if (unveil_lookup(vp, p) == NULL) {
directory_add = ndp->ni_vp != NULL && ndp->ni_vp->v_type == VDIR;
if (directory_add)
- vp=ndp->ni_vp;
+ vp = ndp->ni_vp;
else
- vp=ndp->ni_dvp;
+ vp = ndp->ni_dvp;
KASSERT(vp->v_type == VDIR);
vref(vp);
}
}
- } else {
+ } else {
/*
* New unveil involving this directory vnode.
*/
* unveil checking - for component directories in a namei lookup.
*/
void
-unveil_check_component(struct proc *p, struct nameidata *ni, struct vnode *dp )
+unveil_check_component(struct proc *p, struct nameidata *ni, struct vnode *dp)
{
struct unveil *uv = NULL;
}
}
}
- }
- else
+ } else
unveil_save_traversed_vnode(ni, dp);
}
ni->ni_unveil_match->uv_vp);
#endif
return (0);
- }
- else if (p->p_p->ps_uvpcwd) {
+ } else if (p->p_p->ps_uvpcwd) {
ni->ni_unveil_match = p->p_p->ps_uvpcwd;
#ifdef DEBUG_UNVEIL
printf("unveil: %s(%d): used cwd unveil vnode from vnode %p\n",
#endif
LIST_FOREACH(pr, &allprocess, ps_list) {
struct unveil * uv;
+
if ((uv = unveil_lookup(vp, pr->ps_mainproc)) != NULL) {
uv->uv_vp = NULL;
uv->uv_flags = 0;