From 0bb600f9deeab5ad52b3314eecd3e1183d81fa4b Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Mon, 6 Jul 2009 19:26:03 -0700 Subject: [PATCH] Avoid converting more negative errors into invalid pointers * Apply upstream patch to avoid converting more negative errors into invalid kernel memory pointers. --- debian/changelog | 7 ++++ src/afs/LINUX/osi_vnodeops.c | 78 ++++++++++++++++++++++-------------- 2 files changed, 56 insertions(+), 29 deletions(-) diff --git a/debian/changelog b/debian/changelog index 4389f9e61..4ce7c1540 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +openafs (1.4.2-6etch3) UNRELEASED; urgency=medium + + * Apply upstream patch to avoid converting more negative errors into + invalid kernel memory pointers. + + -- Russ Allbery Mon, 06 Jul 2009 19:25:59 -0700 + openafs (1.4.2-6etch2) oldstable-security; urgency=high * Apply upstream security patches from 1.4.9: diff --git a/src/afs/LINUX/osi_vnodeops.c b/src/afs/LINUX/osi_vnodeops.c index 7373814c0..68b72349f 100644 --- a/src/afs/LINUX/osi_vnodeops.c +++ b/src/afs/LINUX/osi_vnodeops.c @@ -56,6 +56,22 @@ RCSID extern struct vcache *afs_globalVp; + +/* This function converts a positive error code from AFS into a negative + * code suitable for passing into the Linux VFS layer. It checks that the + * error code is within the permissable bounds for the ERR_PTR mechanism. + * + * _All_ error codes which come from the AFS layer should be passed through + * this function before being returned to the kernel. + */ + +static inline int afs_convert_code(int code) { + if ((code >= 0) && (code <= MAX_ERRNO)) + return -code; + else + return -EIO; +} + static ssize_t afs_linux_read(struct file *fp, char *buf, size_t count, loff_t * offp) { @@ -75,7 +91,7 @@ afs_linux_read(struct file *fp, char *buf, size_t count, loff_t * offp) code = afs_VerifyVCache(vcp, &treq); if (code) - code = -code; + code = afs_convert_code(code); else { osi_FlushPages(vcp, credp); /* ensure stale pages are gone */ AFS_GUNLOCK(); @@ -126,7 +142,7 @@ afs_linux_write(struct file *fp, const char *buf, size_t count, loff_t * offp) afs_FakeOpen(vcp); ReleaseWriteLock(&vcp->lock); if (code) - code = -code; + code = afs_convert_code(code); else { AFS_GUNLOCK(); #ifdef DO_SYNC_READ @@ -181,19 +197,25 @@ afs_linux_readdir(struct file *fp, void *dirbuf, filldir_t filldir) code = afs_InitReq(&treq, credp); crfree(credp); - if (code) + if (code) { + code = afs_convert_code(code); goto out1; + } afs_InitFakeStat(&fakestat); code = afs_EvalFakeStat(&avc, &fakestat, &treq); - if (code) + if (code) { + code = afs_convert_code(code); goto out; + } /* update the cache entry */ tagain: code = afs_VerifyVCache(avc, &treq); - if (code) + if (code) { + code = afs_convert_code(code); goto out; + } /* get a reference to the entire directory */ tdc = afs_GetDCache(avc, (afs_size_t) 0, &treq, &origOffset, &tlen, 1); @@ -374,7 +396,7 @@ out: return code; out_err: - code = -code; + code = afs_convert_code(code); goto out; } @@ -396,7 +418,7 @@ afs_linux_open(struct inode *ip, struct file *fp) #endif crfree(credp); - return -code; + return afs_convert_code(code); } static int @@ -417,7 +439,7 @@ afs_linux_release(struct inode *ip, struct file *fp) #endif crfree(credp); - return -code; + return afs_convert_code(code); } static int @@ -441,7 +463,7 @@ afs_linux_fsync(struct file *fp, struct dentry *dp) unlock_kernel(); #endif crfree(credp); - return -code; + return afs_convert_code(code); } @@ -503,7 +525,7 @@ afs_linux_lock(struct file *fp, int cmd, struct file_lock *flp) flp->fl_end = flock.l_start + flock.l_len; crfree(credp); - return -code; + return afs_convert_code(code); } @@ -539,7 +561,7 @@ out: AFS_GUNLOCK(); crfree(credp); - return -code; + return afs_convert_code(code); } #if !defined(AFS_LINUX24_ENV) @@ -689,7 +711,7 @@ afs_linux_revalidate(struct dentry *dp) #endif crfree(credp); - return -code; + return afs_convert_code(code); } #if defined(AFS_LINUX26_ENV) @@ -898,7 +920,7 @@ afs_linux_create(struct inode *dip, struct dentry *dp, int mode) unlock_kernel(); #endif crfree(credp); - return -code; + return afs_convert_code(code); } /* afs_linux_lookup */ @@ -969,14 +991,12 @@ afs_linux_lookup(struct inode *dip, struct dentry *dp) #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,10) if (code == ENOENT) return ERR_PTR(0); - else if ((code >= 0) && (code <= MAX_ERRNO)) - return ERR_PTR(-code); - else - return ERR_PTR(-EIO); + else + return ERR_PTR(afs_convert_code(code)); #else if (code == ENOENT) code = 0; - return -code; + return afs_convert_code(code); #endif } @@ -998,7 +1018,7 @@ afs_linux_link(struct dentry *olddp, struct inode *dip, struct dentry *newdp) AFS_GUNLOCK(); crfree(credp); - return -code; + return afs_convert_code(code); } static int @@ -1067,7 +1087,7 @@ out: unlock_kernel(); #endif crfree(credp); - return -code; + return afs_convert_code(code); } @@ -1089,7 +1109,7 @@ afs_linux_symlink(struct inode *dip, struct dentry *dp, const char *target) code = afs_symlink(VTOAFS(dip), name, &vattr, target, credp); AFS_GUNLOCK(); crfree(credp); - return -code; + return afs_convert_code(code); } static int @@ -1126,7 +1146,7 @@ afs_linux_mkdir(struct inode *dip, struct dentry *dp, int mode) unlock_kernel(); #endif crfree(credp); - return -code; + return afs_convert_code(code); } static int @@ -1155,7 +1175,7 @@ afs_linux_rmdir(struct inode *dip, struct dentry *dp) } crfree(credp); - return -code; + return afs_convert_code(code); } @@ -1207,7 +1227,7 @@ afs_linux_rename(struct inode *oldip, struct dentry *olddp, #endif crfree(credp); - return -code; + return afs_convert_code(code); } @@ -1230,7 +1250,7 @@ afs_linux_ireadlink(struct inode *ip, char *target, int maxlen, uio_seg_t seg) if (!code) return maxlen - tuio.uio_resid; else - return -code; + return afs_convert_code(code); } #if !defined(AFS_LINUX24_ENV) @@ -1378,7 +1398,7 @@ afs_linux_readpage(struct file *fp, struct page *pp) } crfree(credp); - return -code; + return afs_convert_code(code); } @@ -1421,7 +1441,7 @@ afs_linux_writepage_sync(struct inode *ip, struct page *pp, code = afs_DoPartialWrite(vcp, &treq); ReleaseWriteLock(&vcp->lock); } - code = code ? -code : count - tuio.uio_resid; + code = code ? afs_convert_code(code) : count - tuio.uio_resid; afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp, ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp), @@ -1526,7 +1546,7 @@ afs_linux_updatepage(struct file *fp, struct page *pp, unsigned long offset, ReleaseWriteLock(&vcp->lock); } - code = code ? -code : count - tuio.uio_resid; + code = code ? afs_convert_code(code) : count - tuio.uio_resid; afs_Trace4(afs_iclSetp, CM_TRACE_UPDATEPAGE, ICL_TYPE_POINTER, vcp, ICL_TYPE_POINTER, pp, ICL_TYPE_INT32, page_count(pp), ICL_TYPE_INT32, code); @@ -1564,7 +1584,7 @@ afs_linux_permission(struct inode *ip, int mode) AFS_GUNLOCK(); crfree(credp); - return -code; + return afs_convert_code(code); } #if defined(AFS_LINUX24_ENV) -- 2.39.5