afs: Check dcache size when checking DVs 36/13436/7
authorAndrew Deason <adeason@sinenomine.net>
Thu, 17 Jan 2019 22:21:25 +0000 (16:21 -0600)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 12 Jul 2019 15:14:49 +0000 (11:14 -0400)
commit7c60a0fba11dd24494a5f383df8bea5fdbabbdd7
tree0496de789ce46f0e54ea43463807612413f2e640
parenteed79e2d28dcab889d01869e57dec14fd30d421c
afs: Check dcache size when checking DVs

Currently, if the dcache for a file has nonsensical length (due to
cache corruption or other bugs), we never notice, and we serve
obviously bad data to applications. For example, the vcache metadata
for a file may say the file is 2k bytes long, but the dcache for that
file only has 1k bytes in it (or more commonly, 0 bytes).

This situation is easily detectable, since the dcache and vcache refer
to the same version of the same file (when the DVs match), and so we
can check if the two lengths make sense together. So to avoid giving
bad data to userspace applications, perform a sanity check on the
lengths at the same time we check for DV matches (to see if the dcache
looks "fresh" and not stale). If the lengths do not make sense
together, we just pretend that the dcache is old, and so we'll ignore
it and fetch a new copy from the fileserver.

Also check the size of the data fetched from the fileserver for a
newly-fetched dcache in afs_GetDCache, to avoid returning a bad dcache
if the dcache isn't already present in the cache.

Change-Id: I338a4962322d8c0d06d1ea25fd7d252b5f83dc9f
Reviewed-on: https://gerrit.openafs.org/13436
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
src/afs/afs_dcache.c