PROBLEM: can't write to a file if RLIMIT_FSIZE is too large

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



(If this is not a correct way of reporting bug, let me know.)

[Description of the problem (cosmetic)]
If RLIMIT_FSIZE is set in the range
    2**63 <= lim < RLIM_INFINITY = 2**64 - 1
then the process can't write to a file.

[Possible cause of the problem]
I guess the problem is in the function generic_write_check_limits().
In fs/read_write.c, at line 1607:
    loff_t limit = rlimit(RLIMIT_FSIZE);
loff_t is signed 64 bit, and the variable 'limit' gets negative value.
But just replacing loff_t by 'unsigned long' (rlmin_t) may not work?
(due to signed --> unsigned conversion, for example).
Another possibility would be to lower RLIM_INFINITY to 2**63 - 1.

[How to reproduce]
Compile and run the following C-code:

#include <sys/resource.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

int main() {
	struct rlimit rlim;
	int fd;

	/* set RLIMIT_FSIZE to 2**63 */
	rlim.rlim_cur = rlim.rlim_max = (rlim_t)1 << 63;
	if(setrlimit(RLIMIT_FSIZE, &rlim) < 0) {
		perror("setrlimit"); return 1;
	}
	if(getrlimit(RLIMIT_FSIZE, &rlim) < 0) {
		perror("getrlimit"); return 1;
	}
	printf("rlim_cur=%#lx\n", rlim.rlim_cur);

	if((fd = creat("tmp.txt", 0600)) < 0) {
		perror("creat"); return 1;
	}
	if(write(fd, "A", 1) < 0) {	/* coredump here */
		perror("write"); return 1;
	}
	close(fd);
	return 0;
}

$ ./a.out
rlim_cur=0x8000000000000000
[1]    185552 file size limit exceeded (core dumped)  ./a.out

------------------------------------------------
Jun-ichi Takimoto <takimoto-j@xxxxxxxxxxxxxxxxx>



[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux