On Tue, Oct 8, 2019 at 2:29 PM Daniel Borkmann <daniel@xxxxxxxxxxxxx> wrote: > > On Tue, Oct 08, 2019 at 12:45:47PM -0700, Andrii Nakryiko wrote: > > Maps that are read-only both from BPF program side and user space side > > have their contents constant, so verifier can track referenced values > > precisely and use that knowledge for dead code elimination, branch > > pruning, etc. This patch teaches BPF verifier how to do this. > > > > Signed-off-by: Andrii Nakryiko <andriin@xxxxxx> > > --- > > kernel/bpf/verifier.c | 58 +++++++++++++++++++++++++++++++++++++++++-- > > 1 file changed, 56 insertions(+), 2 deletions(-) > > > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > > index ffc3e53f5300..1e4e4bd64ca5 100644 > > --- a/kernel/bpf/verifier.c > > +++ b/kernel/bpf/verifier.c > > @@ -2739,6 +2739,42 @@ static void coerce_reg_to_size(struct bpf_reg_state *reg, int size) > > reg->smax_value = reg->umax_value; > > } > > > > +static bool bpf_map_is_rdonly(const struct bpf_map *map) > > +{ > > + return (map->map_flags & BPF_F_RDONLY_PROG) && > > + ((map->map_flags & BPF_F_RDONLY) || map->frozen); > > This is definitely buggy. Testing for 'map->map_flags & BPF_F_RDONLY' > to assume it's RO from user space side is not correct as it's just > related to the current fd, but not the map itself. So the second part > definitely /must/ only be: && map->frozen Yep, you are right, map->frozen and BPF_F_RDONLY_PROG only. > > Thanks, > Daniel