Skip to contentSkip to conversation

selftests: bpf: don't try to read files without read permission

PATCH Applied Jiri Pirko 3 participants 6 messages Oct 15, 2019 – Nov 1, 2019

Subsystems (5)
lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

PATCH 1/1 selftests: bpf: don't try to read files without read permission

From: Jiri Pirko <[email protected]>

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

---
 tools/testing/selftests/bpf/test_offload.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/test_offload.py +1 -1
index 15a666329a34..c44c650bde3a 100755
@@ -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):
Signature · 1 line
2.21.0
#3 lore raw
In reply to Jiri Pirko
Quoted 16 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

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

---
 tools/testing/selftests/bpf/test_offload.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/test_offload.py +0 -0
index 15a666329a34..c44c650bde3a 100755

tools/testing/selftests/bpf/test_offload.py class DebugfsDir: · line 315

Quoted 5 lines
tools/testing/selftests/bpf/test_offload.py +1 -1
@@ -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.

Quoted 3 lines
tools/testing/selftests/bpf/test_offload.py +0 -0
                 _, out = cmd('cat %s/%s' % (path, f))
                 dfs[f] = out.strip()
             elif os.path.isdir(p):
#4 lore raw
Quoted 12 lines · Jakub Kicinski
Quoted 11 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

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

---
 tools/testing/selftests/bpf/test_offload.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

tools/testing/selftests/bpf/test_offload.py class DebugfsDir: · line 315

Quoted 10 lines
tools/testing/selftests/bpf/test_offload.py +1 -1
index 15a666329a34..c44c650bde3a 100755
@@ -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

Quoted 5 lines

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

Quoted 3 lines
tools/testing/selftests/bpf/test_offload.py +0 -0
                 _, out = cmd('cat %s/%s' % (path, f))
                 dfs[f] = out.strip()
             elif os.path.isdir(p):  
author
#5 lore raw
Quoted 27 lines · Fri, Nov 01, 2019 at 12:40:57AM CET, [email protected] wrote:
Quoted 12 lines · Jakub Kicinski
Quoted 11 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

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

---
 tools/testing/selftests/bpf/test_offload.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

tools/testing/selftests/bpf/test_offload.py class DebugfsDir: · line 315

Quoted 10 lines
tools/testing/selftests/bpf/test_offload.py +1 -1
index 15a666329a34..c44c650bde3a 100755
@@ -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).

Quoted 2 lines

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.

Quoted 9 lines

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

Quoted 5 lines

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

Quoted 3 lines
tools/testing/selftests/bpf/test_offload.py +0 -0
                 _, out = cmd('cat %s/%s' % (path, f))
                 dfs[f] = out.strip()
             elif os.path.isdir(p):