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