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

Disk quota is not enforced #32

Closed
rqu opened this issue Jan 3, 2021 · 4 comments
Closed

Disk quota is not enforced #32

rqu opened this issue Jan 3, 2021 · 4 comments

Comments

@rqu
Copy link
Contributor

rqu commented Jan 3, 2021

Looking at isolate source it seems that --quota parameters are only used by command --init, while other commands (including --run) silently ignore it. ReCodEx passes --quota only to isolate --run, not to isolate --init.

Steps to reproduce:

I have tested this using the following program (submit to any C or C++ exercise). It writes to file big as much as it can, then terminates. Please do not run this in production*.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv) {
	char buff[1000];
	for(int i = 0; i < 1000; i++)
		buff[i] = rand();
	FILE* fp = fopen("big", "w");
	while(fwrite(buff, 1, 1000, fp) == 1000);
	fclose(fp);
	return 0;
}

Expected behavior: When the quota is eventually reached, write syscall fails with EDQUOT, fwrite returns <1000, and the program terminates.

Observed behavior: The quota is exceeded and the file fills the disk.

You may need to add a sleep at the end of the program and check df -h /var/recodex-worker-wd concurrently in a shell.

* - In my setup, the isolate box and the ReCodEx Worker working directory are on the same filesystem, so the file cannot be copied out of the isolate box (ENOSPC). While the box does get properly cleaned up, the solution is left in the "work-in-progress" status forever (“The evaluation is not available yet. Click the refresh button for an update.”). YMMV.

@krulis-martin
Copy link
Member

@rqu Could you specify, where did you find that quota needs to be set during --init ? Actually, when I try it, I got error message Cannot set disk quota: No such process.

@rqu
Copy link
Contributor Author

rqu commented Jan 8, 2021

The parameter to --quota is saved to global variables block_quota and inode_quota at isolate.c:1072..1080.
The only user of these variables is function set_quota at rules.c:505..543.
The only call site of set_quota is at isolate.c:772 in function init.
The only call site of init is at isolate.c:1166 which is reached only if --init was passed.

The error message comes from rules.c:539, "No such process" is ESRCH. According to man 2 quotactl:

ESRCH No disk quota is found for the indicated user. Quotas have not been turned on for this filesystem.

The fact you are getting the error means isolate at least attempted to set the quota, as opposed to the case where quotactl was not called at all.

The "only" way to enable quotas seems to be the quotactl command Q_QUOTAON, but there is an utility package for this (quota on CentOS and Ubuntu, quota-tools on Arch). It contains a command named quotaon.

Searching the Web I also found you can add usrquota mount option to the FS in /etc/fstab. It is not interpreted by kernel or the FS drivers, but by the mentioned utility package. I do not know what command and when, however.

@krulis-martin
Copy link
Member

OK, thanks, I think I got it.

@krulis-martin
Copy link
Member

Fixed in release 1.7.2.

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

2 participants