git: 281f61d211b3 - stable/12 - bpf: Make dead_bpf_if const

From: Zhenlei Huang <zlei_at_FreeBSD.org>
Date: Mon, 13 Nov 2023 10:24:41 UTC
The branch stable/12 has been updated by zlei:

URL: https://cgit.FreeBSD.org/src/commit/?id=281f61d211b38d95986d2cec97407e770313a087

commit 281f61d211b38d95986d2cec97407e770313a087
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2023-10-21 04:52:27 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2023-11-13 10:22:41 +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
    
    (cherry picked from commit 7a974a649848e1222a49d0d49726d06bd5c1dbd9)
    (cherry picked from commit 5d031613affa14b3de64f8cf9fed15604fb826d3)
    (cherry picked from commit 1e147980497b38d65cd72162c000c88507a7fa76)
---
 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 5ca92a97f74f..47e41f3886cb 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -99,7 +99,7 @@ __FBSDID("$FreeBSD$");
 
 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 = LIST_HEAD_INITIALIZER()
 };
 
@@ -2693,7 +2693,7 @@ bpfdetach(struct ifnet *ifp)
 		 */
 		BPFIF_WLOCK(bp);
 		bp->bif_flags |= BPFIF_FLAG_DYING;
-		*bp->bif_bpf = (struct bpf_if *)&dead_bpf_if;
+		*bp->bif_bpf = __DECONST(struct bpf_if *, &dead_bpf_if);
 		BPFIF_WUNLOCK(bp);
 
 		CTR4(KTR_NET, "%s: sheduling free for encap %d (%p) for if %p",
@@ -3046,7 +3046,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