Skip to content

Commit c569061

Browse files
[Medium] Patch nbdkit for CVE-2025-47711 & CVE-2025-47712
1 parent 24ea47e commit c569061

File tree

3 files changed

+269
-1
lines changed

3 files changed

+269
-1
lines changed

SPECS/nbdkit/CVE-2025-47711.patch

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
From 9457616cacdb044aa1773d7a931cdfeea77b1057 Mon Sep 17 00:00:00 2001
2+
From: dj_palli <v-dpalli@microsoft.com>
3+
Date: Wed, 18 Jun 2025 14:40:17 +0000
4+
Subject: [PATCH] Address CVE-2025-47711
5+
6+
---
7+
server/protocol.c | 2 +-
8+
tests/Makefile.am | 2 ++
9+
tests/test-eval-extents.sh | 71 ++++++++++++++++++++++++++++++++++++++
10+
3 files changed, 74 insertions(+), 1 deletion(-)
11+
create mode 100644 tests/test-eval-extents.sh
12+
13+
diff --git a/server/protocol.c b/server/protocol.c
14+
index d9a5e28..c32fec8 100644
15+
--- a/server/protocol.c
16+
+++ b/server/protocol.c
17+
@@ -493,7 +493,7 @@ extents_to_block_descriptors (struct nbdkit_extents *extents,
18+
(*nr_blocks)++;
19+
20+
pos += length;
21+
- if (pos > offset + count) /* this must be the last block */
22+
+ if (pos >= offset + count) /* this must be the last block */
23+
break;
24+
25+
/* If we reach here then we must have consumed this whole
26+
diff --git a/tests/Makefile.am b/tests/Makefile.am
27+
index 9233c37..a1905c9 100644
28+
--- a/tests/Makefile.am
29+
+++ b/tests/Makefile.am
30+
@@ -781,6 +781,7 @@ TESTS += \
31+
test-eval.sh \
32+
test-eval-file.sh \
33+
test-eval-exports.sh \
34+
+ test-eval-extents.sh \
35+
test-eval-cache.sh \
36+
test-eval-dump-plugin.sh \
37+
test-eval-disconnect.sh \
38+
@@ -789,6 +790,7 @@ EXTRA_DIST += \
39+
test-eval.sh \
40+
test-eval-file.sh \
41+
test-eval-exports.sh \
42+
+ test-eval-extents.sh \
43+
test-eval-cache.sh \
44+
test-eval-dump-plugin.sh \
45+
test-eval-disconnect.sh \
46+
diff --git a/tests/test-eval-extents.sh b/tests/test-eval-extents.sh
47+
new file mode 100644
48+
index 0000000..92b503e
49+
--- /dev/null
50+
+++ b/tests/test-eval-extents.sh
51+
@@ -0,0 +1,71 @@
52+
+#!/usr/bin/env bash
53+
+# nbdkit
54+
+# Copyright Red Hat
55+
+#
56+
+# Redistribution and use in source and binary forms, with or without
57+
+# modification, are permitted provided that the following conditions are
58+
+# met:
59+
+#
60+
+# * Redistributions of source code must retain the above copyright
61+
+# notice, this list of conditions and the following disclaimer.
62+
+#
63+
+# * Redistributions in binary form must reproduce the above copyright
64+
+# notice, this list of conditions and the following disclaimer in the
65+
+# documentation and/or other materials provided with the distribution.
66+
+#
67+
+# * Neither the name of Red Hat nor the names of its contributors may be
68+
+# used to endorse or promote products derived from this software without
69+
+# specific prior written permission.
70+
+#
71+
+# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
72+
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
73+
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
74+
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
75+
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
76+
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
77+
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
78+
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
79+
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
80+
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
81+
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
82+
+# SUCH DAMAGE.
83+
+
84+
+source ./functions.sh
85+
+set -e
86+
+set -x
87+
+
88+
+requires_run
89+
+requires_plugin eval
90+
+requires_nbdsh_uri
91+
+requires nbdsh --base-allocation --version
92+
+
93+
+files="eval-extents.out"
94+
+rm -f $files
95+
+cleanup_fn rm -f $files
96+
+
97+
+# Trigger an off-by-one bug introduced in v1.11.10 and fixed in v1.43.7
98+
+export script='
99+
+def f(context, offset, extents, status):
100+
+ print(extents)
101+
+
102+
+# First, probe where the server should return 2 extents.
103+
+h.block_status(2**32-1, 2, f)
104+
+
105+
+# Next, probe where the server has exactly 2**32-1 bytes in its first extent.
106+
+h.block_status(2**32-1, 1, f)
107+
+
108+
+# Now, probe where the first extent has to be truncated.
109+
+h.block_status(2**32-1, 0, f)
110+
+'
111+
+nbdkit eval \
112+
+ get_size='echo 5G' \
113+
+ pread='dd if=/dev/zero count=$3 iflag=count_bytes' \
114+
+ extents='echo 0 4G 1; echo 4G 1G 2' \
115+
+ --run 'nbdsh --base-allocation --uri "$uri" -c "$script"' \
116+
+ > eval-extents.out
117+
+cat eval-extents.out
118+
+diff -u - eval-extents.out <<EOF
119+
+[4294967294, 1, 1073741824, 2]
120+
+[4294967295, 1]
121+
+[4294967295, 1]
122+
+EOF
123+
--
124+
2.45.2
125+

SPECS/nbdkit/CVE-2025-47712.patch

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
From 93e521b7d705202335c4147218181b0bdd1e7cb0 Mon Sep 17 00:00:00 2001
2+
From: dj_palli <v-dpalli@microsoft.com>
3+
Date: Wed, 18 Jun 2025 16:11:18 +0000
4+
Subject: [PATCH] Address CVE-2025-47712
5+
6+
---
7+
filters/blocksize/blocksize.c | 3 +-
8+
tests/Makefile.am | 2 +
9+
tests/test-blocksize-extents-overflow.sh | 83 ++++++++++++++++++++++++
10+
3 files changed, 87 insertions(+), 1 deletion(-)
11+
create mode 100644 tests/test-blocksize-extents-overflow.sh
12+
13+
diff --git a/filters/blocksize/blocksize.c b/filters/blocksize/blocksize.c
14+
index 09195ce..d3fcb4b 100644
15+
--- a/filters/blocksize/blocksize.c
16+
+++ b/filters/blocksize/blocksize.c
17+
@@ -482,7 +482,8 @@ blocksize_extents (nbdkit_next *next,
18+
return -1;
19+
}
20+
21+
- if (nbdkit_extents_aligned (next, MIN (ROUND_UP (count, h->minblock),
22+
+ if (nbdkit_extents_aligned (next,
23+
+ MIN (ROUND_UP ((uint64_t) count, h->minblock),
24+
h->maxlen),
25+
ROUND_DOWN (offset, h->minblock), flags,
26+
h->minblock, extents2, err) == -1)
27+
diff --git a/tests/Makefile.am b/tests/Makefile.am
28+
index a1905c9..dc8445f 100644
29+
--- a/tests/Makefile.am
30+
+++ b/tests/Makefile.am
31+
@@ -1483,12 +1483,14 @@ test_layers_filter3_la_LIBADD = $(IMPORT_LIBRARY_ON_WINDOWS)
32+
TESTS += \
33+
test-blocksize.sh \
34+
test-blocksize-extents.sh \
35+
+ test-blocksize-extents-overflow.sh \
36+
test-blocksize-default.sh \
37+
test-blocksize-sharding.sh \
38+
$(NULL)
39+
EXTRA_DIST += \
40+
test-blocksize.sh \
41+
test-blocksize-extents.sh \
42+
+ test-blocksize-extents-overflow.sh \
43+
test-blocksize-default.sh \
44+
test-blocksize-sharding.sh \
45+
$(NULL)
46+
diff --git a/tests/test-blocksize-extents-overflow.sh b/tests/test-blocksize-extents-overflow.sh
47+
new file mode 100644
48+
index 0000000..844c399
49+
--- /dev/null
50+
+++ b/tests/test-blocksize-extents-overflow.sh
51+
@@ -0,0 +1,83 @@
52+
+#!/usr/bin/env bash
53+
+# nbdkit
54+
+# Copyright Red Hat
55+
+#
56+
+# Redistribution and use in source and binary forms, with or without
57+
+# modification, are permitted provided that the following conditions are
58+
+# met:
59+
+#
60+
+# * Redistributions of source code must retain the above copyright
61+
+# notice, this list of conditions and the following disclaimer.
62+
+#
63+
+# * Redistributions in binary form must reproduce the above copyright
64+
+# notice, this list of conditions and the following disclaimer in the
65+
+# documentation and/or other materials provided with the distribution.
66+
+#
67+
+# * Neither the name of Red Hat nor the names of its contributors may be
68+
+# used to endorse or promote products derived from this software without
69+
+# specific prior written permission.
70+
+#
71+
+# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
72+
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
73+
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
74+
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
75+
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
76+
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
77+
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
78+
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
79+
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
80+
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
81+
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
82+
+# SUCH DAMAGE.
83+
+
84+
+# Demonstrate a fix for a bug where blocksize overflowed 32 bits
85+
+
86+
+source ./functions.sh
87+
+set -e
88+
+set -x
89+
+
90+
+requires_run
91+
+requires_plugin eval
92+
+requires_nbdsh_uri
93+
+requires nbdsh --base-allocation --version
94+
+
95+
+# Script a sparse server that requires 512-byte aligned requests.
96+
+exts='
97+
+if test $(( ($3|$4) & 511 )) != 0; then
98+
+ echo "EINVAL request unaligned" 2>&1
99+
+ exit 1
100+
+fi
101+
+echo 0 5G 0
102+
+'
103+
+
104+
+# We also need an nbdsh script to parse all extents, coalescing adjacent
105+
+# types for simplicity.
106+
+# FIXME: Once nbdkit plugin version 3 allows 64-bit block extents, run
107+
+# this test twice, once for each bit size (32-bit needs 2 extents, 64-bit
108+
+# will get the same result with only 1 extent).
109+
+export script='
110+
+size = h.get_size()
111+
+offs = 0
112+
+entries = []
113+
+def f(metacontext, offset, e, err):
114+
+ global entries
115+
+ global offs
116+
+ assert offs == offset
117+
+ for length, flags in zip(*[iter(e)] * 2):
118+
+ if entries and flags == entries[-1][1]:
119+
+ entries[-1] = (entries[-1][0] + length, flags)
120+
+ else:
121+
+ entries.append((length, flags))
122+
+ offs = offs + length
123+
+
124+
+# Test a loop over the entire device
125+
+while offs < size:
126+
+ len = min(size - offs, 2**32-1)
127+
+ h.block_status(len, offs, f)
128+
+assert entries == [(5 * 2**30, 0)]
129+
+'
130+
+
131+
+# Now run everything
132+
+nbdkit --filter=blocksize eval minblock=512 \
133+
+ get_size='echo 5G' pread='exit 1' extents="$exts" \
134+
+ --run 'nbdsh --base-allocation -u "$uri" -c "$script"'
135+
--
136+
2.45.2
137+

SPECS/nbdkit/nbdkit.spec

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Distribution: Mariner
5151

5252
Name: nbdkit
5353
Version: 1.35.3
54-
Release: 3%{?dist}
54+
Release: 4%{?dist}
5555
Summary: NBD server
5656

5757
License: BSD
@@ -128,6 +128,8 @@ Requires: nbdkit-server%{?_isa} = %{version}-%{release}
128128
Requires: nbdkit-basic-plugins%{?_isa} = %{version}-%{release}
129129
Requires: nbdkit-basic-filters%{?_isa} = %{version}-%{release}
130130

131+
Patch0: CVE-2025-47711.patch
132+
Patch1: CVE-2025-47712.patch
131133

132134
%description
133135
NBD is a protocol for accessing block devices (hard disks and
@@ -1193,6 +1195,10 @@ export LIBGUESTFS_TRACE=1
11931195

11941196

11951197
%changelog
1198+
* Wed Jan 15 2025 Durga Jagadeesh Palli <v-dpalli@microsoft.com> - 1.35.3-4
1199+
- add patch for CVE-2025-47711.patch
1200+
- add patch for CVE-2025-47712.patch
1201+
11961202
* Wed Sep 20 2023 Jon Slobodzian <joslobo@microsoft.com> - 1.35.3-3
11971203
- Recompile with stack-protection fixed gcc version (CVE-2023-4039)
11981204

0 commit comments

Comments
 (0)