git write operations fail in repository on SMB share
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 33.7k
- Forks
- 1.8k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 116
Description
### Windows Version
Microsoft Windows [Version 10.0.26200.8457]
### WSL Version
2.5.9.0
### Are you using WSL 1 or WSL 2?
- [ ] WSL 2
- [x] WSL 1
### Kernel Version
4.4.0-26100-Microsoft
### Distro Version
Ubuntu 22.04
### Other Software
_No response_
### Repro Steps
WSL uses drvfs to mount network shares over the SMB protocol. When a git repository is stored on a network share you can perform read operations such as 'git status' and 'git log' but write operations such as 'git add' and 'git tag' will fail with an error like this:
```
# git tag -a -m "" my_tag
error: insufficient permission for adding an object to repository database .git/objects
error: unable to write tag file
```
If you run the command under strace you will see an error like this:
```
# strace git tag -a -m "" my_tag
...
openat(AT_FDCWD, ".git/objects/f1/tmp_obj_yHk6zM", O_RDWR|O_CREAT|O_EXCL, 0444) = -1 EACCES (Permission denied)
...
```
The same error can be reproduced outside a git repository (but still on a network share) with the following test program:
```
#include
#include
#include
int main()
{
int fd = open("new.txt", O_RDWR | O_CREAT | O_EXCL, 0444);
if (fd == -1) { perror("open failed"); }
else { close(fd); unlink("new.txt"); printf("success\n"); }
}
```
This operation is valid and permissible according to the POSIX documentation for open(2):
```
Note that mode applies only to future accesses of the newly
created file; the open() call that creates a read-only file
may well return a read/write file descriptor.
```
Therefore this appears to be a defect in the drvfs filesystem plugin. You can observe when running the test program that the file does get created with the correct permissions despite the open() failure. It seems like this atomic operation has been split into two operations (create + open) inside the drvfs plugin.
### Expected Behavior
POSIX compliance
### Actual Behavior
violation of POSIX
### Diagnostic Logs
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the standalone open() test program on an SMB share mounted through drvfs, then compare its strace with the failing git tag or git add operation. Done means creating a read-only file with O_RDWR|O_CREAT|O_EXCL succeeds without EACCES and git write operations work on the share.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- networking, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100