Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 21 Oct 2023 04:54:45 GMT
From:      Zhenlei Huang <zlei@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 7a974a649848 - main - bpf: Make dead_bpf_if const
Message-ID:  <202310210454.39L4sjoj023564@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by zlei:

URL: https://cgit.FreeBSD.org/src/commit/?id=7a974a649848e1222a49d0d49726d06bd5c1dbd9

commit 7a974a649848e1222a49d0d49726d06bd5c1dbd9
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2023-10-21 04:52:27 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2023-10-21 04:52:27 +0000

    bpf: Make dead_bpf_if const
    
    The dead_bpf_if is not subjected to be written. Make it const so that
    on destructive writing to it the kernel will panic instead of silent
    memory corruption.
    
    No functional change intended.
    
    Reviewed by:    markj
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D42189
---
 sys/net/bpf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index 96420b709911..9e135b90614b 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -100,7 +100,7 @@
 
 MALLOC_DEFINE(M_BPF, "BPF", "BPF data");
 
-static struct bpf_if_ext dead_bpf_if = {
+static const struct bpf_if_ext dead_bpf_if = {
 	.bif_dlist = CK_LIST_HEAD_INITIALIZER()
 };
 
@@ -2859,7 +2859,7 @@ bpfdetach(struct ifnet *ifp)
 			continue;
 
 		CK_LIST_REMOVE(bp, bif_next);
-		*bp->bif_bpf = (struct bpf_if *)&dead_bpf_if;
+		*bp->bif_bpf = __DECONST(struct bpf_if *, &dead_bpf_if);
 
 		CTR4(KTR_NET,
 		    "%s: sheduling free for encap %d (%p) for if %p",
@@ -3162,7 +3162,7 @@ void
 bpfattach2(struct ifnet *ifp, u_int dlt, u_int hdrlen, struct bpf_if **driverp)
 {
 
-	*driverp = (struct bpf_if *)&dead_bpf_if;
+	*driverp = __DECONST(struct bpf_if *, &dead_bpf_if);
 }
 
 void



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