Skip to content

Commit

Permalink
afs: Fix total-length calculation for multiple-page send
Browse files Browse the repository at this point in the history
[ Upstream commit 1199db6 ]

Fix the total-length calculation in afs_make_call() when the operation
being dispatched has data from a series of pages attached.

Despite the patched code looking like that it should reduce mathematically
to the current code, it doesn't because the 32-bit unsigned arithmetic
being used to calculate the page-offset-difference doesn't correctly extend
to a 64-bit value when the result is effectively negative.

Without this, some FS.StoreData operations that span multiple pages fail,
reporting too little or too much data.

Signed-off-by: David Howells <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
dhowells authored and gregkh committed Dec 14, 2017
1 parent d702be1 commit 49e186e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions fs/afs/rxrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,17 @@ int afs_make_call(struct in_addr *addr, struct afs_call *call, gfp_t gfp,
*/
tx_total_len = call->request_size;
if (call->send_pages) {
tx_total_len += call->last_to - call->first_offset;
tx_total_len += (call->last - call->first) * PAGE_SIZE;
if (call->last == call->first) {
tx_total_len += call->last_to - call->first_offset;
} else {
/* It looks mathematically like you should be able to
* combine the following lines with the ones above, but
* unsigned arithmetic is fun when it wraps...
*/
tx_total_len += PAGE_SIZE - call->first_offset;
tx_total_len += call->last_to;
tx_total_len += (call->last - call->first - 1) * PAGE_SIZE;
}
}

/* create a call */
Expand Down

0 comments on commit 49e186e

Please sign in to comment.