From 3e6640e96dfee36cc302428d71f5de210f67be5f Mon Sep 17 00:00:00 2001 From: Nickolai Zeldovich Date: Fri, 9 Aug 2002 22:15:12 +0000 Subject: [PATCH] Set the maxfilesize rlimit to infinity while writing to cache files to avoid potential truncation if the user's rlimit is too low. This bug likely also exists in AIX, DARWIN, DUX, FBSD, HPUX and NBSD, but surprisingly IRIX got this right. --- src/afs/LINUX/osi_misc.c | 14 +++++++++++++- src/afs/SOLARIS/osi_file.c | 10 +++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/afs/LINUX/osi_misc.c b/src/afs/LINUX/osi_misc.c index 484376d1b..b2ae7d921 100644 --- a/src/afs/LINUX/osi_misc.c +++ b/src/afs/LINUX/osi_misc.c @@ -114,6 +114,7 @@ int osi_rdwr(int rw, struct osi_file *file, caddr_t addrp, size_t asize, KERNEL_SPACE_DECL; struct file *filp = &file->file; off_t offset = file->offset; + unsigned long savelim; /* Seek to the desired position. Return -1 on error. */ if (filp->f_op->llseek) { @@ -123,6 +124,9 @@ int osi_rdwr(int rw, struct osi_file *file, caddr_t addrp, size_t asize, else filp->f_pos = offset; + savelim = current->rlim[RLIMIT_FSIZE].rlim_cur; + current->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY; + /* Read/Write the data. */ TO_USER_SPACE(); if (rw == UIO_READ) @@ -133,6 +137,8 @@ int osi_rdwr(int rw, struct osi_file *file, caddr_t addrp, size_t asize, code = asize; TO_KERNEL_SPACE(); + current->rlim[RLIMIT_FSIZE].rlim_cur = savelim; + if (code >=0) { *resid = asize - code; return 0; @@ -152,6 +158,10 @@ int osi_file_uio_rdwr(struct osi_file *osifile, uio_t *uiop, int rw) int code = 0; struct iovec *iov; int count; + unsigned long savelim; + + savelim = current->rlim[RLIMIT_FSIZE].rlim_cur; + current->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY; if (uiop->uio_seg == AFS_UIOSYS) TO_USER_SPACE(); @@ -165,7 +175,7 @@ int osi_file_uio_rdwr(struct osi_file *osifile, uio_t *uiop, int rw) uiop->uio_iovcnt--; continue; } - + if (rw == UIO_READ) code = FOP_READ(filp, iov->iov_base, count); else @@ -186,6 +196,8 @@ int osi_file_uio_rdwr(struct osi_file *osifile, uio_t *uiop, int rw) if (uiop->uio_seg == AFS_UIOSYS) TO_KERNEL_SPACE(); + current->rlim[RLIMIT_FSIZE].rlim_cur = savelim; + return code; } diff --git a/src/afs/SOLARIS/osi_file.c b/src/afs/SOLARIS/osi_file.c index c7709cd96..acbb09137 100644 --- a/src/afs/SOLARIS/osi_file.c +++ b/src/afs/SOLARIS/osi_file.c @@ -339,13 +339,9 @@ afs_osi_Write(afile, offset, aptr, asize) osi_Panic("afs_osi_Write called with null param"); if (offset != -1) afile->offset = offset; AFS_GUNLOCK(); -#ifdef AFS_SUN59_ENV - code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset, - AFS_UIOSYS, 0, curproc->p_fsz_ctl.rlim_cur, &afs_osi_cred, &resid); -#else - code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, afile->offset, - AFS_UIOSYS, 0, (u.u_rlimit[RLIMIT_FSIZE].rlim_cur), &afs_osi_cred, &resid); -#endif + code = gop_rdwr(UIO_WRITE, afile->vnode, (caddr_t) aptr, asize, + afile->offset, AFS_UIOSYS, 0, RLIM64_INFINITY, + &afs_osi_cred, &resid); AFS_GLOCK(); if (code == 0) { code = asize - resid; -- 2.39.5