Rebase to new stable branch version 1.10.1

resolves: rhbz#2011708
This commit is contained in:
Richard W.M. Jones 2021-10-30 14:44:07 +01:00
parent 127efec280
commit f05317d624
4 changed files with 133 additions and 7 deletions

View File

@ -0,0 +1,70 @@
From 0dc8ee268e56fb8b8dcd18fd3483045e65ffc5a2 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 26 Oct 2021 13:40:16 +0100
Subject: [PATCH] python: Fix crash when passing None as a buffer
$ nbdkit -U - null 512 --run 'nbdsh -u $uri -c "h.pwrite(None, 0)"'
nbdkit: external command was killed by signal 11
The stack trace indicated that the code was calling
PyBuffer_Release (&buf) on an uninitialized buffer 'buf'. What was
happening was that PyArg_ParseTuple was recognizing the type error in
the parameter (None is not a buffer-like object) and failing, but it
didn't initialize the Py_buffer parameter so that contained random
stuff from the stack, and then we tried to release it by calling
PyBuffer_Release.
To fix this, initialize the stack buffer, then avoid calling
PyBuffer_Release if the .obj field in the Py_buffer is still NULL
(which should be impossible if PyArg_ParseTuple set the &buf
parameter).
After this commit we see the type error:
$ nbdkit -U - null 512 --run './run nbdsh -u $uri -c "h.pwrite(None, 0)"'
Traceback (most recent call last):
File "/usr/lib64/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib64/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/home/rjones/d/libnbd/python/nbd.py", line 2568, in <module>
nbdsh.shell()
File "/home/rjones/d/libnbd/python/nbdsh.py", line 138, in shell
exec(c, d, d)
File "<string>", line 1, in <module>
File "/home/rjones/d/libnbd/python/nbd.py", line 1610, in pwrite
return libnbdmod.pwrite(self._o, buf, offset, flags)
TypeError: a bytes-like object is required, not 'NoneType'
(cherry picked from commit 51195424f8ba73d0ab1fb4145ddfa81cb8056d4e)
---
generator/Python.ml | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/generator/Python.ml b/generator/Python.ml
index cd12f27..49281bf 100644
--- a/generator/Python.ml
+++ b/generator/Python.ml
@@ -274,7 +274,7 @@ let print_python_binding name { args; optargs; ret; may_set_error } =
function
| Bool n -> pr " int %s;\n" n
| BytesIn (n, _) ->
- pr " Py_buffer %s;\n" n
+ pr " Py_buffer %s = { .obj = NULL };\n" n
| BytesOut (n, count) ->
pr " char *%s = NULL;\n" n;
pr " Py_ssize_t %s;\n" count
@@ -552,7 +552,9 @@ let print_python_binding name { args; optargs; ret; may_set_error } =
List.iter (
function
| Bool _ -> ()
- | BytesIn (n, _) -> pr " PyBuffer_Release (&%s);\n" n
+ | BytesIn (n, _) ->
+ pr " if (%s.obj)\n" n;
+ pr " PyBuffer_Release (&%s);\n" n
| BytesOut (n, _) -> pr " free (%s);\n" n
| BytesPersistIn _ | BytesPersistOut _ -> ()
| Closure { cbname } ->
--
2.31.1

View File

@ -0,0 +1,55 @@
From 48136328150bc587178091b5766bda382158cb6c Mon Sep 17 00:00:00 2001
From: Nir Soffer <nsoffer@redhat.com>
Date: Sat, 23 Oct 2021 00:08:31 +0300
Subject: [PATCH] lib/poll.c: Retry poll after EINTR
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
I see a rare random failure when calling BlockStatus via Go binding:
block_status: nbd_block_status: poll: Interrupted system call
I could not reproduce this with "nbdinfo --map", even after modifying it
to call nbd_block_status() for every 128 MiB.
Fixing this in nbd_unlock_poll() avoids this issue in the entire
library, when we wait for command completion. This seems more useful
that fixing it in all libnbd clients.
Tested using a go client listing all extents in an image, calling
BlockStatus for every 128m with fedora 34 qcow2 image. Without this fix,
this was always failing.
$ hyperfine -r1000 --show-output "./client nbd+unix://?socket=/tmp/nbd.sock > /dev/null"
Benchmark 1: ./client nbd+unix://?socket=/tmp/nbd.sock > /dev/null
Time (mean ± σ): 31.6 ms ± 3.1 ms [User: 8.8 ms, System: 7.2 ms]
Range (min … max): 26.1 ms … 52.3 ms 1000 runs
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
(cherry picked from commit b3440853cdeca0e44ad9c526e71faaa6cf344bfc)
---
lib/poll.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/lib/poll.c b/lib/poll.c
index edfcc59..df01d94 100644
--- a/lib/poll.c
+++ b/lib/poll.c
@@ -57,8 +57,11 @@ nbd_unlocked_poll (struct nbd_handle *h, int timeout)
* would allow other threads to close file descriptors which we have
* passed to poll.
*/
- r = poll (fds, 1, timeout);
- debug (h, "poll end: r=%d revents=%x", r, fds[0].revents);
+ do {
+ r = poll (fds, 1, timeout);
+ debug (h, "poll end: r=%d revents=%x", r, fds[0].revents);
+ } while (r == -1 && errno == EINTR);
+
if (r == -1) {
set_error (errno, "poll");
return -1;
--
2.31.1

View File

@ -2,13 +2,13 @@
%global verify_tarball_signature 1
# If there are patches which touch autotools files, set this to 1.
%global patches_touch_autotools %{nil}
%global patches_touch_autotools 1
# The source directory.
%global source_directory 1.10-stable
Name: libnbd
Version: 1.10.0
Version: 1.10.1
Release: 1%{?dist}
Summary: NBD client library in userspace
@ -29,7 +29,8 @@ Source3: copy-patches.sh
# https://gitlab.com/nbdkit/libnbd/-/commits/rhel-9.0/
# Patches.
# (nothing)
Patch0001: 0001-python-Fix-crash-when-passing-None-as-a-buffer.patch
Patch0002: 0002-lib-poll.c-Retry-poll-after-EINTR.patch
%if 0%{patches_touch_autotools}
BuildRequires: autoconf, automake, libtool
@ -323,8 +324,8 @@ make %{?_smp_mflags} check || {
%changelog
* Fri Oct 08 2021 Richard W.M. Jones <rjones@redhat.com> - 1.10.0-1
- Rebase to new stable branch version 1.10.0
* Sat Oct 30 2021 Richard W.M. Jones <rjones@redhat.com> - 1.10.1-1
- Rebase to new stable branch version 1.10.1
resolves: rhbz#2011708
* Mon Aug 09 2021 Mohan Boddu <mboddu@redhat.com> - 1.8.2-3

View File

@ -1,2 +1,2 @@
SHA512 (libnbd-1.10.0.tar.gz) = b74866fce8c7bb96690f19171aa0c3f5f0bb486e728c538e30a0b615aa826299ee5472174bc3961721637a525221184b8c8196d8d25a0e765e9de5edbe2ea885
SHA512 (libnbd-1.10.0.tar.gz.sig) = d189e1440cff33f878d2025c3e51feb814bf3c5ed63fa02f4fdf90906245f908e41bed12fb7e54356e8ed8e19ebeb4d3fc5a026ab3ef82abf6ac787609e54bc5
SHA512 (libnbd-1.10.1.tar.gz) = 9deb537535093ec52a73763b5c05f591d4f9e88a2910c375411316b8c2a7861f8f845f6071b8d426467bbb1843b2c1b7131206d344d3fd9904e8a02dcd97a9e8
SHA512 (libnbd-1.10.1.tar.gz.sig) = 94e1c9cbfc4c611d26498fd8df4a574bfefb5a706b2a8831b955b8b4b1a3d460b3ca26f5747015fccef5a5a36940535cc4d4a1f8d45aa1080dab52ba289a981b