Skip to content

Commit 02d2e4b

Browse files
committed
gopathrs: return raw errors from openat2 retry loop
This is to match the new behavour from libpathrs, as it provides more reasonable information to downstream users (they can check for unix.EAGAIN and have their own custom retry logic). Ref: cyphar/libpathrs#265 Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 5dae0ae commit 02d2e4b

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

pathrs-lite/internal/fd/openat2_linux.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import (
1717
"runtime"
1818

1919
"golang.org/x/sys/unix"
20-
21-
"github.com/cyphar/filepath-securejoin/pathrs-lite/internal"
2220
)
2321

2422
func scopedLookupShouldRetry(how *unix.OpenHow, err error) bool {
@@ -43,10 +41,10 @@ func Openat2(dir Fd, path string, how *unix.OpenHow) (*os.File, error) {
4341
// Make sure we always set O_CLOEXEC.
4442
how.Flags |= unix.O_CLOEXEC
4543
var tries int
46-
for tries < scopedLookupMaxRetries {
44+
for {
4745
fd, err := unix.Openat2(dirFd, path, how)
4846
if err != nil {
49-
if scopedLookupShouldRetry(how, err) {
47+
if scopedLookupShouldRetry(how, err) && tries < scopedLookupMaxRetries {
5048
// We retry a couple of times to avoid the spurious errors, and
5149
// if we are being attacked then returning -EAGAIN is the best
5250
// we can do.
@@ -58,5 +56,4 @@ func Openat2(dir Fd, path string, how *unix.OpenHow) (*os.File, error) {
5856
runtime.KeepAlive(dir)
5957
return os.NewFile(uintptr(fd), fullPath), nil
6058
}
61-
return nil, &os.PathError{Op: "openat2", Path: fullPath, Err: internal.ErrPossibleAttack}
6259
}

pathrs-lite/internal/gopathrs/lookup_linux_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/stretchr/testify/require"
2525
"golang.org/x/sys/unix"
2626

27-
"github.com/cyphar/filepath-securejoin/pathrs-lite/internal"
2827
"github.com/cyphar/filepath-securejoin/pathrs-lite/internal/fd"
2928
"github.com/cyphar/filepath-securejoin/pathrs-lite/internal/gocompat"
3029
"github.com/cyphar/filepath-securejoin/pathrs-lite/internal/procfs"
@@ -580,7 +579,7 @@ func TestPartialLookup_RacingRename(t *testing.T) {
580579
)},
581580
} {
582581
test := test // copy iterator
583-
test.skipErrs = append(test.skipErrs, internal.ErrPossibleAttack, internal.ErrPossibleBreakout)
582+
test.skipErrs = append(test.skipErrs, unix.EAGAIN, unix.EXDEV)
584583
t.Run(name, func(t *testing.T) {
585584
root := testutils.CreateTree(t, tree...)
586585

0 commit comments

Comments
 (0)