diff mbox series

[net-next] selftests: bpf: don't try to read files without read permission

Message ID 20191015100057.19199-1-jiri@resnulli.us
State Accepted
Delegated to: BPF Maintainers
Headers show
Series [net-next] selftests: bpf: don't try to read files without read permission | expand

Commit Message

Jiri Pirko Oct. 15, 2019, 10 a.m. UTC
From: Jiri Pirko <jiri@mellanox.com>

Recently couple of files that are write only were added to netdevsim
debugfs. Don't read these files and avoid error.

Reported-by: kernel test robot <rong.a.chen@intel.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
 tools/testing/selftests/bpf/test_offload.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jakub Kicinski Oct. 15, 2019, 3:35 p.m. UTC | #1
On Tue, 15 Oct 2019 12:00:56 +0200, Jiri Pirko wrote:
> From: Jiri Pirko <jiri@mellanox.com>
> 
> Recently couple of files that are write only were added to netdevsim
> debugfs. Don't read these files and avoid error.
> 
> Reported-by: kernel test robot <rong.a.chen@intel.com>
> Signed-off-by: Jiri Pirko <jiri@mellanox.com>

Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>

Thanks!
Alexei Starovoitov Oct. 15, 2019, 11:28 p.m. UTC | #2
On Tue, Oct 15, 2019 at 8:35 AM Jakub Kicinski
<jakub.kicinski@netronome.com> wrote:
>
> On Tue, 15 Oct 2019 12:00:56 +0200, Jiri Pirko wrote:
> > From: Jiri Pirko <jiri@mellanox.com>
> >
> > Recently couple of files that are write only were added to netdevsim
> > debugfs. Don't read these files and avoid error.
> >
> > Reported-by: kernel test robot <rong.a.chen@intel.com>
> > Signed-off-by: Jiri Pirko <jiri@mellanox.com>
>
> Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>

Applied. Thanks
Jakub Kicinski Oct. 31, 2019, 11:35 p.m. UTC | #3
On Tue, 15 Oct 2019 12:00:56 +0200, Jiri Pirko wrote:
> From: Jiri Pirko <jiri@mellanox.com>
> 
> Recently couple of files that are write only were added to netdevsim
> debugfs. Don't read these files and avoid error.
> 
> Reported-by: kernel test robot <rong.a.chen@intel.com>
> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
> ---
>  tools/testing/selftests/bpf/test_offload.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py
> index 15a666329a34..c44c650bde3a 100755
> --- a/tools/testing/selftests/bpf/test_offload.py
> +++ b/tools/testing/selftests/bpf/test_offload.py
> @@ -312,7 +312,7 @@ class DebugfsDir:
>              if f == "ports":
>                  continue
>              p = os.path.join(path, f)
> -            if os.path.isfile(p):
> +            if os.path.isfile(p) and os.access(p, os.R_OK):

Have you tested this? Looks like python always returns True here when
run as root, and this script requires root (and checks for it).

Also the fix is needed in net, not sure why you sent it to net-next.

>                  _, out = cmd('cat %s/%s' % (path, f))
>                  dfs[f] = out.strip()
>              elif os.path.isdir(p):
Jakub Kicinski Oct. 31, 2019, 11:40 p.m. UTC | #4
On Thu, 31 Oct 2019 16:35:35 -0700, Jakub Kicinski wrote:
> On Tue, 15 Oct 2019 12:00:56 +0200, Jiri Pirko wrote:
> > From: Jiri Pirko <jiri@mellanox.com>
> > 
> > Recently couple of files that are write only were added to netdevsim
> > debugfs. Don't read these files and avoid error.
> > 
> > Reported-by: kernel test robot <rong.a.chen@intel.com>
> > Signed-off-by: Jiri Pirko <jiri@mellanox.com>
> > ---
> >  tools/testing/selftests/bpf/test_offload.py | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py
> > index 15a666329a34..c44c650bde3a 100755
> > --- a/tools/testing/selftests/bpf/test_offload.py
> > +++ b/tools/testing/selftests/bpf/test_offload.py
> > @@ -312,7 +312,7 @@ class DebugfsDir:
> >              if f == "ports":
> >                  continue
> >              p = os.path.join(path, f)
> > -            if os.path.isfile(p):
> > +            if os.path.isfile(p) and os.access(p, os.R_OK):  
> 
> Have you tested this? Looks like python always returns True here when
> run as root, and this script requires root (and checks for it).

Yeah, you definitely haven't tested this. Even if it worked we'd fall
into the else condition and say:

Exception: /sys/kernel/debug/netdevsim/netdevsim0//ports/0/dev/take_snapshot is neither file nor directory

> Also the fix is needed in net, not sure why you sent it to net-next.
> 
> >                  _, out = cmd('cat %s/%s' % (path, f))
> >                  dfs[f] = out.strip()
> >              elif os.path.isdir(p):
Jiri Pirko Nov. 1, 2019, 6:36 a.m. UTC | #5
Fri, Nov 01, 2019 at 12:40:57AM CET, jakub.kicinski@netronome.com wrote:
>On Thu, 31 Oct 2019 16:35:35 -0700, Jakub Kicinski wrote:
>> On Tue, 15 Oct 2019 12:00:56 +0200, Jiri Pirko wrote:
>> > From: Jiri Pirko <jiri@mellanox.com>
>> > 
>> > Recently couple of files that are write only were added to netdevsim
>> > debugfs. Don't read these files and avoid error.
>> > 
>> > Reported-by: kernel test robot <rong.a.chen@intel.com>
>> > Signed-off-by: Jiri Pirko <jiri@mellanox.com>
>> > ---
>> >  tools/testing/selftests/bpf/test_offload.py | 2 +-
>> >  1 file changed, 1 insertion(+), 1 deletion(-)
>> > 
>> > diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py
>> > index 15a666329a34..c44c650bde3a 100755
>> > --- a/tools/testing/selftests/bpf/test_offload.py
>> > +++ b/tools/testing/selftests/bpf/test_offload.py
>> > @@ -312,7 +312,7 @@ class DebugfsDir:
>> >              if f == "ports":
>> >                  continue
>> >              p = os.path.join(path, f)
>> > -            if os.path.isfile(p):
>> > +            if os.path.isfile(p) and os.access(p, os.R_OK):  
>> 
>> Have you tested this? Looks like python always returns True here when
>> run as root, and this script requires root (and checks for it).
>
>Yeah, you definitely haven't tested this. Even if it worked we'd fall
>into the else condition and say:

Sure I tested. It worked. Odd.

>
>Exception: /sys/kernel/debug/netdevsim/netdevsim0//ports/0/dev/take_snapshot is neither file nor directory
>
>> Also the fix is needed in net, not sure why you sent it to net-next.
>> 
>> >                  _, out = cmd('cat %s/%s' % (path, f))
>> >                  dfs[f] = out.strip()
>> >              elif os.path.isdir(p):  
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py
index 15a666329a34..c44c650bde3a 100755
--- a/tools/testing/selftests/bpf/test_offload.py
+++ b/tools/testing/selftests/bpf/test_offload.py
@@ -312,7 +312,7 @@  class DebugfsDir:
             if f == "ports":
                 continue
             p = os.path.join(path, f)
-            if os.path.isfile(p):
+            if os.path.isfile(p) and os.access(p, os.R_OK):
                 _, out = cmd('cat %s/%s' % (path, f))
                 dfs[f] = out.strip()
             elif os.path.isdir(p):