From e351b19055ccbc497ed1e5ee7b5d96d042ccbb0d Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Thu, 20 Apr 2023 14:34:25 -0700 Subject: [PATCH] sock/posix: Fix sendmsg_idx rollover for zcopy If the idx gets to UINT32_MAX we need to ensure it doesn't wrap around before we check if we're done iterating. Fixes #2892 Change-Id: I2c57ed2a6f6eda16e2d1faa63e587dca0b380a17 Signed-off-by: Ben Walker Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17687 Reviewed-by: Konrad Sztyber Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins Reviewed-by: Aleksey Marchuk --- module/sock/posix/posix.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/module/sock/posix/posix.c b/module/sock/posix/posix.c index e61e4fae0..ce8b10b8a 100644 --- a/module/sock/posix/posix.c +++ b/module/sock/posix/posix.c @@ -1178,7 +1178,8 @@ _sock_check_zcopy(struct spdk_sock *sock) * we encounter one match we can stop looping as soon as a * non-match is found. */ - for (idx = serr->ee_info; idx <= serr->ee_data; idx++) { + idx = serr->ee_info; + while (true) { found = false; TAILQ_FOREACH_SAFE(req, &sock->pending_reqs, internal.link, treq) { if (!req->internal.is_zcopy) { @@ -1197,6 +1198,16 @@ _sock_check_zcopy(struct spdk_sock *sock) break; } } + + if (idx == serr->ee_data) { + break; + } + + if (idx == UINT32_MAX) { + idx = 0; + } else { + idx++; + } } }