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)
Sat, Nov 9, 2:32 AM
Unknown Object (File)
Sat, Nov 9, 2:31 AM
Unknown Object (File)
Wed, Nov 6, 10:18 AM
Unknown Object (File)
Tue, Nov 5, 3:19 PM
Unknown Object (File)
Tue, Oct 15, 8:02 PM
Unknown Object (File)
Tue, Oct 15, 8:43 AM
Unknown Object (File)
Sun, Oct 13, 5:21 PM
Unknown Object (File)
Oct 12 2024, 9:47 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.