From: "Michael J. Ruhl" <michael.j.ruhl-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
To: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH rdma-core v4 3/4] ibacm: Fix a retry loop calculation race condition
Date: Wed, 15 Nov 2017 14:35:18 -0500 [thread overview]
Message-ID: <20171115193507.470.1997.stgit@phlsvslse11.ph.intel.com> (raw)
In-Reply-To: <20171115193155.470.85049.stgit-K+u1se/DcYrLESAwzcoQNrvm/XP+8Wra@public.gmane.org>
From: Michael J. Ruhl <michael.j.ruhl-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
The retry loop calculation uses a conversion to int of an unsigned
64 bit number (next_expire) minus the current time to decide if
event_wait() should be called. This calculation works correctly as
long as the next_expire value is not the default value (-1).
If the next_expire is the default value, periodically this subtraction
can result in a very large postive timeout value (days rather than
milliseconds).
For example:
next_expire = 0xFFFFFFFFFFFFFFFF (-1)
current_ms = 0x15f7db52146 (today's ms since 1970)
max_delay_ms = (int) next_expire - future_ms
future_ms = 0x15f80000000 = max_delay_ms 2147483647
future_ms = 0x16080000000 = max_delay_ms 2147483647
Converting max_delay_ms to days:
2147483647 / 1000 / 60 / 60 / 24 == 24 days
0xxx180000000 - 0xxx080000000 = 4294967296
every 48 days, this issue repeats
This calculation can occur if a wait_cnt is incremented and a message
expiration is handled so that next_expire is not updated. If wait_cnt
is incremented before the wait calculation is done (the race condition),
event_wait() can be called with the potentially very large value.
If next_expire is not updated, do not do the wait calculation and
avoid the race condition.
Reported-by: Morys Grzegorz <grzegorz.morys-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Reviewed-by: Mike Marciniszyn <mike.marciniszyn-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Reviewed-by: Dennis Dalessandro <dennis.dalessandro-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Signed-off-by: Michael J. Ruhl <michael.j.ruhl-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
ibacm/prov/acmp/src/acmp.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/ibacm/prov/acmp/src/acmp.c b/ibacm/prov/acmp/src/acmp.c
index d707b8e..884fc48 100644
--- a/ibacm/prov/acmp/src/acmp.c
+++ b/ibacm/prov/acmp/src/acmp.c
@@ -1579,10 +1579,12 @@ static void *acmp_retry_handler(void *context)
pthread_mutex_unlock(&acmp_dev_lock);
acmp_process_timeouts();
- wait = (int) (next_expire - time_stamp_ms());
- if (wait > 0 && atomic_get(&wait_cnt)) {
- pthread_testcancel();
- event_wait(&timeout_event, wait);
+ if (next_expire != -1) {
+ wait = (int) (next_expire - time_stamp_ms());
+ if (wait > 0 && atomic_get(&wait_cnt)) {
+ pthread_testcancel();
+ event_wait(&timeout_event, wait);
+ }
}
}
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2017-11-15 19:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-15 19:34 [PATCH rdma-core v4 0/4] ibacm: acmp retry issues Michael J. Ruhl
[not found] ` <20171115193155.470.85049.stgit-K+u1se/DcYrLESAwzcoQNrvm/XP+8Wra@public.gmane.org>
2017-11-15 19:34 ` [PATCH rdma-core v4 1/4] ibacm: Fix an incorrect expiration check for the retry timer Michael J. Ruhl
2017-11-15 19:35 ` [PATCH rdma-core v4 2/4] ibacm: Calculate correct tv_nsec value in event_wait() Michael J. Ruhl
2017-11-15 19:35 ` Michael J. Ruhl [this message]
2017-11-15 19:35 ` [PATCH rdma-core v4 4/4] ibacm: Use MONOTONIC time base to avoid timer expiration issues Michael J. Ruhl
[not found] ` <20171115193524.470.17499.stgit-K+u1se/DcYrLESAwzcoQNrvm/XP+8Wra@public.gmane.org>
2017-11-16 12:09 ` Ruhl, Michael J
2017-11-17 0:11 ` [PATCH rdma-core v4 0/4] ibacm: acmp retry issues Jason Gunthorpe
2017-11-20 8:28 ` Leon Romanovsky
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=20171115193507.470.1997.stgit@phlsvslse11.ph.intel.com \
--to=michael.j.ruhl-ral2jqcrhueavxtiumwx3w@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox