From c6b61a4510c0c34688b979182ea6f3823a840296 Mon Sep 17 00:00:00 2001 From: Perry Ruiter Date: Thu, 29 May 2014 15:51:57 -0700 Subject: [PATCH] afs: Verify osi_UFSOpen worked In some builds (UKERNEL) osi_UFSOpen returns a NULL if it runs into a problem. On the other builds osi_UFSOpen simply panics. afs/afs_cell.c was checking for a NULL return but other callers were not. Add checking logic to all callers. This is a prepartory patch. A subsequent patch will have osi_UFSOpen return NULL rather than panic for other builds too. Change-Id: I3610a57dff59b84fe5ea8b1c862f3192157f255f Reviewed-on: http://gerrit.openafs.org/11243 Tested-by: BuildBot Reviewed-by: Chas Williams - CONTRACTOR Reviewed-by: Garrett Wollman Reviewed-by: Benjamin Kaduk Reviewed-by: D Brashear --- src/afs/VNOPS/afs_vnop_read.c | 2 ++ src/afs/VNOPS/afs_vnop_symlink.c | 6 ++++++ src/afs/VNOPS/afs_vnop_write.c | 3 +++ src/afs/afs_dcache.c | 7 +++++++ src/afs/afs_init.c | 5 ++++- src/afs/afs_volume.c | 28 +++++++++++++++++++++------- 6 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/afs/VNOPS/afs_vnop_read.c b/src/afs/VNOPS/afs_vnop_read.c index 66370f314..5d3d1000c 100644 --- a/src/afs/VNOPS/afs_vnop_read.c +++ b/src/afs/VNOPS/afs_vnop_read.c @@ -485,6 +485,8 @@ afs_UFSReadUIO(afs_dcache_id_t *cacheId, struct uio *tuiop) struct osi_file *tfile; tfile = (struct osi_file *) osi_UFSOpen(cacheId); + if (!tfile) + return -1; #if defined(AFS_AIX41_ENV) AFS_GUNLOCK(); diff --git a/src/afs/VNOPS/afs_vnop_symlink.c b/src/afs/VNOPS/afs_vnop_symlink.c index 4ab1619d0..0571627b5 100644 --- a/src/afs/VNOPS/afs_vnop_symlink.c +++ b/src/afs/VNOPS/afs_vnop_symlink.c @@ -394,6 +394,12 @@ afs_UFSHandleLink(struct vcache *avc, struct vrequest *areq) tlen = len; ObtainReadLock(&tdc->lock); tfile = osi_UFSOpen(&tdc->f.inode); + if (!tfile) { + ReleaseReadLock(&tdc->lock); + afs_PutDCache(tdc); + osi_FreeLargeSpace(rbuf); + return ENOENT; + } code = afs_osi_Read(tfile, -1, rbuf, tlen); osi_UFSClose(tfile); ReleaseReadLock(&tdc->lock); diff --git a/src/afs/VNOPS/afs_vnop_write.c b/src/afs/VNOPS/afs_vnop_write.c index 44d072858..086fc9d21 100644 --- a/src/afs/VNOPS/afs_vnop_write.c +++ b/src/afs/VNOPS/afs_vnop_write.c @@ -104,6 +104,9 @@ afs_UFSWriteUIO(struct vcache *avc, afs_dcache_id_t *inode, struct uio *tuiop) int code; tfile = (struct osi_file *)osi_UFSOpen(inode); + if (!tfile) + return -1; + #if defined(AFS_AIX41_ENV) AFS_GUNLOCK(); code = VNOP_RDWR(tfile->vnode, UIO_WRITE, FWRITE, tuiop, NULL, NULL, diff --git a/src/afs/afs_dcache.c b/src/afs/afs_dcache.c index dd75e2c84..235dce6e8 100644 --- a/src/afs/afs_dcache.c +++ b/src/afs/afs_dcache.c @@ -3115,6 +3115,13 @@ afs_InitCacheFile(char *afile, ino_t ainode) if ((tdc->f.states & DWriting) || tdc->f.fid.Fid.Volume == 0) fileIsBad = 1; tfile = osi_UFSOpen(&tdc->f.inode); + if (!tfile) { + ReleaseWriteLock(&afs_xdcache); + ReleaseWriteLock(&tdc->lock); + afs_PutDCache(tdc); + return ENOENT; + } + code = afs_osi_Stat(tfile, &tstat); if (code) osi_Panic("initcachefile stat"); diff --git a/src/afs/afs_init.c b/src/afs/afs_init.c index 45d4b12ac..d588c75fb 100644 --- a/src/afs/afs_init.c +++ b/src/afs/afs_init.c @@ -349,7 +349,7 @@ afs_InitVolumeInfo(char *afile) * * Environment: * This function is called only during initialization. The given - * file should NOT be truncated to 0 lenght; its contents descrebe + * file should NOT be truncated to 0 length; its contents describe * what data is really in the cache. * * WARNING: data will be written to this file over time by AFS. @@ -472,6 +472,9 @@ afs_InitCacheInfo(char *afile) afs_fsfragsize = AFS_MIN_FRAGSIZE; } tfile = osi_UFSOpen(&cacheInode); + if (!tfile) + return ENOENT; + afs_osi_Stat(tfile, &tstat); cacheInfoModTime = tstat.mtime; code = afs_osi_Read(tfile, -1, &theader, sizeof(theader)); diff --git a/src/afs/afs_volume.c b/src/afs/afs_volume.c index e9996e7d0..bf53767ed 100644 --- a/src/afs/afs_volume.c +++ b/src/afs/afs_volume.c @@ -201,6 +201,10 @@ afs_UFSGetVolSlot(afs_int32 volid, struct cell *tcell) */ if (afs_FVIndex != tv->vtix) { tfile = osi_UFSOpen(&volumeInode); + if (!tfile) { + afs_warn("afs_UFSGetVolSlot: unable to open volumeinfo\n"); + goto error; + } code = afs_osi_Read(tfile, sizeof(struct fvolume) * tv->vtix, &staticFVolume, sizeof(struct fvolume)); @@ -210,7 +214,6 @@ afs_UFSGetVolSlot(afs_int32 volid, struct cell *tcell) (int)code); goto error; } - afs_FVIndex = tv->vtix; } } afs_FVIndex = tv->vtix; @@ -221,6 +224,10 @@ afs_UFSGetVolSlot(afs_int32 volid, struct cell *tcell) staticFVolume.rootVnode = tv->rootVnode; staticFVolume.rootUnique = tv->rootUnique; tfile = osi_UFSOpen(&volumeInode); + if (!tfile) { + afs_warn("afs_UFSGetVolSlot: unable to open volumeinfo\n"); + goto error; + } code = afs_osi_Write(tfile, sizeof(struct fvolume) * afs_FVIndex, &staticFVolume, sizeof(struct fvolume)); @@ -243,13 +250,20 @@ afs_UFSGetVolSlot(afs_int32 volid, struct cell *tcell) for (j = fvTable[FVHash(tcell->cellNum, volid)]; j != 0; j = tf->next) { if (afs_FVIndex != j) { tfile = osi_UFSOpen(&volumeInode); - code = - afs_osi_Read(tfile, sizeof(struct fvolume) * j, - &staticFVolume, sizeof(struct fvolume)); - osi_UFSClose(tfile); + if (!tfile) { + afs_warn("afs_UFSGetVolSlot: unable to open volumeinfo\n"); + code = -1; /* indicate error */ + } else { + code = + afs_osi_Read(tfile, sizeof(struct fvolume) * j, + &staticFVolume, sizeof(struct fvolume)); + osi_UFSClose(tfile); + if (code != sizeof(struct fvolume)) { + afs_warn("afs_SetupVolume: error %d reading volumeinfo\n", + (int)code); + } + } if (code != sizeof(struct fvolume)) { - afs_warn("afs_SetupVolume: error %d reading volumeinfo\n", - (int)code); /* put tv back on the free list; the data in it is not valid */ tv->next = afs_freeVolList; afs_freeVolList = tv; -- 2.39.5