On Mon, 3 Jun 2019, Hrvoje Popovski wrote:
> i'm having samba server, transmission client and gnome desktop on one
> box. from time to time i'm getting witness log below. source is clean
> and fetched few hours ago and compiled with WITNESS. userland and
> packages are up to date ..
> i put kern.witness.watch=3 in sysctl.conf so now i'm in ddb and will
> leave it like this if something is needed

>From [email protected] Sat Jun  1 13:25:04 2019
Date: Sat, 1 Jun 2019 13:25:00 -0700
From: Philip Guenther <[email protected]>
To: Antoine Jacoutot <[email protected]>
Cc: [email protected]
Subject: Re: witness and unveil

On Sat, 1 Jun 2019, Antoine Jacoutot wrote:
> Running a WITNESS kernel, mpi@ told me to send this here.
> 
> kern.version=OpenBSD 6.5-current (GENERIC.MP) #0: Sat Jun  1 18:29:16 CEST 
> 2019
> 
> witness: acquiring duplicate lock of same type: "&to->uv_lock"
>  1st unveil
>  2nd unveil

Give this diff a try.

Philip

Index: kern_unveil.c
===================================================================
RCS file: /data/src/openbsd/src/sys/kern/kern_unveil.c,v
retrieving revision 1.25
diff -u -p -r1.25 kern_unveil.c
--- kern_unveil.c       26 Mar 2019 13:41:40 -0000      1.25
+++ kern_unveil.c       1 Jun 2019 20:17:47 -0000
@@ -124,19 +124,25 @@ unveil_delete_names(struct unveil *uv)
 }
 
 void
-unveil_add_name(struct unveil *uv, char *name, u_char flags)
+unveil_add_name_unlocked(struct unveil *uv, char *name, u_char flags)
 {
        struct unvname *unvn;
 
-       rw_enter_write(&uv->uv_lock);
        unvn = unvname_new(name, strlen(name) + 1, flags);
        RBT_INSERT(unvname_rbt, &uv->uv_names, unvn);
-       rw_exit_write(&uv->uv_lock);
 #ifdef DEBUG_UNVEIL
        printf("added name %s underneath vnode %p\n", name, uv->uv_vp);
 #endif
 }
 
+void
+unveil_add_name(struct unveil *uv, char *name, u_char flags)
+{
+       rw_enter_write(&uv->uv_lock);
+       unveil_add_name_unlocked(uv, name, flags);
+       rw_exit_write(&uv->uv_lock);
+}
+
 struct unvname *
 unveil_namelookup(struct unveil *uv, char *name)
 {
@@ -228,8 +234,8 @@ unveil_copy(struct process *parent, stru
                RBT_INIT(unvname_rbt, &to->uv_names);
                rw_enter_read(&from->uv_lock);
                RBT_FOREACH_SAFE(unvn, unvname_rbt, &from->uv_names, next) {
-                       unveil_add_name(&child->ps_uvpaths[i], unvn->un_name,
-                           unvn->un_flags);
+                       unveil_add_name_unlocked(&child->ps_uvpaths[i],
+                           unvn->un_name, unvn->un_flags);
                        child->ps_uvncount++;
                }
                rw_exit_read(&from->uv_lock);

Reply via email to