From 18cb979e595e171758565c03d21fc4bba7c917b9 Mon Sep 17 00:00:00 2001 From: Dmitry Savitskiy Date: Thu, 2 Nov 2023 16:05:51 +0300 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. This is a backport from 23.05. Original commit e351b19055ccbc497ed1e5ee7b5d96d042ccbb0d. Signed-off-by: Dmitry Savitskiy --- module/sock/posix/posix.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/module/sock/posix/posix.c b/module/sock/posix/posix.c index 9020540eb6d..2ce596de32f 100644 --- a/module/sock/posix/posix.c +++ b/module/sock/posix/posix.c @@ -686,21 +686,30 @@ _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.offset == idx) { found = true; - rc = spdk_sock_request_put(sock, req, 0); if (rc < 0) { return rc; } - } else if (found) { break; } } + + if (idx == serr->ee_data) { + break; + } + + if (idx == UINT32_MAX) { + idx = 0; + } else { + idx++; + } } }