Blame SOURCES/0004-opt_go-Tolerate-unplanned-server-death.patch

a81d13
From ffe8f0a994c1f2656aa011353b386663d32db69e Mon Sep 17 00:00:00 2001
a81d13
From: Eric Blake <eblake@redhat.com>
a81d13
Date: Mon, 1 Mar 2021 15:25:31 -0600
a81d13
Subject: [PATCH] opt_go: Tolerate unplanned server death
a81d13
a81d13
While debugging some experimental nbdkit code that was triggering an
a81d13
assertion failure in nbdkit, I noticed a secondary failure of nbdsh
a81d13
also dying from an assertion:
a81d13
a81d13
libnbd: debug: nbdsh: nbd_opt_go: transition: NEWSTYLE.OPT_GO.SEND -> DEAD
a81d13
libnbd: debug: nbdsh: nbd_opt_go: option queued, ignoring state machine failure
a81d13
nbdsh: opt.c:86: nbd_unlocked_opt_go: Assertion `nbd_internal_is_state_negotiating (get_next_state (h))' failed.
a81d13
a81d13
Although my trigger was from non-production nbdkit code, libnbd should
a81d13
never die from an assertion failure merely because a server
a81d13
disappeared at the wrong moment during an incomplete reply to
a81d13
NBD_OPT_GO or NBD_OPT_INFO.  If this is assigned a CVE, a followup
a81d13
patch will add mention of it in docs/libnbd-security.pod.
a81d13
a81d13
Fixes: bbf1c51392 (api: Give aio_opt_go a completion callback)
a81d13
(cherry picked from commit fb4440de9cc76e9c14bd3ddf3333e78621f40ad0)
a81d13
---
a81d13
 lib/opt.c | 8 +++++---
a81d13
 1 file changed, 5 insertions(+), 3 deletions(-)
a81d13
a81d13
diff --git a/lib/opt.c b/lib/opt.c
a81d13
index 2317b72..e5802f4 100644
a81d13
--- a/lib/opt.c
a81d13
+++ b/lib/opt.c
a81d13
@@ -1,5 +1,5 @@
a81d13
 /* NBD client library in userspace
a81d13
- * Copyright (C) 2020 Red Hat Inc.
a81d13
+ * Copyright (C) 2020-2021 Red Hat Inc.
a81d13
  *
a81d13
  * This library is free software; you can redistribute it and/or
a81d13
  * modify it under the terms of the GNU Lesser General Public
a81d13
@@ -83,7 +83,8 @@ nbd_unlocked_opt_go (struct nbd_handle *h)
a81d13
 
a81d13
   r = wait_for_option (h);
a81d13
   if (r == 0 && err) {
a81d13
-    assert (nbd_internal_is_state_negotiating (get_next_state (h)));
a81d13
+    assert (nbd_internal_is_state_negotiating (get_next_state (h)) ||
a81d13
+            nbd_internal_is_state_dead (get_next_state (h)));
a81d13
     set_error (err, "server replied with error to opt_go request");
a81d13
     return -1;
a81d13
   }
a81d13
@@ -105,7 +106,8 @@ nbd_unlocked_opt_info (struct nbd_handle *h)
a81d13
 
a81d13
   r = wait_for_option (h);
a81d13
   if (r == 0 && err) {
a81d13
-    assert (nbd_internal_is_state_negotiating (get_next_state (h)));
a81d13
+    assert (nbd_internal_is_state_negotiating (get_next_state (h)) ||
a81d13
+            nbd_internal_is_state_dead (get_next_state (h)));
a81d13
     set_error (err, "server replied with error to opt_info request");
a81d13
     return -1;
a81d13
   }
a81d13
-- 
a81d13
2.31.1
a81d13