-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Gvisor failed to ftruncate on deleted file #3654
Comments
Hi @amscanne Adin, I notice you introduce these logic in following patch, would you please
|
Anyone can add some background here? As there's no description on the orginal problem of this change, we cannot blindly revert that change. |
Using repro C program from this ticket. Under gvisor release-20200907.0-44-g7e0b019b84b9:
Outside gvisor on native linux:
I've stumbled on this problem months ago but didn't bother to file a ticket. I don't remember the exact circumstances but it did bite me before. |
Re: 75cd70e, that change is a defense-in-depth measure. It prevents a compromised Sentry from exploiting walk races. It is not strictly necessary, given there are a number of other defense-in-depth measures in place (e.g. gofers run in a chroot, which makes the races largely irrelevant), but I don't think it hurts. Is the only thing required here relaxing the constraint in the handler? That seems fine to me, it was probably overreaching. |
We may have problems if we allow the operation on a deleted file, if another file with the same name has been created. An open FID does not necessarily correspond to an open FD in every gofer implementation--some implementations may still walk the path again despite having an open FID. Therefore, we still need this check so that the new file is not truncated. One way to solve this would be to add a new setattr call that requires the operation to be performed on an open file. This would be useful for a few system calls, e.g. ftruncate, fchmod, utimensat. Gofers that don't support this could simply fail the call if the file has been unlinked. |
You're right, though I delete the #include<fcntl.h>
#include<stdio.h>
#include<unistd.h>
int main()
{
int file_desc = open("test.txt",O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW, 0600);
printf("file_desc: %d\n", file_desc);
int ret = unlink("test.txt");
printf("unlink: %d\n", ret);
int file_desc2 = open("test.txt",O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW, 0600);
printf("file_desc2: %d\n", file_desc2);
int wn = write(file_desc2, "fff", 3);
printf("wn: %d\n", wn);
int ftruncate_ret = ftruncate(file_desc, 0);
printf("ftruncate_ret: %d\n", ftruncate_ret);
return 0;
} |
Are you still getting EINVAL, or is it something else like ENOENT? |
Hello, We faced problems running sqlite3 in gvisor environment. A substantial amount of sqlite3 db tests are failing on the latest gvisor, as sqlite3 calls unlink at the very beginning of session when working with temporary entities. If you are interested, you can run a docker I prepared, note that the docker pull yaroslavlitvinov/public:sqlite3.test
docker run --runtime runsc -it --entrypoint /bin/bash yaroslavlitvinov/public:sqlite3.test
./testfixture ../test/tempdb2.test According to docs: a file does exist until the the file descriptor is not released.
|
Thanks for the easy repro. The fsgofer included with runsc either reuses the open FD or safely reopens using the magic link in |
It's safe to call SetAttr and Allocate on fsgofer because the file path is not used to open the file, if needed. Fixes #3654 PiperOrigin-RevId: 405994182
Description
When a GR3 program open a file and delete(unlink) it, then ftruncate the deleted file with FD, the ftruncate syscall will fail with 'Invalid argument'.
In function Tsetattr.handle explains the behavior, but I don't really understand it.
Steps to reproduce
Run the following c code:
How we found above syscall sequence:
We simply run
pytest --version
in runsc.Environment
Please include the following details of your environment:
The text was updated successfully, but these errors were encountered: