Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Mar 2016 10:19:33 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r296561 - stable/10/sys/net
Message-ID:  <201603091019.u29AJX0D064059@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Wed Mar  9 10:19:32 2016
New Revision: 296561
URL: https://svnweb.freebsd.org/changeset/base/296561

Log:
  MFC r296009:
  In bpf_getdltlist(), do not call copyout(9) while holding bpf lock.
  Copy the data into temprorary malloced buffer and drop the lock for
  copyout.

Modified:
  stable/10/sys/net/bpf.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/net/bpf.c
==============================================================================
--- stable/10/sys/net/bpf.c	Wed Mar  9 10:14:53 2016	(r296560)
+++ stable/10/sys/net/bpf.c	Wed Mar  9 10:19:32 2016	(r296561)
@@ -2616,26 +2616,44 @@ bpf_ifdetach(void *arg __unused, struct 
 static int
 bpf_getdltlist(struct bpf_d *d, struct bpf_dltlist *bfl)
 {
-	int n, error;
 	struct ifnet *ifp;
 	struct bpf_if *bp;
+	u_int *lst;
+	int error, n, n1;
 
 	BPF_LOCK_ASSERT();
 
 	ifp = d->bd_bif->bif_ifp;
+again:
+	n1 = 0;
+	LIST_FOREACH(bp, &bpf_iflist, bif_next) {
+		if (bp->bif_ifp == ifp)
+			n1++;
+	}
+	if (bfl->bfl_list == NULL) {
+		bfl->bfl_len = n1;
+		return (0);
+	}
+	if (n1 > bfl->bfl_len)
+		return (ENOMEM);
+	BPF_UNLOCK();
+	lst = malloc(n1 * sizeof(u_int), M_TEMP, M_WAITOK);
 	n = 0;
-	error = 0;
+	BPF_LOCK();
 	LIST_FOREACH(bp, &bpf_iflist, bif_next) {
 		if (bp->bif_ifp != ifp)
 			continue;
-		if (bfl->bfl_list != NULL) {
-			if (n >= bfl->bfl_len)
-				return (ENOMEM);
-			error = copyout(&bp->bif_dlt,
-			    bfl->bfl_list + n, sizeof(u_int));
+		if (n > n1) {
+			free(lst, M_TEMP);
+			goto again;
 		}
+		lst[n] = bp->bif_dlt;
 		n++;
 	}
+	BPF_UNLOCK();
+	error = copyout(lst, bfl->bfl_list, sizeof(u_int) * n);
+	free(lst, M_TEMP);
+	BPF_LOCK();
 	bfl->bfl_len = n;
 	return (error);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201603091019.u29AJX0D064059>