linux/fs/nfsd
NeilBrown 70fc1659eb nfsd: fix memory corruption caused by readdir
commit b602345da6 upstream.

If the result of an NFSv3 readdir{,plus} request results in the
"offset" on one entry having to be split across 2 pages, and is sized
so that the next directory entry doesn't fit in the requested size,
then memory corruption can happen.

When encode_entry() is called after encoding the last entry that fits,
it notices that ->offset and ->offset1 are set, and so stores the
offset value in the two pages as required.  It clears ->offset1 but
*does not* clear ->offset.

Normally this omission doesn't matter as encode_entry_baggage() will
be called, and will set ->offset to a suitable value (not on a page
boundary).
But in the case where cd->buflen < elen and nfserr_toosmall is
returned, ->offset is not reset.

This means that nfsd3proc_readdirplus will see ->offset with a value 4
bytes before the end of a page, and ->offset1 set to NULL.
It will try to write 8bytes to ->offset.
If we are lucky, the next page will be read-only, and the system will
  BUG: unable to handle kernel paging request at...

If we are unlucky, some innocent page will have the first 4 bytes
corrupted.

nfsd3proc_readdir() doesn't even check for ->offset1, it just blindly
writes 8 bytes to the offset wherever it is.

Fix this by clearing ->offset after it is used, and copying the
->offset handling code from nfsd3_proc_readdirplus into
nfsd3_proc_readdir.

(Note that the commit hash in the Fixes tag is from the 'history'
 tree - this bug predates git).

Fixes: 0b1d57cf7654 ("[PATCH] kNFSd: Fix nfs3 dentry encoding")
Fixes-URL: https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=0b1d57cf7654
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
History 2019-07-09 22:04:11 +01:00
..
acl.h nfsd4: use xdr_reserve_space in attribute encoding 2014-05-28 14:52:34 -04:00
auth.c nfsd: silence sparse warning about accessing credentials 2018-11-20 18:05:28 +00:00
auth.h nfsd: Remove nfsd_luid, nfsd_lgid, nfsd_ruid and nfsd_rgid 2013-02-13 06:15:51 -08:00
cache.h nfsd: get rid of unused function definition 2014-01-02 17:53:23 -05:00
current_stateid.h nfsd41: use current stateid by value 2012-02-15 11:20:45 -05:00
export.c NFSD: Error out when getting more than one fsloc/secinfo/uuid 2014-05-30 17:32:25 -04:00
export.h NFSD: Using type of uint32_t for ex_nflavors instead of int 2014-05-30 17:32:24 -04:00
fault_inject.c NFSD: Use simple_read_from_buffer for coping data to userspace 2014-05-08 14:59:52 -04:00
idmap.h nfsd4: use xdr_reserve_space in attribute encoding 2014-05-28 14:52:34 -04:00
Kconfig nfsd: fix Kconfig syntax 2013-10-26 15:37:26 -04:00
lockd.c nfsd: Remove deprecated nfsctl system call and related code. 2011-07-15 18:58:42 -04:00
Makefile NFSD: Added fault injection 2011-11-07 21:10:47 -05:00
netns.h NFSD: Don't start lockd when only NFSv4 is running 2014-01-03 18:18:50 -05:00
nfs2acl.c nfsd: check permissions when setting ACLs 2016-08-22 22:38:20 +01:00
nfs3acl.c nfsd: check permissions when setting ACLs 2016-08-22 22:38:20 +01:00
nfs3proc.c nfsd: fix memory corruption caused by readdir 2019-07-09 22:04:11 +01:00
nfs3xdr.c nfsd: fix memory corruption caused by readdir 2019-07-09 22:04:11 +01:00
nfs4acl.c nfsd: check permissions when setting ACLs 2016-08-22 22:38:20 +01:00
nfs4callback.c nfsd: Fix slot wake up race in the nfsv4.1 callback code 2014-12-10 17:14:59 +00:00
nfs4idmap.c nfsd4: use xdr_reserve_space in attribute encoding 2014-05-28 14:52:34 -04:00
nfs4proc.c nfsd: fix deadlock secinfo+readdir compound 2016-05-01 00:06:00 +02:00
nfs4recover.c nfsd: switch to %p[dD] 2013-10-24 23:34:51 -04:00
nfs4state.c nfsd: fix the check for confirmed openowner in nfs4_preprocess_stateid_op 2015-05-28 09:59:59 +01:00
nfs4xdr.c nfsd: restrict rd_maxcount to svc_max_payload in nfsd_encode_readdir 2018-11-20 18:04:51 +00:00
nfscache.c nfsd: don't halt scanning the DRC LRU list when there's an RC_INPROG entry 2014-06-06 19:22:49 -04:00
nfsctl.c nfsd: fix nsfd startup race triggering BUG_ON 2015-05-06 10:36:19 +01:00
nfsd.h nfsd: correctly define v4.2 support attributes 2014-12-10 17:14:53 +00:00
nfsfh.c SUNRPC/NFSD: Remove using of dprintk with KERN_WARNING 2014-05-30 20:25:28 -04:00
nfsfh.h nfsd: remove <linux/nfsd/nfsfh.h> 2014-05-06 17:54:53 -04:00
nfsproc.c switch vfs_getattr() to struct path 2013-02-26 02:46:08 -05:00
nfssvc.c nfsd: check for oversized NFSv2/v3 arguments 2017-06-05 21:17:23 +01:00
nfsxdr.c nfsd: stricter decoding of write-like NFSv2/v3 ops 2017-06-05 21:17:23 +01:00
state.h nfsd4: allow larger 4.1 session drc slots 2014-05-23 09:03:41 -04:00
stats.c nfsd: move <linux/nfsd/stats.h> to fs/nfsd 2014-05-06 17:54:55 -04:00
stats.h nfsd: move <linux/nfsd/stats.h> to fs/nfsd 2014-05-06 17:54:55 -04:00
vfs.c ima: pass 'opened' flag to identify newly created files 2017-08-26 02:14:23 +01:00
vfs.h nfsd: remove unused function nfsd_read_file 2014-05-30 17:32:27 -04:00
xdr.h nfsd: handle vfs_getattr errors in acl protocol 2013-02-26 02:46:09 -05:00
xdr3.h nfsd: fix encode_entryplus_baggage stack usage 2014-01-23 13:50:27 -05:00
xdr4.h nfsd4: allow large readdirs 2014-05-30 17:32:03 -04:00
xdr4cb.h nfsd4: check backchannel attributes on create_session 2013-04-09 16:53:56 -04:00