All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org, NeilBrown <neilb@suse.com>,
	"Ari Kauppi" <ari@synopsys.com>,
	"Tuomas Haanpää" <thaan@synopsys.com>,
	"J. Bruce Fields" <bfields@redhat.com>
Subject: [PATCH 3.2 091/101] nfsd: check for oversized NFSv2/v3 arguments
Date: Thu, 01 Jun 2017 16:40:55 +0100	[thread overview]
Message-ID: <lsq.1496331655.78721593@decadent.org.uk> (raw)
In-Reply-To: <lsq.1496331653.552489284@decadent.org.uk>

3.2.89-rc1 review patch.  If anyone has any objections, please let me know.

------------------

From: "J. Bruce Fields" <bfields@redhat.com>

commit e6838a29ecb484c97e4efef9429643b9851fba6e upstream.

A client can append random data to the end of an NFSv2 or NFSv3 RPC call
without our complaining; we'll just stop parsing at the end of the
expected data and ignore the rest.

Encoded arguments and replies are stored together in an array of pages,
and if a call is too large it could leave inadequate space for the
reply.  This is normally OK because NFS RPC's typically have either
short arguments and long replies (like READ) or long arguments and short
replies (like WRITE).  But a client that sends an incorrectly long reply
can violate those assumptions.  This was observed to cause crashes.

Also, several operations increment rq_next_page in the decode routine
before checking the argument size, which can leave rq_next_page pointing
well past the end of the page array, causing trouble later in
svc_free_pages.

So, following a suggestion from Neil Brown, add a central check to
enforce our expectation that no NFSv2/v3 call has both a large call and
a large reply.

As followup we may also want to rewrite the encoding routines to check
more carefully that they aren't running off the end of the page array.

We may also consider rejecting calls that have any extra garbage
appended.  That would be safer, and within our rights by spec, but given
the age of our server and the NFS protocol, and the fact that we've
never enforced this before, we may need to balance that against the
possibility of breaking some oddball client.

Reported-by: Tuomas Haanpää <thaan@synopsys.com>
Reported-by: Ari Kauppi <ari@synopsys.com>
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 fs/nfsd/nfssvc.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -561,6 +561,37 @@ static __be32 map_new_errors(u32 vers, _
 	return nfserr;
 }
 
+/*
+ * A write procedure can have a large argument, and a read procedure can
+ * have a large reply, but no NFSv2 or NFSv3 procedure has argument and
+ * reply that can both be larger than a page.  The xdr code has taken
+ * advantage of this assumption to be a sloppy about bounds checking in
+ * some cases.  Pending a rewrite of the NFSv2/v3 xdr code to fix that
+ * problem, we enforce these assumptions here:
+ */
+static bool nfs_request_too_big(struct svc_rqst *rqstp,
+				struct svc_procedure *proc)
+{
+	/*
+	 * The ACL code has more careful bounds-checking and is not
+	 * susceptible to this problem:
+	 */
+	if (rqstp->rq_prog != NFS_PROGRAM)
+		return false;
+	/*
+	 * Ditto NFSv4 (which can in theory have argument and reply both
+	 * more than a page):
+	 */
+	if (rqstp->rq_vers >= 4)
+		return false;
+	/* The reply will be small, we're OK: */
+	if (proc->pc_xdrressize > 0 &&
+	    proc->pc_xdrressize < XDR_QUADLEN(PAGE_SIZE))
+		return false;
+
+	return rqstp->rq_arg.len > PAGE_SIZE;
+}
+
 int
 nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp)
 {
@@ -573,6 +604,11 @@ nfsd_dispatch(struct svc_rqst *rqstp, __
 				rqstp->rq_vers, rqstp->rq_proc);
 	proc = rqstp->rq_procinfo;
 
+	if (nfs_request_too_big(rqstp, proc)) {
+		dprintk("nfsd: NFSv%d argument too large\n", rqstp->rq_vers);
+		*statp = rpc_garbage_args;
+		return 1;
+	}
 	/*
 	 * Give the xdr decoder a chance to change this if it wants
 	 * (necessary in the NFSv4.0 compound case)

  parent reply	other threads:[~2017-06-01 15:44 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-01 15:40 [PATCH 3.2 000/101] 3.2.89-rc1 review Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 032/101] USB: serial: digi_acceleport: fix OOB-event processing Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 031/101] USB: serial: digi_acceleport: fix OOB data sanity check Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 049/101] powerpc/xmon: Fix data-breakpoint Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 043/101] KEYS: Fix an error code in request_master_key() Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 066/101] ALSA: timer: Reject user params with too small ticks Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 033/101] USB: serial: digi_acceleport: fix incomplete rx sanity check Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 039/101] serial: 8250_pci: Add MKS Tenta SCOM-0800 and SCOM-0801 cards Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 020/101] usb: dwc3: gadget: skip Set/Clear Halt when invalid Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 056/101] nfsd: special case truncates some more Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 023/101] USB: serial: ftdi_sio: fix extreme low-latency setting Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 029/101] bcma: use (get|put)_device when probing/removing device driver Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 024/101] drm/ttm: Make sure BOs being swapped out are cacheable Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 046/101] md linear: fix a race between linear_add() and linear_congested() Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 045/101] mmc: host: omap_hsmmc: avoid possible overflow of timeout value Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 074/101] xfrm_user: validate XFRM_MSG_NEWAE XFRMA_REPLAY_ESN_VAL replay_window Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 021/101] usb: gadget: f_hid: Use spinlock instead of mutex Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 060/101] net/dccp: fix use after free in tw_timer_handler() Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 079/101] net/packet: fix overflow in check for priv area size Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 093/101] nfsd: stricter decoding of write-like NFSv2/v3 ops Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 082/101] KEYS: fix keyctl_set_reqkey_keyring() to not leak thread keyrings Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 061/101] scsi: aacraid: Fix memory leak in fib init path Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 075/101] xfrm_user: validate XFRM_MSG_NEWAE incoming ESN size harder Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 055/101] nfsd: minor nfsd_setattr cleanup Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 092/101] nfsd4: minor NFSv2/v3 write decoding cleanup Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 014/101] USB: serial: mct_u232: fix modem-status error handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 051/101] MIPS: Fix special case in 64 bit IP checksumming Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 009/101] USB: serial: ark3116: fix open error handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 089/101] tracing: Use strlcpy() instead of strcpy() in __trace_find_cmdline() Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 080/101] net/packet: fix overflow in check for tp_frame_nr Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 018/101] perf script: Fix man page about --dump-raw-trace option Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 085/101] crypto: hash - Fix the pointer voodoo in unaligned ahash Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 016/101] USB: serial: ti_usb_3410_5052: fix control-message error handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 071/101] KEYS: Reinstate EPERM for a key type name beginning with a '.' Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 006/101] IB/ipoib: Change list_del to list_del_init in the tx object Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 040/101] USB: serial: cp210x: add new IDs for GE Bx50v3 boards Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 078/101] packet: handle too big packets for PACKET_V3 Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 003/101] ath5k: drop bogus warning on drv_set_key with unsupported cipher Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 026/101] ext4: trim allocation requests to group size Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 035/101] s390/qdio: clear DSCI prior to scanning multiple input queues Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 042/101] USB: serial: mos7840: fix another NULL-deref at open Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 070/101] KEYS: special dot prefixed keyring name bug fix Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 038/101] ext4: preserve the needs_recovery flag when the journal is aborted Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 001/101] adm80211: return an error if adm8211_alloc_rings() fails Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 012/101] USB: serial: io_edgeport: fix epic-descriptor handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 017/101] staging: rtl: fix possible NULL pointer dereference Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 095/101] USB: serial: io_ti: fix information leak in completion handler Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 076/101] drm/vmwgfx: NULL pointer dereference in vmw_surface_define_ioctl() Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 004/101] RDMA/core: Fix incorrect structure packing for booleans Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 057/101] NFSv4: Fix the underestimation of delegation XDR space reservation Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 096/101] USB: serial: omninet: fix reference leaks at open Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 067/101] ALSA: ctxfi: Fallback DMA mask to 32bit Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 050/101] Bluetooth: Add another AR3012 04ca:3018 device Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 044/101] drivers: hv: Turn off write permission on the hypercall page Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 037/101] jbd2: don't leak modified metadata buffers on an aborted journal Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 081/101] net/packet: fix overflow in check for tp_reserve Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 099/101] sctp: do not inherit ipv6_{mc|ac|fl}_list from parent Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 098/101] ipv6: Check ip6_find_1stfragopt() return value properly Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 058/101] fuse: add missing FR_FORCE Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 027/101] ext4: use private version of page_zero_new_buffers() for data=journal mode Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 041/101] USB: serial: ftdi_sio: fix line-status over-reporting Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 010/101] USB: serial: ftdi_sio: fix modem-status error handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 028/101] ext4: fix data corruption in data=journal mode Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 052/101] MIPS: OCTEON: Fix copy_from_user fault handling for large buffers Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 063/101] NFSv4: Fix range checking in __nfs4_get_acl_uncached and __nfs4_proc_set_acl Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 083/101] mm/mempolicy.c: fix error handling in set_mempolicy and mbind Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 062/101] scsi: aacraid: Reorder Adapter status check Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 077/101] drm/vmwgfx: fix integer overflow in vmw_surface_define_ioctl() Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 002/101] tty: serial: msm: Fix module autoload Ben Hutchings
2017-06-01 15:40 ` Ben Hutchings [this message]
2017-06-01 15:40 ` [PATCH 3.2 084/101] crypto: ahash - Fully restore ahash request before completing Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 030/101] [media] media: fix dm1105.c build error Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 015/101] USB: serial: ssu100: fix control-message error handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 068/101] ALSA: seq: Fix link corruption by event " Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 086/101] crypto: hash - Pull out the functions to save/restore request Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 007/101] USB: serial: ch341: fix modem-status handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 072/101] KEYS: Disallow keyrings beginning with '.' to be joined as session keyrings Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 013/101] USB: serial: io_edgeport: fix descriptor error handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 069/101] USB: iowarrior: fix NULL-deref at probe Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 025/101] drm/radeon: handle vfct with multiple vbios images Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 048/101] nlm: Ensure callback code also checks that the files match Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 064/101] NFSv4: fix getacl ERANGE for some ACL buffer sizes Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 034/101] USB: serial: keyspan_pda: fix receive sanity checks Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 008/101] USB: serial: ark3116: fix register-accessor error handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 005/101] IB/ipoib: Set device connection mode only when needed Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 101/101] ipv6: fix out of bound writes in __ip6_append_data() Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 100/101] ipv6/dccp: do not inherit ipv6_mc_list from parent Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 011/101] USB: serial: ftdi_sio: fix latency-timer error handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 065/101] net sched actions: decrement module reference count after table flush Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 047/101] md: ensure md devices are freed before module is unloaded Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 087/101] crypto: hash - Simplify the ahash_finup implementation Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 059/101] rdma_cm: fail iwarp accepts w/o connection params Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 053/101] MIPS: ip27: Disable qlge driver in defconfig Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 036/101] x86/pci-calgary: Fix iommu_free() comparison of unsigned expression >= 0 Ben Hutchings
2017-06-01 15:40   ` Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 090/101] ipx: call ipxitf_put() in ioctl error path Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 094/101] dccp/tcp: do not inherit mc_list from parent Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 097/101] ipv6: Prevent overrun when parsing v6 header options Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 073/101] ping: implement proper locking Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 019/101] mwifiex: debugfs: Fix (sometimes) off-by-1 SSID print Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 088/101] crypto: ahash - Fix EINPROGRESS notification callback Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 022/101] MIPS: 'make -s' should be silent Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 054/101] nfsd: update mtime on truncate Ben Hutchings
2017-06-01 21:41 ` [PATCH 3.2 000/101] 3.2.89-rc1 review Guenter Roeck
2017-06-01 21:59   ` Ben Hutchings

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=lsq.1496331655.78721593@decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=ari@synopsys.com \
    --cc=bfields@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neilb@suse.com \
    --cc=stable@vger.kernel.org \
    --cc=thaan@synopsys.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.