Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I/O Error when opening files with custom process umask #7

Open
Toilal opened this issue Feb 7, 2019 · 2 comments
Open

I/O Error when opening files with custom process umask #7

Toilal opened this issue Feb 7, 2019 · 2 comments

Comments

@Toilal
Copy link
Contributor

Toilal commented Feb 7, 2019

When opening a file with O_EXCL flag, nfs4j always receives 0000 filemode, making subsequent writes on this file failing. There's an easy reproduction case with inplace sed.

test.txt

test

test.sh

#!/bin/bash
sed -i 's/test/hello' test.txt

Using trace gives more information on what's hapening from the NFS client.

trace.sh

#!/bin/bash
strace -f -e trace=file test.sh

It shows this line, that should it should be created with 0600 flag.

open("./sedAaF5hB", O_RDWR|O_CREAT|O_EXCL, 0600) = 4

In nfs4j, it seems to only occurs with nfs 4.1 mount, as it goes throw OperationOPEN.java#L136 and then get a create filemode = 0000 at OperationOPEN.java#L150.

@Toilal
Copy link
Contributor Author

Toilal commented Feb 7, 2019

After analysing source code of sed, this is caused by some tricks with umask system call.

It can be reproduced with the following python script

#!/usr/bin/env python3
import os

filename = './sedBk0bug'
try:
    os.remove(filename)
except:
    pass

oldmask = os.umask(0o700)
fd = os.open(filename, os.O_RDWR | os.O_CREAT, 0o600)
os.umask(oldmask)

os.write(fd, b'hello')
os.close(fd)

Without umask invocation, it just work as expected over NFS, but with umask invocation it fails.

@Toilal Toilal changed the title I/O Error when opening files with O_EXCL flag (nfs 4.1) I/O Error when opening files with custom process umask (nfs 4.1) Feb 7, 2019
@Toilal
Copy link
Contributor Author

Toilal commented Feb 7, 2019

It seems to be related to some flaws in NFS spec, see this draft that add umask support for NFS4.2 : https://tools.ietf.org/id/draft-ietf-nfsv4-umask-05.html#RFC7862

@Toilal Toilal changed the title I/O Error when opening files with custom process umask (nfs 4.1) I/O Error when opening files with custom process umask Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant