From dac817389081d45dab15880f34d9a35c059853c9 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Thu, 19 Nov 2009 18:19:39 -0500 Subject: [PATCH] Windows: when assigning a new clientModTime, hold a lock The smb server modifies the cm_scache_t clientModTime without holding a write lock creating a race condition. Fix it. LICENSE MIT Change-Id: I6f110f87ef76131965da31a8bf02685480ad9641 Reviewed-on: http://gerrit.openafs.org/857 Reviewed-by: Derrick Brashear Tested-by: Jeffrey Altman Reviewed-by: Jeffrey Altman --- src/WINNT/afsd/smb.c | 6 ++++++ src/WINNT/afsd/smb3.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/WINNT/afsd/smb.c b/src/WINNT/afsd/smb.c index 48c206349b..cc402f8edc 100644 --- a/src/WINNT/afsd/smb.c +++ b/src/WINNT/afsd/smb.c @@ -6804,10 +6804,12 @@ long smb_CloseFID(smb_vc_t *vcp, smb_fid_t *fidp, cm_user_t *userp, (fidp->flags & (SMB_FID_OPENWRITE | SMB_FID_DELONCLOSE)) == SMB_FID_OPENWRITE) { if (dosTime != 0 && dosTime != -1) { + lock_ObtainWrite(&fidp->scp->rw); scp->mask |= CM_SCACHEMASK_CLIENTMODTIME; /* This fixes defect 10958 */ CompensateForSmbClientLastWriteTimeBugs(&dosTime); smb_UnixTimeFromDosUTime(&scp->clientModTime, dosTime); + lock_ReleaseWrite(&fidp->scp->rw); } if (smb_AsyncStore != 2) { lock_ReleaseMutex(&fidp->mx); @@ -7536,8 +7538,10 @@ long smb_ReceiveCoreWrite(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) */ lock_ObtainMutex(&fidp->mx); if ((fidp->flags & SMB_FID_MTIMESETDONE) != SMB_FID_MTIMESETDONE) { + lock_ObtainWrite(&fidp->scp->rw); fidp->scp->mask |= CM_SCACHEMASK_CLIENTMODTIME; fidp->scp->clientModTime = time(NULL); + lock_ReleaseWrite(&fidp->scp->rw); } lock_ReleaseMutex(&fidp->mx); @@ -7764,8 +7768,10 @@ long smb_ReceiveCoreWriteRaw(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *out */ lock_ObtainMutex(&fidp->mx); if ((fidp->flags & SMB_FID_LOOKSLIKECOPY) != SMB_FID_LOOKSLIKECOPY) { + lock_ObtainWrite(&fidp->scp->rw); fidp->scp->mask |= CM_SCACHEMASK_CLIENTMODTIME; fidp->scp->clientModTime = time(NULL); + lock_ReleaseWrite(&fidp->scp->rw); } lock_ReleaseMutex(&fidp->mx); diff --git a/src/WINNT/afsd/smb3.c b/src/WINNT/afsd/smb3.c index 39acf88763..cb185df4e2 100644 --- a/src/WINNT/afsd/smb3.c +++ b/src/WINNT/afsd/smb3.c @@ -6890,8 +6890,10 @@ long smb_ReceiveV3WriteX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) */ lock_ObtainMutex(&fidp->mx); if ((fidp->flags & SMB_FID_MTIMESETDONE) != SMB_FID_MTIMESETDONE) { + lock_ObtainWrite(&fidp->scp->rw); scp->mask |= CM_SCACHEMASK_CLIENTMODTIME; scp->clientModTime = time(NULL); + lock_ReleaseWrite(&fidp->scp->rw); } lock_ReleaseMutex(&fidp->mx);