Skip to contentSkip to conversation

Fixes for the NFSv4.2 READ_PLUS operation

PATCH Superseded [email protected] 3 participants 21 messages Dec 9, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

cover Fixes for the NFSv4.2 READ_PLUS operation

From: Trond Myklebust <[email protected]>

The patches are divided into three parts:
1) A set of SUNRPC patches to fix and clean up the XDR decoding operations that are used by READ_PLUS, READ and READDIR. The main focus is on the operations used to shift data left and right in pages.
2) A set of patches to the NFSv4.2 READ_PLUS client code. These mainly try to fix issues around bounds checking, but also fix at least one protocol conformance problem.
3) A couple of patches for the READ_PLUS server code. These fix issues when nfsd_readv() returns fewer bytes than the maximum requested, and when the READ_PLUS gets truncated.

The patches are intended to apply on top of my existing 'testing' branch in git.linux-nfs.org.

Trond Myklebust (16):
SUNRPC: _shift_data_left/right_pages should check the shift length
SUNRPC: Fixes for xdr_align_data()
SUNRPC: Fix xdr_expand_hole()
SUNRPC: Cleanup xdr_shrink_bufhead()
SUNRPC: _copy_to/from_pages() now check for zero length
SUNRPC: Clean up open coded setting of the xdr_stream 'nwords' field
SUNRPC: Cleanup - constify a number of xdr_buf helpers
SUNRPC: Avoid unnecessary copies in xdr_buf_pages_copy_left/right() NFSv4.2: Ensure we always reset the result->count in
decode_read_plus()
NFSv4.2: decode_read_plus_data() must skip padding after data segment NFSv4.2: decode_read_plus_hole() needs to check the extent offset NFSv4.2: Handle hole lengths that exceed the READ_PLUS read buffer NFSv4.2: Don't error when exiting early on a READ_PLUS buffer overflow NFSv4.2: Deal with potential READ_PLUS data extent buffer overflow
nfsd: Fixes for nfsd4_encode_read_plus_data()
nfsd: Don't set eof on a truncated READ_PLUS

 fs/nfs/nfs42xdr.c          |  78 +++--
 fs/nfsd/nfs4xdr.c          |  14 +-
 include/linux/sunrpc/xdr.h |  26 +-
 net/sunrpc/xdr.c           | 674 +++++++++++++++++++++++--------------
 4 files changed, 493 insertions(+), 299 deletions(-)
Signature · 1 line
2.29.2
author maintainer
#1 lore raw

PATCH 1/16 SUNRPC: _shift_data_left/right_pages should check the shift length

From: Trond Myklebust <[email protected]>

Exit early if the shift is zero.

---
 net/sunrpc/xdr.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
net/sunrpc/xdr.c +12 -0
index f9efc207a7d5..1d48934bdf9e 100644
@@ -226,6 +226,9 @@ _shift_data_left_pages(struct page **pages, size_t pgto_base,
 
 	BUG_ON(pgfrom_base <= pgto_base);
 
+	if (!len)
+		return;
+
 	pgto = pages + (pgto_base >> PAGE_SHIFT);
 	pgfrom = pages + (pgfrom_base >> PAGE_SHIFT);
 
@@ -308,6 +311,9 @@ _shift_data_right_pages(struct page **pages, size_t pgto_base,
 
 	BUG_ON(pgto_base <= pgfrom_base);
 
+	if (!len)
+		return;
+
 	pgto_base += len;
 	pgfrom_base += len;
 
@@ -406,6 +412,9 @@ _copy_to_pages(struct page **pages, size_t pgbase, const char *p, size_t len)
 	char *vto;
 	size_t copy;
 
+	if (!len)
+		return;
+
 	pgto = pages + (pgbase >> PAGE_SHIFT);
 	pgbase &= ~PAGE_MASK;
 
@@ -450,6 +459,9 @@ _copy_from_pages(char *p, struct page **pages, size_t pgbase, size_t len)
 	char *vfrom;
 	size_t copy;
 
+	if (!len)
+		return;
+
 	pgfrom = pages + (pgbase >> PAGE_SHIFT);
 	pgbase &= ~PAGE_MASK;
 
Signature · 1 line
2.29.2
author maintainer
#2 lore raw

PATCH 2/16 SUNRPC: Fixes for xdr_align_data()

From: Trond Myklebust <[email protected]>

The main use case right now for xdr_align_data() is to shift the page data to the left, and in practice shrink the total XDR data buffer. This patch ensures that we fix up the accounting for the buffer length as we shift that data around.

---
 include/linux/sunrpc/xdr.h |   2 +-
 net/sunrpc/xdr.c           | 160 +++++++++++++++++++++++++++----------
 2 files changed, 120 insertions(+), 42 deletions(-)
include/linux/sunrpc/xdr.h +1 -1
index 9548d075e06d..2b4e44bb0654 100644
@@ -252,7 +252,7 @@ extern __be32 *xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes);
 extern unsigned int xdr_read_pages(struct xdr_stream *xdr, unsigned int len);
 extern void xdr_enter_page(struct xdr_stream *xdr, unsigned int len);
 extern int xdr_process_buf(struct xdr_buf *buf, unsigned int offset, unsigned int len, int (*actor)(struct scatterlist *, void *), void *data);
-extern uint64_t xdr_align_data(struct xdr_stream *, uint64_t, uint32_t);
+extern unsigned int xdr_align_data(struct xdr_stream *, unsigned int offset, unsigned int length);
 extern uint64_t xdr_expand_hole(struct xdr_stream *, uint64_t, uint64_t);
 
 /**
net/sunrpc/xdr.c +119 -41

189 lines not on this page · raw message

Signature · 1 line
2.29.2
author maintainer
#3 lore raw

PATCH 3/16 SUNRPC: Fix xdr_expand_hole()

From: Trond Myklebust <[email protected]>

We do want to try to grow the buffer if possible, but if that attempt fails, we still want to move the data and truncate the XDR message.

---
 include/linux/sunrpc/xdr.h |   2 +-
 net/sunrpc/xdr.c           | 254 +++++++++++++++++++++++--------------
 2 files changed, 160 insertions(+), 96 deletions(-)
include/linux/sunrpc/xdr.h +1 -1
index 2b4e44bb0654..178f499e2283 100644
@@ -253,7 +253,7 @@ extern unsigned int xdr_read_pages(struct xdr_stream *xdr, unsigned int len);
 extern void xdr_enter_page(struct xdr_stream *xdr, unsigned int len);
 extern int xdr_process_buf(struct xdr_buf *buf, unsigned int offset, unsigned int len, int (*actor)(struct scatterlist *, void *), void *data);
 extern unsigned int xdr_align_data(struct xdr_stream *, unsigned int offset, unsigned int length);
-extern uint64_t xdr_expand_hole(struct xdr_stream *, uint64_t, uint64_t);
+extern unsigned int xdr_expand_hole(struct xdr_stream *, unsigned int offset, unsigned int length);
 
 /**
  * xdr_stream_remaining - Return the number of bytes remaining in the stream
net/sunrpc/xdr.c +159 -95

320 lines not on this page · raw message

Signature · 1 line
2.29.2
author maintainer
#4 lore raw

PATCH 4/16 SUNRPC: Cleanup xdr_shrink_bufhead()

From: Trond Myklebust <[email protected]>

Clean up xdr_shrink_bufhead() to use the new helpers instead of doing its own thing.

---
 net/sunrpc/xdr.c | 160 +++++++++++++++++++++++------------------------
 1 file changed, 80 insertions(+), 80 deletions(-)
net/sunrpc/xdr.c +80 -80
index e19e89cbb6eb..cbf1bccac4fc 100644
@@ -544,6 +544,51 @@ static void xdr_buf_pages_copy_right(const struct xdr_buf *buf,
 				buf->page_base + base, pglen);
 }
 
+static void xdr_buf_head_copy_right(const struct xdr_buf *buf,
+				    unsigned int base, unsigned int shift)
+{
+	const struct kvec *head = buf->head;
+	const struct kvec *tail = buf->tail;
+	unsigned int to = base + shift;
+	unsigned int len = head->iov_len - base;
+	unsigned int pglen = 0, pgto = 0;
+	unsigned int talen = 0, tato = 0;
+
+	if (base >= head->iov_len)
+		return;
+	if (head->iov_len > to) {
+		pglen = shift;
+		if (pglen > buf->page_len) {
+			talen = pglen - buf->page_len;
+			pglen = buf->page_len;
+		}
+	} else if (buf->page_len + head->iov_len > to) {
+		pgto = to - head->iov_len;
+		pglen = len;
+		if (pgto + pglen > buf->page_len) {
+			talen = pgto + pglen - buf->page_len;
+			pglen -= talen;
+		}
+	} else {
+		tato = to - buf->page_len - head->iov_len;
+		talen = len;
+	}
+
+	len -= talen;
+	base += len;
+	if (talen + tato > tail->iov_len)
+		talen = tail->iov_len > tato ? tail->iov_len - tato : 0;
+	memcpy(tail->iov_base + tato, head->iov_base + base, talen);
+
+	len -= pglen;
+	base -= pglen;
+	_copy_to_pages(buf->pages, buf->page_base + pgto, head->iov_base + base,
+		       pglen);
+
+	base -= len;
+	memmove(head->iov_base + to, head->iov_base + base, len);
+}
+
 static void xdr_buf_tail_shift_right(const struct xdr_buf *buf,
 				     unsigned int base, unsigned int shift)
 {
@@ -567,6 +612,21 @@ static void xdr_buf_pages_shift_right(const struct xdr_buf *buf,
 	xdr_buf_pages_copy_right(buf, base, shift);
 }
 
+static void xdr_buf_head_shift_right(const struct xdr_buf *buf,
+				     unsigned int base, unsigned int shift)
+{
+	const struct kvec *head = buf->head;
+
+	if (!shift)
+		return;
+	if (base >= head->iov_len) {
+		xdr_buf_pages_shift_right(buf, head->iov_len - base, shift);
+		return;
+	}
+	xdr_buf_pages_shift_right(buf, 0, shift);
+	xdr_buf_head_copy_right(buf, base, shift);
+}
+
 static void xdr_buf_tail_copy_left(const struct xdr_buf *buf, unsigned int base,
 				   unsigned int shift)
 {
@@ -665,86 +725,27 @@ static void xdr_buf_pages_shift_left(const struct xdr_buf *buf,
 /**
  * xdr_shrink_bufhead
  * @buf: xdr_buf
- * @len: bytes to remove from buf->head[0]
+ * @len: new length of buf->head[0]
  *
- * Shrinks XDR buffer's header kvec buf->head[0] by
+ * Shrinks XDR buffer's header kvec buf->head[0], setting it to
  * 'len' bytes. The extra data is not lost, but is instead
  * moved into the inlined pages and/or the tail.
  */
-static unsigned int
-xdr_shrink_bufhead(struct xdr_buf *buf, size_t len)
-{
-	struct kvec *head, *tail;
-	size_t copy, offs;
-	unsigned int pglen = buf->page_len;
-	unsigned int result;
-
-	result = 0;
-	tail = buf->tail;
-	head = buf->head;
-
-	WARN_ON_ONCE(len > head->iov_len);
-	if (len > head->iov_len)
-		len = head->iov_len;
-
-	/* Shift the tail first */
-	if (tail->iov_len != 0) {
-		if (tail->iov_len > len) {
-			copy = tail->iov_len - len;
-			memmove((char *)tail->iov_base + len,
-					tail->iov_base, copy);
-			result += copy;
-		}
-		/* Copy from the inlined pages into the tail */
-		copy = len;
-		if (copy > pglen)
-			copy = pglen;
-		offs = len - copy;
-		if (offs >= tail->iov_len)
-			copy = 0;
-		else if (copy > tail->iov_len - offs)
-			copy = tail->iov_len - offs;
-		if (copy != 0) {
-			_copy_from_pages((char *)tail->iov_base + offs,
-					buf->pages,
-					buf->page_base + pglen + offs - len,
-					copy);
-			result += copy;
-		}
-		/* Do we also need to copy data from the head into the tail ? */
-		if (len > pglen) {
-			offs = copy = len - pglen;
-			if (copy > tail->iov_len)
-				copy = tail->iov_len;
-			memcpy(tail->iov_base,
-					(char *)head->iov_base +
-					head->iov_len - offs,
-					copy);
-			result += copy;
-		}
-	}
-	/* Now handle pages */
-	if (pglen != 0) {
-		if (pglen > len)
-			_shift_data_right_pages(buf->pages,
-					buf->page_base + len,
-					buf->page_base,
-					pglen - len);
-		copy = len;
-		if (len > pglen)
-			copy = pglen;
-		_copy_to_pages(buf->pages, buf->page_base,
-				(char *)head->iov_base + head->iov_len - len,
-				copy);
-		result += copy;
-	}
-	head->iov_len -= len;
-	buf->buflen -= len;
-	/* Have we truncated the message? */
-	if (buf->len > buf->buflen)
-		buf->len = buf->buflen;
+static unsigned int xdr_shrink_bufhead(struct xdr_buf *buf, unsigned int len)
+{
+	struct kvec *head = buf->head;
+	unsigned int shift = head->iov_len - len;
 
-	return result;
+	WARN_ON_ONCE(shift > head->iov_len);
+	if (len >= head->iov_len)
+		return 0;
+
+	xdr_buf_try_expand(buf, shift);
+	xdr_buf_head_shift_right(buf, len, shift);
+	head->iov_len = len;
+	buf->buflen -= shift;
+	buf->len -= shift;
+	return shift;
 }
 
 /**
@@ -772,7 +773,7 @@ static unsigned int xdr_shrink_pagelen(struct xdr_buf *buf, unsigned int len)
 void
 xdr_shift_buf(struct xdr_buf *buf, size_t len)
 {
-	xdr_shrink_bufhead(buf, len);
+	xdr_shrink_bufhead(buf, buf->head->iov_len - len);
 }
 EXPORT_SYMBOL_GPL(xdr_shift_buf);
 
@@ -1345,13 +1346,12 @@ static void xdr_realign_pages(struct xdr_stream *xdr)
 	struct xdr_buf *buf = xdr->buf;
 	struct kvec *iov = buf->head;
 	unsigned int cur = xdr_stream_pos(xdr);
-	unsigned int copied, offset;
+	unsigned int copied;
 
 	/* Realign pages to current pointer position */
 	if (iov->iov_len > cur) {
-		offset = iov->iov_len - cur;
-		copied = xdr_shrink_bufhead(buf, offset);
-		trace_rpc_xdr_alignment(xdr, offset, copied);
+		copied = xdr_shrink_bufhead(buf, cur);
+		trace_rpc_xdr_alignment(xdr, cur, copied);
 		xdr->nwords = XDR_QUADLEN(buf->len - cur);
 	}
 }
Signature · 1 line
2.29.2
author maintainer
#5 lore raw

PATCH 5/16 SUNRPC: _copy_to/from_pages() now check for zero length

From: Trond Myklebust <[email protected]>

Clean up callers of _copy_to/from_pages() that still check for a zero length.

---
 net/sunrpc/xdr.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/sunrpc/xdr.c +2 -4
index cbf1bccac4fc..196a06d32312 100644
@@ -1624,8 +1624,7 @@ static void __read_bytes_from_xdr_buf(struct xdr_buf *subbuf, void *obj, unsigne
 	len -= this_len;
 	obj += this_len;
 	this_len = min_t(unsigned int, len, subbuf->page_len);
-	if (this_len)
-		_copy_from_pages(obj, subbuf->pages, subbuf->page_base, this_len);
+	_copy_from_pages(obj, subbuf->pages, subbuf->page_base, this_len);
 	len -= this_len;
 	obj += this_len;
 	this_len = min_t(unsigned int, len, subbuf->tail[0].iov_len);
@@ -1655,8 +1654,7 @@ static void __write_bytes_to_xdr_buf(struct xdr_buf *subbuf, void *obj, unsigned
 	len -= this_len;
 	obj += this_len;
 	this_len = min_t(unsigned int, len, subbuf->page_len);
-	if (this_len)
-		_copy_to_pages(subbuf->pages, subbuf->page_base, obj, this_len);
+	_copy_to_pages(subbuf->pages, subbuf->page_base, obj, this_len);
 	len -= this_len;
 	obj += this_len;
 	this_len = min_t(unsigned int, len, subbuf->tail[0].iov_len);
Signature · 1 line
2.29.2
author maintainer
#6 lore raw

PATCH 6/16 SUNRPC: Clean up open coded setting of the xdr_stream 'nwords' field

From: Trond Myklebust <[email protected]>

Move the setting of the xdr_stream 'nwords' field into the helpers that reset the xdr_stream cursor.

---
 net/sunrpc/xdr.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)
net/sunrpc/xdr.c +16 -13
index 196a06d32312..78232204e6da 100644
@@ -1147,6 +1147,15 @@ static unsigned int xdr_set_iov(struct xdr_stream *xdr, struct kvec *iov,
 	return len - base;
 }
 
+static unsigned int xdr_set_tail_base(struct xdr_stream *xdr,
+				      unsigned int base, unsigned int len)
+{
+	struct xdr_buf *buf = xdr->buf;
+
+	xdr_stream_set_pos(xdr, base + buf->page_len + buf->head->iov_len);
+	return xdr_set_iov(xdr, buf->tail, base, len);
+}
+
 static unsigned int xdr_set_page_base(struct xdr_stream *xdr,
 				      unsigned int base, unsigned int len)
 {
@@ -1165,6 +1174,7 @@ static unsigned int xdr_set_page_base(struct xdr_stream *xdr,
 	if (len > maxlen)
 		len = maxlen;
 
+	xdr_stream_page_set_pos(xdr, base);
 	base += xdr->buf->page_base;
 
 	pgnr = base >> PAGE_SHIFT;
@@ -1187,7 +1197,7 @@ static void xdr_set_page(struct xdr_stream *xdr, unsigned int base,
 {
 	if (xdr_set_page_base(xdr, base, len) == 0) {
 		base -= xdr->buf->page_len;
-		xdr_set_iov(xdr, xdr->buf->tail, base, len);
+		xdr_set_tail_base(xdr, base, len);
 	}
 }
 
@@ -1200,7 +1210,7 @@ static void xdr_set_next_page(struct xdr_stream *xdr)
 	if (newbase < xdr->buf->page_len)
 		xdr_set_page_base(xdr, newbase, xdr_stream_remaining(xdr));
 	else
-		xdr_set_iov(xdr, xdr->buf->tail, 0, xdr_stream_remaining(xdr));
+		xdr_set_tail_base(xdr, 0, xdr_stream_remaining(xdr));
 }
 
 static bool xdr_set_next_buffer(struct xdr_stream *xdr)
@@ -1352,7 +1362,7 @@ static void xdr_realign_pages(struct xdr_stream *xdr)
 	if (iov->iov_len > cur) {
 		copied = xdr_shrink_bufhead(buf, cur);
 		trace_rpc_xdr_alignment(xdr, cur, copied);
-		xdr->nwords = XDR_QUADLEN(buf->len - cur);
+		xdr_set_page(xdr, 0, buf->page_len);
 	}
 }
 
@@ -1360,7 +1370,6 @@ static unsigned int xdr_align_pages(struct xdr_stream *xdr, unsigned int len)
 {
 	struct xdr_buf *buf = xdr->buf;
 	unsigned int nwords = XDR_QUADLEN(len);
-	unsigned int cur = xdr_stream_pos(xdr);
 	unsigned int copied;
 
 	if (xdr->nwords == 0)
@@ -1377,7 +1386,6 @@ static unsigned int xdr_align_pages(struct xdr_stream *xdr, unsigned int len)
 		/* Truncate page data and move it into the tail */
 		copied = xdr_shrink_pagelen(buf, len);
 		trace_rpc_xdr_alignment(xdr, len, copied);
-		xdr->nwords = XDR_QUADLEN(buf->len - cur);
 	}
 	return len;
 }
@@ -1403,12 +1411,10 @@ unsigned int xdr_read_pages(struct xdr_stream *xdr, unsigned int len)
 	if (pglen == 0)
 		return 0;
 
-	xdr->nwords -= nwords;
 	base = (nwords << 2) - pglen;
 	end = xdr_stream_remaining(xdr) - pglen;
 
-	if (xdr_set_iov(xdr, xdr->buf->tail, base, end) == 0)
-		xdr->nwords = 0;
+	xdr_set_tail_base(xdr, base, end);
 	return len <= pglen ? len : pglen;
 }
 EXPORT_SYMBOL_GPL(xdr_read_pages);
@@ -1438,15 +1444,13 @@ unsigned int xdr_align_data(struct xdr_stream *xdr, unsigned int offset,
 	/* Move page data to the left */
 	shift = from - offset;
 	xdr_buf_pages_shift_left(buf, from, shift);
-	xdr->buf->len -= shift;
-	xdr->nwords -= XDR_QUADLEN(shift);
 
 	bytes = xdr_stream_remaining(xdr);
 	if (length > bytes)
 		length = bytes;
 	bytes -= length;
 
-	xdr->nwords -= XDR_QUADLEN(length);
+	xdr->buf->len -= shift;
 	xdr_set_page(xdr, offset + length, bytes);
 	return length;
 }
@@ -1467,12 +1471,11 @@ unsigned int xdr_expand_hole(struct xdr_stream *xdr, unsigned int offset,
 		shift = to - from;
 		xdr_buf_try_expand(buf, shift);
 		xdr_buf_pages_shift_right(buf, from, shift);
-		xdr_stream_page_set_pos(xdr, to);
+		xdr_set_page(xdr, to, xdr_stream_remaining(xdr));
 	} else if (to != from)
 		xdr_align_data(xdr, to, 0);
 	xdr_buf_pages_zero(buf, offset, length);
 
-	xdr_set_page(xdr, to, xdr_stream_remaining(xdr));
 	return length;
 }
 EXPORT_SYMBOL_GPL(xdr_expand_hole);
Signature · 1 line
2.29.2
author maintainer
#7 lore raw

PATCH 7/16 SUNRPC: Cleanup - constify a number of xdr_buf helpers

From: Trond Myklebust <[email protected]>

There are a number of xdr helpers for struct xdr_buf that do not change the structure itself. Mark those as taking const pointers for documentation purposes.

---
 include/linux/sunrpc/xdr.h | 22 ++++++++--------
 net/sunrpc/xdr.c           | 53 +++++++++++++++++---------------------
 2 files changed, 35 insertions(+), 40 deletions(-)
include/linux/sunrpc/xdr.h +11 -11
index 178f499e2283..68d49fdc4ee9 100644
@@ -128,8 +128,8 @@ __be32 *xdr_decode_netobj(__be32 *p, struct xdr_netobj *);
 
 void	xdr_inline_pages(struct xdr_buf *, unsigned int,
 			 struct page **, unsigned int, unsigned int);
-void	xdr_terminate_string(struct xdr_buf *, const u32);
-size_t	xdr_buf_pagecount(struct xdr_buf *buf);
+void	xdr_terminate_string(const struct xdr_buf *, const u32);
+size_t	xdr_buf_pagecount(const struct xdr_buf *buf);
 int	xdr_alloc_bvec(struct xdr_buf *buf, gfp_t gfp);
 void	xdr_free_bvec(struct xdr_buf *buf);
 
@@ -182,14 +182,14 @@ xdr_adjust_iovec(struct kvec *iov, __be32 *p)
  * XDR buffer helper functions
  */
 extern void xdr_shift_buf(struct xdr_buf *, size_t);
-extern void xdr_buf_from_iov(struct kvec *, struct xdr_buf *);
-extern int xdr_buf_subsegment(struct xdr_buf *, struct xdr_buf *, unsigned int, unsigned int);
+extern void xdr_buf_from_iov(const struct kvec *, struct xdr_buf *);
+extern int xdr_buf_subsegment(const struct xdr_buf *, struct xdr_buf *, unsigned int, unsigned int);
 extern void xdr_buf_trim(struct xdr_buf *, unsigned int);
-extern int read_bytes_from_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int);
-extern int write_bytes_to_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int);
+extern int read_bytes_from_xdr_buf(const struct xdr_buf *, unsigned int, void *, unsigned int);
+extern int write_bytes_to_xdr_buf(const struct xdr_buf *, unsigned int, void *, unsigned int);
 
-extern int xdr_encode_word(struct xdr_buf *, unsigned int, u32);
-extern int xdr_decode_word(struct xdr_buf *, unsigned int, u32 *);
+extern int xdr_encode_word(const struct xdr_buf *, unsigned int, u32);
+extern int xdr_decode_word(const struct xdr_buf *, unsigned int, u32 *);
 
 struct xdr_array2_desc;
 typedef int (*xdr_xcode_elem_t)(struct xdr_array2_desc *desc, void *elem);
@@ -200,9 +200,9 @@ struct xdr_array2_desc {
 	xdr_xcode_elem_t xcode;
 };
 
-extern int xdr_decode_array2(struct xdr_buf *buf, unsigned int base,
+extern int xdr_decode_array2(const struct xdr_buf *buf, unsigned int base,
 			     struct xdr_array2_desc *desc);
-extern int xdr_encode_array2(struct xdr_buf *buf, unsigned int base,
+extern int xdr_encode_array2(const struct xdr_buf *buf, unsigned int base,
 			     struct xdr_array2_desc *desc);
 extern void _copy_from_pages(char *p, struct page **pages, size_t pgbase,
 			     size_t len);
@@ -251,7 +251,7 @@ extern void xdr_set_scratch_buffer(struct xdr_stream *xdr, void *buf, size_t buf
 extern __be32 *xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes);
 extern unsigned int xdr_read_pages(struct xdr_stream *xdr, unsigned int len);
 extern void xdr_enter_page(struct xdr_stream *xdr, unsigned int len);
-extern int xdr_process_buf(struct xdr_buf *buf, unsigned int offset, unsigned int len, int (*actor)(struct scatterlist *, void *), void *data);
+extern int xdr_process_buf(const struct xdr_buf *buf, unsigned int offset, unsigned int len, int (*actor)(struct scatterlist *, void *), void *data);
 extern unsigned int xdr_align_data(struct xdr_stream *, unsigned int offset, unsigned int length);
 extern unsigned int xdr_expand_hole(struct xdr_stream *, unsigned int offset, unsigned int length);
 
net/sunrpc/xdr.c +24 -29

137 lines not on this page · raw message

Signature · 1 line
2.29.2
author maintainer
#8 lore raw

PATCH 8/16 SUNRPC: Avoid unnecessary copies in xdr_buf_pages_copy_left/right()

From: Trond Myklebust <[email protected]>

Moving data in the XDR page arrays can be expensive, since it can involve touching up to a megabyte of data. Try to avoid doing so for the case where the server returned less data than we preallocated.

---
 net/sunrpc/xdr.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
net/sunrpc/xdr.c +12 -4
index 7ca6208e7623..86a48c4cdcfc 100644
@@ -600,14 +600,20 @@ static void xdr_buf_tail_shift_right(const struct xdr_buf *buf,
 static void xdr_buf_pages_shift_right(const struct xdr_buf *buf,
 				      unsigned int base, unsigned int shift)
 {
+	struct xdr_buf subbuf;
+
 	if (!shift)
 		return;
 	if (base >= buf->page_len) {
 		xdr_buf_tail_shift_right(buf, base - buf->page_len, shift);
 		return;
 	}
-	xdr_buf_tail_shift_right(buf, 0, shift);
-	xdr_buf_pages_copy_right(buf, base, shift);
+	base += buf->head->iov_len;
+	if (base >= buf->len)
+		return;
+	xdr_buf_subsegment(buf, &subbuf, base, buf->len - base);
+	xdr_buf_tail_shift_right(&subbuf, 0, shift);
+	xdr_buf_pages_copy_right(&subbuf, 0, shift);
 }
 
 static void xdr_buf_head_shift_right(const struct xdr_buf *buf,
@@ -710,14 +716,16 @@ static void xdr_buf_tail_shift_left(const struct xdr_buf *buf,
 static void xdr_buf_pages_shift_left(const struct xdr_buf *buf,
 				     unsigned int base, unsigned int shift)
 {
+	struct xdr_buf subbuf;
 	if (!shift)
 		return;
 	if (base >= buf->page_len) {
 		xdr_buf_tail_shift_left(buf, base - buf->page_len, shift);
 		return;
 	}
-	xdr_buf_pages_copy_left(buf, base, shift);
-	xdr_buf_tail_shift_left(buf, 0, shift);
+	xdr_buf_subsegment(buf, &subbuf, 0, buf->len);
+	xdr_buf_pages_copy_left(&subbuf, base, shift);
+	xdr_buf_tail_shift_left(&subbuf, 0, shift);
 }
 
 /**
Signature · 1 line
2.29.2
author maintainer
#9 lore raw

PATCH 9/16 NFSv4.2: Ensure we always reset the result->count in decode_read_plus()

From: Trond Myklebust <[email protected]>

---
 fs/nfs/nfs42xdr.c | 1 +
 1 file changed, 1 insertion(+)
fs/nfs/nfs42xdr.c +1 -0
index c0b8fcd266c9..1c21db640f4d 100644
@@ -1087,6 +1087,7 @@ static int decode_read_plus(struct xdr_stream *xdr, struct nfs_pgio_res *res)
 	if (unlikely(!p))
 		return -EIO;
 
+	res->count = 0;
 	eof = be32_to_cpup(p++);
 	segments = be32_to_cpup(p++);
 	if (segments == 0)
Signature · 1 line
2.29.2
author maintainer
#10 lore raw

PATCH 10/16 NFSv4.2: decode_read_plus_data() must skip padding after data segment

From: Trond Myklebust <[email protected]>

All XDR opaque object sizes are 32-bit aligned, and a data segment is no exception.

---
 fs/nfs/nfs42xdr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/nfs/nfs42xdr.c +3 -1
index 1c21db640f4d..4c6bce3dbaeb 100644
@@ -1038,7 +1038,9 @@ static int decode_read_plus_data(struct xdr_stream *xdr, struct nfs_pgio_res *re
 
 	p = xdr_decode_hyper(p, &offset);
 	count = be32_to_cpup(p);
-	recvd = xdr_align_data(xdr, res->count, count);
+	recvd = xdr_align_data(xdr, res->count, xdr_align_size(count));
+	if (recvd > count)
+		recvd = count;
 	res->count += recvd;
 
 	if (count > recvd) {
Signature · 1 line
2.29.2
author maintainer
#11 lore raw

PATCH 11/16 NFSv4.2: decode_read_plus_hole() needs to check the extent offset

From: Trond Myklebust <[email protected]>

The server is allowed to return a hole extent with an offset that starts before the offset supplied in the READ_PLUS argument. Ensure that we support that case too.

---
 fs/nfs/nfs42xdr.c | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
fs/nfs/nfs42xdr.c +21 -3
index 4c6bce3dbaeb..f9faa131a4f5 100644
@@ -1053,8 +1053,9 @@ static int decode_read_plus_data(struct xdr_stream *xdr, struct nfs_pgio_res *re
 	return 0;
 }
 
-static int decode_read_plus_hole(struct xdr_stream *xdr, struct nfs_pgio_res *res,
-				 uint32_t *eof)
+static int decode_read_plus_hole(struct xdr_stream *xdr,
+				 struct nfs_pgio_args *args,
+				 struct nfs_pgio_res *res, uint32_t *eof)
 {
 	uint64_t offset, length, recvd;
 	__be32 *p;
@@ -1065,6 +1066,20 @@ static int decode_read_plus_hole(struct xdr_stream *xdr, struct nfs_pgio_res *re
 
 	p = xdr_decode_hyper(p, &offset);
 	p = xdr_decode_hyper(p, &length);
+	if (offset != args->offset + res->count) {
+		/* Server returned an out-of-sequence extent */
+		if (offset > args->offset + res->count ||
+		    offset + length < args->offset + res->count) {
+			dprintk("NFS: server returned out of sequence extent: "
+				"offset/size = %llu/%llu != expected %llu\n",
+				(unsigned long long)offset,
+				(unsigned long long)length,
+				(unsigned long long)(args->offset +
+						     res->count));
+			return 1;
+		}
+		length -= args->offset + res->count - offset;
+	}
 	recvd = xdr_expand_hole(xdr, res->count, length);
 	res->count += recvd;
 
@@ -1077,6 +1092,9 @@ static int decode_read_plus_hole(struct xdr_stream *xdr, struct nfs_pgio_res *re
 
 static int decode_read_plus(struct xdr_stream *xdr, struct nfs_pgio_res *res)
 {
+	struct nfs_pgio_header *hdr =
+		container_of(res, struct nfs_pgio_header, res);
+	struct nfs_pgio_args *args = &hdr->args;
 	uint32_t eof, segments, type;
 	int status, i;
 	__be32 *p;
@@ -1104,7 +1122,7 @@ static int decode_read_plus(struct xdr_stream *xdr, struct nfs_pgio_res *res)
 		if (type == NFS4_CONTENT_DATA)
 			status = decode_read_plus_data(xdr, res, &eof);
 		else if (type == NFS4_CONTENT_HOLE)
-			status = decode_read_plus_hole(xdr, res, &eof);
+			status = decode_read_plus_hole(xdr, args, res, &eof);
 		else
 			return -EINVAL;
 
Signature · 1 line
2.29.2
author maintainer
#12 lore raw

PATCH 12/16 NFSv4.2: Handle hole lengths that exceed the READ_PLUS read buffer

From: Trond Myklebust <[email protected]>

If a hole extends beyond the READ_PLUS read buffer, then we want to fill just the remaining buffer with zeros. Also ignore eof...

---
 fs/nfs/nfs42xdr.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/nfs/nfs42xdr.c +6 -0
index f9faa131a4f5..6ba2a28e7e03 100644
@@ -1080,6 +1080,12 @@ static int decode_read_plus_hole(struct xdr_stream *xdr,
 		}
 		length -= args->offset + res->count - offset;
 	}
+	if (length + res->count > args->count) {
+		*eof = 0;
+		if (unlikely(res->count >= args->count))
+			return 1;
+		length = args->count - res->count;
+	}
 	recvd = xdr_expand_hole(xdr, res->count, length);
 	res->count += recvd;
 
Signature · 1 line
2.29.2
author maintainer
#13 lore raw

PATCH 13/16 NFSv4.2: Don't error when exiting early on a READ_PLUS buffer overflow

From: Trond Myklebust <[email protected]>

Expanding the READ_PLUS extents can cause the read buffer to overflow. If it does, then don't error, but just exit early.

---
 fs/nfs/nfs42xdr.c | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)
fs/nfs/nfs42xdr.c +17 -19
index 6ba2a28e7e03..9ef5261a1a70 100644
@@ -1025,16 +1025,16 @@ static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *re
 	return decode_op_hdr(xdr, OP_DEALLOCATE);
 }
 
-static int decode_read_plus_data(struct xdr_stream *xdr, struct nfs_pgio_res *res,
-				 uint32_t *eof)
+static int decode_read_plus_data(struct xdr_stream *xdr,
+				 struct nfs_pgio_res *res)
 {
 	uint32_t count, recvd;
 	uint64_t offset;
 	__be32 *p;
 
 	p = xdr_inline_decode(xdr, 8 + 4);
-	if (unlikely(!p))
-		return -EIO;
+	if (!p)
+		return 1;
 
 	p = xdr_decode_hyper(p, &offset);
 	count = be32_to_cpup(p);
@@ -1043,13 +1043,8 @@ static int decode_read_plus_data(struct xdr_stream *xdr, struct nfs_pgio_res *re
 		recvd = count;
 	res->count += recvd;
 
-	if (count > recvd) {
-		dprintk("NFS: server cheating in read reply: "
-				"count %u > recvd %u\n", count, recvd);
-		*eof = 0;
+	if (count > recvd)
 		return 1;
-	}
-
 	return 0;
 }
 
@@ -1061,8 +1056,8 @@ static int decode_read_plus_hole(struct xdr_stream *xdr,
 	__be32 *p;
 
 	p = xdr_inline_decode(xdr, 8 + 8);
-	if (unlikely(!p))
-		return -EIO;
+	if (!p)
+		return 1;
 
 	p = xdr_decode_hyper(p, &offset);
 	p = xdr_decode_hyper(p, &length);
@@ -1089,10 +1084,8 @@ static int decode_read_plus_hole(struct xdr_stream *xdr,
 	recvd = xdr_expand_hole(xdr, res->count, length);
 	res->count += recvd;
 
-	if (recvd < length) {
-		*eof = 0;
+	if (recvd < length)
 		return 1;
-	}
 	return 0;
 }
 
@@ -1121,12 +1114,12 @@ static int decode_read_plus(struct xdr_stream *xdr, struct nfs_pgio_res *res)
 
 	for (i = 0; i < segments; i++) {
 		p = xdr_inline_decode(xdr, 4);
-		if (unlikely(!p))
-			return -EIO;
+		if (!p)
+			goto early_out;
 
 		type = be32_to_cpup(p++);
 		if (type == NFS4_CONTENT_DATA)
-			status = decode_read_plus_data(xdr, res, &eof);
+			status = decode_read_plus_data(xdr, res);
 		else if (type == NFS4_CONTENT_HOLE)
 			status = decode_read_plus_hole(xdr, args, res, &eof);
 		else
@@ -1135,12 +1128,17 @@ static int decode_read_plus(struct xdr_stream *xdr, struct nfs_pgio_res *res)
 		if (status < 0)
 			return status;
 		if (status > 0)
-			break;
+			goto early_out;
 	}
 
 out:
 	res->eof = eof;
 	return 0;
+early_out:
+	if (unlikely(!i))
+		return -EIO;
+	res->eof = 0;
+	return 0;
 }
 
 static int decode_seek(struct xdr_stream *xdr, struct nfs42_seek_res *res)
Signature · 1 line
2.29.2
author maintainer
#14 lore raw

PATCH 14/16 NFSv4.2: Deal with potential READ_PLUS data extent buffer overflow

From: Trond Myklebust <[email protected]>

If the server returns more data than we have buffer space for, then we need to truncate and exit early.

---
 fs/nfs/nfs42xdr.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
fs/nfs/nfs42xdr.c +7 -2
index 9ef5261a1a70..8386ca45a43f 100644
@@ -1026,6 +1026,7 @@ static int decode_deallocate(struct xdr_stream *xdr, struct nfs42_falloc_res *re
 }
 
 static int decode_read_plus_data(struct xdr_stream *xdr,
+				 struct nfs_pgio_args *args,
 				 struct nfs_pgio_res *res)
 {
 	uint32_t count, recvd;
@@ -1041,8 +1042,12 @@ static int decode_read_plus_data(struct xdr_stream *xdr,
 	recvd = xdr_align_data(xdr, res->count, xdr_align_size(count));
 	if (recvd > count)
 		recvd = count;
+	if (res->count + recvd > args->count) {
+		if (args->count > res->count)
+			res->count += args->count - res->count;
+		return 1;
+	}
 	res->count += recvd;
-
 	if (count > recvd)
 		return 1;
 	return 0;
@@ -1119,7 +1124,7 @@ static int decode_read_plus(struct xdr_stream *xdr, struct nfs_pgio_res *res)
 
 		type = be32_to_cpup(p++);
 		if (type == NFS4_CONTENT_DATA)
-			status = decode_read_plus_data(xdr, res);
+			status = decode_read_plus_data(xdr, args, res);
 		else if (type == NFS4_CONTENT_HOLE)
 			status = decode_read_plus_hole(xdr, args, res, &eof);
 		else
Signature · 1 line
2.29.2
author maintainer
#15 lore raw

PATCH 15/16 nfsd: Fixes for nfsd4_encode_read_plus_data()

From: Trond Myklebust <[email protected]>

Ensure that we encode the data payload + padding, and that we truncate the preallocated buffer to the actual read size.

---
 fs/nfsd/nfs4xdr.c | 5 +++++
 1 file changed, 5 insertions(+)
fs/nfsd/nfs4xdr.c +5 -0
index 833a2c64dfe8..26f6e277101d 100644
@@ -4632,6 +4632,7 @@ nfsd4_encode_read_plus_data(struct nfsd4_compoundres *resp,
 			    resp->rqstp->rq_vec, read->rd_vlen, maxcount, eof);
 	if (nfserr)
 		return nfserr;
+	xdr_truncate_encode(xdr, starting_len + 16 + xdr_align_size(*maxcount));
 
 	tmp = htonl(NFS4_CONTENT_DATA);
 	write_bytes_to_xdr_buf(xdr->buf, starting_len,      &tmp,   4);
@@ -4639,6 +4640,10 @@ nfsd4_encode_read_plus_data(struct nfsd4_compoundres *resp,
 	write_bytes_to_xdr_buf(xdr->buf, starting_len + 4,  &tmp64, 8);
 	tmp = htonl(*maxcount);
 	write_bytes_to_xdr_buf(xdr->buf, starting_len + 12, &tmp,   4);
+
+	tmp = xdr_zero;
+	write_bytes_to_xdr_buf(xdr->buf, starting_len + 16 + *maxcount, &tmp,
+			       xdr_pad_size(*maxcount));
 	return nfs_ok;
 }
 
Signature · 1 line
2.29.2
author maintainer
#16 lore raw

PATCH 16/16 nfsd: Don't set eof on a truncated READ_PLUS

From: Trond Myklebust <[email protected]>

If the READ_PLUS operation was truncated due to an error, then ensure we clear the 'eof' flag.

---
 fs/nfsd/nfs4xdr.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
fs/nfsd/nfs4xdr.c +5 -4
index 26f6e277101d..5f5169b9c2e9 100644
@@ -4736,14 +4736,15 @@ nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr,
 	if (nfserr && segments == 0)
 		xdr_truncate_encode(xdr, starting_len);
 	else {
-		tmp = htonl(eof);
-		write_bytes_to_xdr_buf(xdr->buf, starting_len,     &tmp, 4);
-		tmp = htonl(segments);
-		write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4);
 		if (nfserr) {
 			xdr_truncate_encode(xdr, last_segment);
 			nfserr = nfs_ok;
+			eof = 0;
 		}
+		tmp = htonl(eof);
+		write_bytes_to_xdr_buf(xdr->buf, starting_len,     &tmp, 4);
+		tmp = htonl(segments);
+		write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4);
 	}
 
 	return nfserr;
Signature · 1 line
2.29.2
#17 lore raw

Re: [PATCH 15/16] nfsd: Fixes for nfsd4_encode_read_plus_data()

In reply to [email protected]

Hey-

Quoted 6 lines · On Dec 9, 2020, at 9:48 AM, [email protected] wrote:

From: Trond Myklebust <[email protected]>

Ensure that we encode the data payload + padding, and that we truncate the preallocated buffer to the actual read size.

Did you intend to merge 15/16 and 16/16 through your tree?

Can the patch descriptions say a little more about why these changes are necessary? If they fix a misbehavior, describe the problem.

Quoted 31 lines

---
fs/nfsd/nfs4xdr.c | 5 +++++

1 file changed, 5 insertions(+)
fs/nfsd/nfs4xdr.c +5 -0
index 833a2c64dfe8..26f6e277101d 100644
@@ -4632,6 +4632,7 @@ nfsd4_encode_read_plus_data(struct nfsd4_compoundres *resp,
 			    resp->rqstp->rq_vec, read->rd_vlen, maxcount, eof);
 	if (nfserr)
 		return nfserr;
+	xdr_truncate_encode(xdr, starting_len + 16 + xdr_align_size(*maxcount));
 
 	tmp = htonl(NFS4_CONTENT_DATA);
 	write_bytes_to_xdr_buf(xdr->buf, starting_len,      &tmp,   4);
@@ -4639,6 +4640,10 @@ nfsd4_encode_read_plus_data(struct nfsd4_compoundres *resp,
 	write_bytes_to_xdr_buf(xdr->buf, starting_len + 4,  &tmp64, 8);
 	tmp = htonl(*maxcount);
 	write_bytes_to_xdr_buf(xdr->buf, starting_len + 12, &tmp,   4);
+
+	tmp = xdr_zero;
+	write_bytes_to_xdr_buf(xdr->buf, starting_len + 16 + *maxcount, &tmp,
+			       xdr_pad_size(*maxcount));
 	return nfs_ok;
 }
 
Signature · 1 line
2.29.2

--
Chuck Lever
[email protected]

#18 lore raw

Re: [PATCH 15/16] nfsd: Fixes for nfsd4_encode_read_plus_data()

Quoted 11 lines · Chuck Lever

Hey-

Quoted 7 lines · On Dec 9, 2020, at 9:48 AM, [email protected] wrote:

From: Trond Myklebust <[email protected]>

Ensure that we encode the data payload + padding, and that we truncate
the preallocated buffer to the actual read size.

Did you intend to merge 15/16 and 16/16 through your tree?

No. They can go through the nfsd tree. I included them here because they are necessary in order to pass the xfstests.

Quoted 3 lines

Can the patch descriptions say a little more about why these changes are necessary? If they fix a misbehavior, describe the problem.

It's the same problem and solution that exists in the READ code.

nfsd_readv() doesn't necessarily return the same number of bytes that we requested and preallocated buffer space for. So to deal with that, we have to truncate the preallocated buffer.

Finally, we have to write zeros into the padding bytes after the read buffer.

Quoted 35 lines
Quoted 35 lines

---
fs/nfsd/nfs4xdr.c | 5 +++++

1 file changed, 5 insertions(+)
fs/nfsd/nfs4xdr.c +1 -0
index 833a2c64dfe8..26f6e277101d 100644
@@ -4632,6 +4632,7 @@ nfsd4_encode_read_plus_data(struct
 nfsd4_compoundres *resp,
                             resp->rqstp->rq_vec, read->rd_vlen,
 maxcount, eof);
         if (nfserr)
                 return nfserr;
+       xdr_truncate_encode(xdr, starting_len + 16 +
 xdr_align_size(*maxcount));

        tmp = htonl(NFS4_CONTENT_DATA); write_bytes_to_xdr_buf(xdr->buf, starting_len,      &tmp, 4);

fs/nfsd/nfs4xdr.c +3 -0
@@ -4639,6 +4640,10 @@ nfsd4_encode_read_plus_data(struct
 nfsd4_compoundres *resp,
         write_bytes_to_xdr_buf(xdr->buf, starting_len + 4,  &tmp64,
 8);
         tmp = htonl(*maxcount);
         write_bytes_to_xdr_buf(xdr->buf, starting_len + 12, &tmp,  
 4);
+
+       tmp = xdr_zero;
+       write_bytes_to_xdr_buf(xdr->buf, starting_len + 16 +

*maxcount, &tmp,
+                              xdr_pad_size(*maxcount)); return nfs_ok;
}

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]
#19 lore raw

Re: [PATCH 15/16] nfsd: Fixes for nfsd4_encode_read_plus_data()

Quoted 11 lines · Trond Myklebust
Quoted 6 lines · Chuck Lever

Hey-

Quoted 4 lines · On Dec 9, 2020, at 9:48 AM, [email protected] wrote:

From: Trond Myklebust <[email protected]>

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Ensure that we encode the data payload + padding, and that we truncate
the preallocated buffer to the actual read size.

Did you intend to merge 15/16 and 16/16 through your tree?

No. They can go through the nfsd tree. I included them here because they are necessary in order to pass the xfstests.

Would it be OK if they went in 5.11-rc? I've got the initial merge tag prepared already. If they can't wait, let me know.

Quoted 9 lines
Quoted 3 lines

Can the patch descriptions say a little more about why these changes are necessary? If they fix a misbehavior, describe the problem.

It's the same problem and solution that exists in the READ code.

nfsd_readv() doesn't necessarily return the same number of bytes that we requested and preallocated buffer space for. So to deal with that, we have to truncate the preallocated buffer.

Huh. I thought it was doing that already? Oh, that's just for the cases where the server returns an error status. The READ_PLUS encoder incorrectly does not do that truncation for short READs... got it.

Quoted 2 lines

Finally, we have to write zeros into the padding bytes after the read buffer.

Right. Then the problem statement is that the server's READ_PLUS XDR encoder isn't padding the read buffer properly.

Quibble: perhaps these are two separate issues that each deserve their own patches with Fixes: tags (and if you re-post these, please add a Fixes: tag to 16/16 too).

Thanks!

Quoted 27 lines
Quoted 27 lines
Quoted 27 lines

---
fs/nfsd/nfs4xdr.c | 5 +++++

1 file changed, 5 insertions(+)
fs/nfsd/nfs4xdr.c +1 -0
index 833a2c64dfe8..26f6e277101d 100644
@@ -4632,6 +4632,7 @@ nfsd4_encode_read_plus_data(struct
 nfsd4_compoundres *resp,
                            resp->rqstp->rq_vec, read->rd_vlen,
 maxcount, eof);
        if (nfserr)
                return nfserr;
+       xdr_truncate_encode(xdr, starting_len + 16 +
 xdr_align_size(*maxcount));
        tmp = htonl(NFS4_CONTENT_DATA);
        write_bytes_to_xdr_buf(xdr->buf, starting_len,      &tmp,  

4);

fs/nfsd/nfs4xdr.c +0 -0
@@ -4639,6 +4640,10 @@ nfsd4_encode_read_plus_data(struct
 nfsd4_compoundres *resp,
        write_bytes_to_xdr_buf(xdr->buf, starting_len + 4,  &tmp64,
 8);
        tmp = htonl(*maxcount);
        write_bytes_to_xdr_buf(xdr->buf, starting_len + 12, &tmp,  
Quoted 13 lines
Quoted 8 lines
Quoted 8 lines
fs/nfsd/nfs4xdr.c +3 -0
 4);
+
+       tmp = xdr_zero;
+       write_bytes_to_xdr_buf(xdr->buf, starting_len + 16 +

*maxcount, &tmp,

+                              xdr_pad_size(*maxcount));
        return nfs_ok;
}
Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]

--
Chuck Lever
[email protected]

#20 lore raw

Re: [PATCH 15/16] nfsd: Fixes for nfsd4_encode_read_plus_data()

Quoted 16 lines · Chuck Lever
Quoted 16 lines

On Dec 9, 2020, at 11:39 AM, Trond Myklebust <
[email protected]> wrote:

Quoted 10 lines · Chuck Lever

Hey-

Quoted 7 lines · On Dec 9, 2020, at 9:48 AM, [email protected] wrote:

From: Trond Myklebust <[email protected]>

Ensure that we encode the data payload + padding, and that we truncate
the preallocated buffer to the actual read size.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Did you intend to merge 15/16 and 16/16 through your tree?

No. They can go through the nfsd tree. I included them here because they are necessary in order to pass the xfstests.

Would it be OK if they went in 5.11-rc? I've got the initial merge tag prepared already. If they can't wait, let me know.

I'm fine with that.

Quoted 24 lines
Quoted 6 lines
Quoted 5 lines

Can the patch descriptions say a little more about why these changes are necessary? If they fix a misbehavior, describe the problem.

Quoted 7 lines

It's the same problem and solution that exists in the READ code.

nfsd_readv() doesn't necessarily return the same number of bytes that
we requested and preallocated buffer space for. So to deal with that,
we have to truncate the preallocated buffer.

Huh. I thought it was doing that already? Oh, that's just for the cases where the server returns an error status. The READ_PLUS encoder incorrectly does not do that truncation for short READs... got it.

Quoted 3 lines

Finally, we have to write zeros into the padding bytes after the read
buffer.

Quoted 6 lines

Right. Then the problem statement is that the server's READ_PLUS XDR encoder isn't padding the read buffer properly.

Quibble: perhaps these are two separate issues that each deserve their own patches with Fixes: tags (and if you re-post these, please add a Fixes: tag to 16/16 too).

I'm not planning on reposting.

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]