Page MenuHomeFreeBSD

bpf: Make dead_bpf_if const
ClosedPublic

Authored by zlei on Oct 13 2023, 2:00 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, May 21, 4:20 PM
Unknown Object (File)
Apr 16 2024, 6:53 AM
Unknown Object (File)
Apr 11 2024, 10:18 AM
Unknown Object (File)
Mar 5 2024, 5:56 AM
Unknown Object (File)
Feb 18 2024, 12:02 AM
Unknown Object (File)
Dec 20 2023, 5:49 AM
Unknown Object (File)
Dec 13 2023, 3:06 AM
Unknown Object (File)
Dec 2 2023, 9:09 AM

Details

Summary

The dead_bpf_if is not subjected to be written. Make it const so that the kernel can panic on destructive writing to it instead of silently memory corruption.

No functional change intended.

MFC after: 1 week

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

zlei requested review of this revision.Oct 13 2023, 2:00 PM
zlei edited the summary of this revision. (Show Details)
sys/net/bpf.c
2862

Rather than casting away the const (which generally should be done with __DECONST), why not change the type of bif_bpf?

sys/net/bpf.c
2862

Emm, clang complains with

error: passing 'struct bpf_if ' to parameter of type 'const struct bpf_if ' discards qualifiers in nested pointer types [-Werror,-Wincompatible-pointer-types-discards-qualifiers]

if bif_bpf is const struct bpf_if ** .

sys/net/bpf.c
2862

Found a good explaining https://c-faq.com/ansi/constmismatch.html .

OK, a cast is much simpler. It make troubles to change the type of bif_bpf to const struct bpf_if ** .

sys/net/bpf.c
2862

It make troubles to change the type of bif_bpf to const struct bpf_if ** .

It should be done anyway. Only bpf.c should be potentially modifying bpf_if fields anyway, so external references ought to be const: https://people.freebsd.org/~markj/patches/bpf_const.diff

In any case, please use __DECONST at least.

This revision is now accepted and ready to land.Oct 13 2023, 3:35 PM
sys/net/bpf.c
2862

It should be done anyway. Only bpf.c should be potentially modifying bpf_if fields anyway, so external references ought to be const

Reasonable.

This change is quite simple. I'm going to commit this firstly.

This revision was automatically updated to reflect the committed changes.