Go to file
Andrew Deason 3caee75754 afs: Avoid incorrect size when fetching beyond EOF
Currently, afs_GetDCache contains a couple of calculations that look
similar to this:

    if (position + size > file_length) {
        size = file_length - position;
    }
    if (size < 0) {
        size = 0;
    }

Most of the time, this is fine. However, if 'position' is more than
2GiB greater than file_length, 'size' will calculated to be smaller
than -2GiB. Since 'size' in this code is a signed 32-bit integer, this
can cause 'size' to underflow, and result in a value closer to
(positive) 2GiB.

This has two potential effects:

The afs_AdjustSize call in afs_GetDCache will cause the underlying
cache file for this dcache to be very large (if our offset is around
2GiB larger than the file size). This can confuse other parts of the
client, since our cache usage reporting will be incorrect (and can be
even way larger than the max configured cache size).

This will also cause a read request to the fileserver that is larger
than necessary. Although 'size' will be capped at our chunksize, it
should be 0 in this situation, since we know there is no data to
fetch. At worst, this currently can just result in worse performance
in rare situations, but it can also just be very confusing.

Note that an afs_GetDCache request beyond EOF can currently happen in
non-race conditions on at least Solaris when performing a file write.
For example, with a chunksize of 256KiB, something like this will
trigger the overflow in 'size' in most cases:

    $ printf '' > smallfile && printf b | dd of=smallfile bs=1 oseek=2147745793

But there are probably other similar scenarios.

To fix this, just check if our offset is beyond the relevant file
size, and do not depend on 'size' having sane values in edge cases
such as this.

Change-Id: Ie36f66ce11fbee905062b3a787871ec077c15354
Reviewed-on: http://gerrit.openafs.org/11828
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Chas Williams <3chas3@gmail.com>
2016-01-24 20:27:07 -05:00
build-tools fix src tarball error text in make-release 2013-09-07 07:40:44 -07:00
doc doc: afsd -settime and -nosettime are obsolete 2016-01-24 19:17:47 -05:00
src afs: Avoid incorrect size when fetching beyond EOF 2016-01-24 20:27:07 -05:00
tests tests: give the full path to the softsig test helper program 2015-08-26 10:54:50 -04:00
.gitignore Add libtool support 2012-09-04 06:55:51 -07:00
.splintrc start-splint-support-20030528 2003-05-28 19:18:08 +00:00
acinclude.m4 Initial set of changes for El Capitan OS X 10.11 . 2016-01-24 18:39:50 -05:00
CODING rxkad: Resolve warnings in ticket5.c 2015-12-25 01:57:06 -05:00
configure-libafs.ac build-sys: use m4 quoting consistantly 2013-07-12 08:04:23 -07:00
configure.ac IRIX: Move src/sgistuff to platform/IRIX 2015-01-22 09:42:00 -05:00
CONTRIBUTING openafs: add a contributor code of conduct 2015-09-18 20:38:28 -04:00
INSTALL readme: remove README.PTHREADED_UBIK 2015-08-17 22:17:25 -04:00
libafsdep Move build support files into build-tools 2010-07-14 20:40:36 -07:00
LICENSE readme: move the LICENSE file to the top level directory 2015-08-17 22:10:05 -04:00
Makefile-libafs.in Fix libafs_tree's cross-architecture support 2010-05-24 20:28:41 -07:00
Makefile.in readme: move the LICENSE file to the top level directory 2015-08-17 22:10:05 -04:00
NEWS Update NEWS for 1.6.2.1 2013-03-25 11:45:46 -07:00
NTMakefile build: remove trailing whitespace from makefiles 2014-10-08 10:46:57 -04:00
README Tweak grammar in README 2015-12-28 19:32:17 -05:00
README-WINDOWS Update windows build documentation 2013-07-02 15:14:09 -07:00
regen.sh regen: look for glibtoolize also 2012-09-06 12:04:22 -07:00

AFS is a distributed file system that enables users to share and
access all of the files stored in a network of computers as easily as
they access the files stored on their local machines. The file system is
called distributed for this exact reason: files can reside on many
different machines, but are available to users on every machine.

OpenAFS 1.0 was originally released by IBM under the terms of the
IBM Public License 1.0 (IPL10).  For details on IPL10 see the LICENSE
file in this directory.  The current OpenAFS distribution is licensed
under a combination of the IPL10 and many other licenses as granted by
the relevant copyright holders.  The LICENSE file in this directory
contains more details, thought it is not a comprehensive statement.

See INSTALL for information about building and installing OpenAFS
on various platforms.

See CODING for developer information and guidelines.

See NEWS for recent changes to OpenAFS.