linux-stable/fs/nfsd
NeilBrown b602345da6 nfsd: fix memory corruption caused by readdir
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
Cc: stable@vger.kernel.org (v2.6.12+)
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
2019-03-05 16:41:33 -05:00
..
Kconfig block: make scsi_request and scsi ioctl support optional 2017-01-31 10:53:05 -07:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
acl.h nfsd4: remove nfs4_acl_new 2014-07-08 17:14:27 -04:00
auth.c nfsd: auth: Fix gid sorting when rootsquash enabled 2018-01-22 20:13:07 -08:00
auth.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
blocklayout.c vfs/y2038: inode timestamps conversion to timespec64 2018-06-15 07:31:07 +09:00
blocklayoutxdr.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
blocklayoutxdr.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
cache.h knfsd: Improve lookup performance in the duplicate reply cache using an rbtree 2018-10-29 16:58:04 -04:00
current_stateid.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
export.c knfsd: Allow lockless lookups of the exports 2018-10-29 16:58:04 -04:00
export.h knfsd: Allow lockless lookups of the exports 2018-10-29 16:58:04 -04:00
fault_inject.c Lots of good bugfixes, including: 2017-11-18 11:22:04 -08:00
flexfilelayout.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
flexfilelayoutxdr.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
flexfilelayoutxdr.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
idmap.h nfsd: Remove duplicate define of IDMAP_NAMESZ/IDMAP_TYPE_xx 2015-07-20 14:58:46 -04:00
lockd.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
netns.h NFSD introduce async copy feature 2018-09-25 20:34:54 -04:00
nfs2acl.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
nfs3acl.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
nfs3proc.c nfsd: fix memory corruption caused by readdir 2019-03-05 16:41:33 -05:00
nfs3xdr.c nfsd: fix memory corruption caused by readdir 2019-03-05 16:41:33 -05:00
nfs4acl.c nfsd: check permissions when setting ACLs 2016-06-24 12:11:52 -04:00
nfs4callback.c nfsd: fix an IS_ERR() vs NULL check 2019-02-06 15:37:14 -05:00
nfs4idmap.c knfsd: Lockless lookup of NFSv4 identities. 2018-10-29 16:58:04 -04:00
nfs4layouts.c nfsd: drop useless LIST_HEAD 2018-12-27 20:59:50 -05:00
nfs4proc.c NFSD remove OP_CACHEME from 4.2 op_flags 2018-12-14 12:52:15 -05:00
nfs4recover.c nfsd: fix a warning in __cld_pipe_upcall() 2018-11-28 18:36:03 -05:00
nfs4state.c nfsd: fix performance-limiting session calculation 2019-02-21 10:47:00 -05:00
nfs4xdr.c NFSD introduce async copy feature 2018-09-25 20:34:54 -04:00
nfscache.c mm: convert totalram_pages and totalhigh_pages variables to atomic 2018-12-28 12:11:47 -08:00
nfsctl.c nfsd4: fix crash on writing v4_end_grace before nfsd startup 2018-11-28 18:36:02 -05:00
nfsd.h nfsd4: support change_attr_type attribute 2018-06-17 10:41:31 -04:00
nfsfh.c nfsd: use true and false for boolean values 2018-08-09 16:11:21 -04:00
nfsfh.h This request is late, apologies. 2018-02-08 15:18:32 -08:00
nfsproc.c NFSD: Handle full-length symlinks 2018-08-09 16:11:21 -04:00
nfssvc.c race of nfsd inetaddr notifiers vs nn->nfsd_serv change 2017-11-27 16:45:11 -05:00
nfsxdr.c vfs: change inode times to use struct timespec64 2018-06-05 16:57:31 -07:00
pnfs.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
state.h NFS/NFSD/SUNRPC: replace generic creds with 'struct cred'. 2018-12-19 13:52:46 -05:00
stats.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
stats.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
trace.c nfsd: move include of state.h from trace.c to trace.h 2015-10-23 15:57:29 -04:00
trace.h nfsd: Trace NFSv4 COMPOUND execution 2018-04-03 15:08:15 -04:00
vfs.c nfsd: Fix error return values for nfsd4_clone_file_range() 2019-02-06 15:32:05 -05:00
vfs.h nfsd: Add I/O trace points in the NFSv4 read proc 2018-04-03 15:08:15 -04:00
xdr.h NFSD: Clean up legacy NFS SYMLINK argument XDR decoders 2018-04-03 15:08:16 -04:00
xdr3.h NFSD: Clean up legacy NFS SYMLINK argument XDR decoders 2018-04-03 15:08:16 -04:00
xdr4.h NFSD introduce async copy feature 2018-09-25 20:34:54 -04:00
xdr4cb.h NFSD CB_OFFLOAD xdr 2018-09-25 20:34:54 -04:00