Re: [PATCH v9 bpf-next 13/14] selftests/bpf: Add test for d_path helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Aug 04, 2020 at 11:40:05PM -0700, Andrii Nakryiko wrote:

SNIP

> > +SEC("fentry/vfs_getattr")
> > +int BPF_PROG(prog_stat, struct path *path, struct kstat *stat,
> > +            __u32 request_mask, unsigned int query_flags)
> > +{
> > +       pid_t pid = bpf_get_current_pid_tgid() >> 32;
> > +       int ret;
> > +
> > +       if (pid != my_pid)
> > +               return 0;
> > +
> > +       if (cnt_stat >= MAX_FILES)
> > +               return 0;
> > +       ret = bpf_d_path(path, paths_stat[cnt_stat], MAX_PATH_LEN);
> > +
> > +       /* We need to recheck cnt_stat for verifier. */
> > +       if (cnt_stat >= MAX_FILES)
> > +               return 0;
> > +       rets_stat[cnt_stat] = ret;
> > +
> > +       cnt_stat++;
> > +       return 0;
> > +}
> > +
> > +SEC("fentry/filp_close")
> > +int BPF_PROG(prog_close, struct file *file, void *id)
> > +{
> > +       pid_t pid = bpf_get_current_pid_tgid() >> 32;
> > +       int ret;
> > +
> > +       if (pid != my_pid)
> > +               return 0;
> > +
> > +       if (cnt_close >= MAX_FILES)
> > +               return 0;
> > +       ret = bpf_d_path(&file->f_path,
> > +                        paths_close[cnt_close], MAX_PATH_LEN);
> > +
> > +       /* We need to recheck cnt_stat for verifier. */
> 
> you need to do it because you are re-reading a global variable; if you
> stored cnt_close in a local variable, then did >= MAX_FILES check
> once, you probably could have avoided this duplication. Same for
> another instance above.

I see, nice.. I'll update both comments

thanks,
jirka




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux