Skip to contentSkip to conversation

nbd: restrict sockets to TCP and UDP

PATCH Applied Eric Dumazet 6 participants 17 messages Sep 9, 2025 – Nov 24, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nbd: restrict sockets to TCP and UDP

Recently, syzbot started to abuse NBD with all kinds of sockets.

Commit cf1b2326b734 ("nbd: verify socket is supported during setup") made sure the socket supported a shutdown() method.

Explicitely accept TCP and UNIX stream sockets.

---
 drivers/block/nbd.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/block/nbd.c +8 -0
index 6463d0e8d0cef71e73e67fecd16de4dec1c75da7..87b0b78249da3325023949585f4daf40486c9692 100644
@@ -1217,6 +1217,14 @@ static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd,
 	if (!sock)
 		return NULL;
 
+	if (!sk_is_tcp(sock->sk) &&
+	    !sk_is_stream_unix(sock->sk)) {
+		dev_err(disk_to_dev(nbd->disk), "Unsupported socket: should be TCP or UNIX.\n");
+		*err = -EINVAL;
+		sockfd_put(sock);
+		return NULL;
+	}
+
 	if (sock->ops->shutdown == sock_no_shutdown) {
 		dev_err(disk_to_dev(nbd->disk), "Unsupported socket: shutdown callout must be supported.\n");
 		*err = -EINVAL;
Signature · 1 line
2.51.0.384.g4c02a37b29-goog
maintainer Applied
#1 lore raw
Quoted 8 lines · Eric Dumazet

Recently, syzbot started to abuse NBD with all kinds of sockets.

Commit cf1b2326b734 ("nbd: verify socket is supported during setup") made sure the socket supported a shutdown() method.

Explicitely accept TCP and UNIX stream sockets.

[...]

Applied, thanks!

[1/1] nbd: restrict sockets to TCP and UDP

      commit: 9f7c02e031570e8291a63162c6c046dc15ff85b0

Best regards,

Signature · 1 line
Jens Axboe
#2 lore raw
In reply to Eric Dumazet
Quoted 6 lines · Eric Dumazet

Recently, syzbot started to abuse NBD with all kinds of sockets.

Commit cf1b2326b734 ("nbd: verify socket is supported during setup") made sure the socket supported a shutdown() method.

Explicitely accept TCP and UNIX stream sockets.

I'm not clear what the actual problem is, but I will say that libnbd & nbdkit (which are another NBD client & server, interoperable with the kernel) we support and use NBD over vsock[1]. And we could support NBD over pretty much any stream socket (Infiniband?) [2].

[1] https://libguestfs.org/nbd_aio_connect_vsock.3.html
https://libguestfs.org/nbdkit-service.1.html#AF_VSOCK
[2] https://libguestfs.org/nbd_connect_socket.3.html

TCP and Unix domain sockets are by far the most widely used, but I don't think it's fair to exclude other socket types.

Rich.

Quoted 35 lines
---
 drivers/block/nbd.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/block/nbd.c +8 -0
index 6463d0e8d0cef71e73e67fecd16de4dec1c75da7..87b0b78249da3325023949585f4daf40486c9692 100644
@@ -1217,6 +1217,14 @@ static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd,
 	if (!sock)
 		return NULL;
 
+	if (!sk_is_tcp(sock->sk) &&
+	    !sk_is_stream_unix(sock->sk)) {
+		dev_err(disk_to_dev(nbd->disk), "Unsupported socket: should be TCP or UNIX.\n");
+		*err = -EINVAL;
+		sockfd_put(sock);
+		return NULL;
+	}
+
 	if (sock->ops->shutdown == sock_no_shutdown) {
 		dev_err(disk_to_dev(nbd->disk), "Unsupported socket: shutdown callout must be supported.\n");
 		*err = -EINVAL;
Signature · 1 line
2.51.0.384.g4c02a37b29-goog
Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html
#3 lore raw
Quoted 14 lines · Richard W.M. Jones
Quoted 6 lines · Eric Dumazet

Recently, syzbot started to abuse NBD with all kinds of sockets.

Commit cf1b2326b734 ("nbd: verify socket is supported during setup") made sure the socket supported a shutdown() method.

Explicitely accept TCP and UNIX stream sockets.

I'm not clear what the actual problem is, but I will say that libnbd & nbdkit (which are another NBD client & server, interoperable with the kernel) we support and use NBD over vsock[1]. And we could support NBD over pretty much any stream socket (Infiniband?) [2].

Quoted 6 lines

[1] https://libguestfs.org/nbd_aio_connect_vsock.3.html
https://libguestfs.org/nbdkit-service.1.html#AF_VSOCK
[2] https://libguestfs.org/nbd_connect_socket.3.html

TCP and Unix domain sockets are by far the most widely used, but I don't think it's fair to exclude other socket types.

If we have known and supported socket types, please send a patch to add them.

I asked the question last week and got nothing about vsock or other types.

https://lore.kernel.org/netdev/CANn89iLNFHBMTF2Pb6hHERYpuih9eQZb6A12+ndzBcQs_kZoBA@mail.gmail.com/

For sure, we do not want datagram sockets, RAW, netlink, and many others.

#4 lore raw
Quoted 23 lines · Eric Dumazet
Quoted 14 lines · Richard W.M. Jones
Quoted 6 lines · Eric Dumazet

Recently, syzbot started to abuse NBD with all kinds of sockets.

Commit cf1b2326b734 ("nbd: verify socket is supported during setup") made sure the socket supported a shutdown() method.

Explicitely accept TCP and UNIX stream sockets.

I'm not clear what the actual problem is, but I will say that libnbd & nbdkit (which are another NBD client & server, interoperable with the kernel) we support and use NBD over vsock[1]. And we could support NBD over pretty much any stream socket (Infiniband?) [2].

Quoted 6 lines

[1] https://libguestfs.org/nbd_aio_connect_vsock.3.html
https://libguestfs.org/nbdkit-service.1.html#AF_VSOCK
[2] https://libguestfs.org/nbd_connect_socket.3.html

TCP and Unix domain sockets are by far the most widely used, but I don't think it's fair to exclude other socket types.

Quoted 7 lines

If we have known and supported socket types, please send a patch to add them.

I asked the question last week and got nothing about vsock or other types.

https://lore.kernel.org/netdev/CANn89iLNFHBMTF2Pb6hHERYpuih9eQZb6A12+ndzBcQs_kZoBA@mail.gmail.com/

For sure, we do not want datagram sockets, RAW, netlink, and many others.

BTW vsock will probably fire lockdep warnings, I see GFP_KERNEL being used in net/vmw_vsock/virtio_transport.c

So you will have to fix this.

maintainer
#5 lore raw
Quoted 28 lines · Eric Dumazet
Quoted 27 lines · Eric Dumazet
Quoted 14 lines · Richard W.M. Jones
Quoted 6 lines · Eric Dumazet

Recently, syzbot started to abuse NBD with all kinds of sockets.

Commit cf1b2326b734 ("nbd: verify socket is supported during setup") made sure the socket supported a shutdown() method.

Explicitely accept TCP and UNIX stream sockets.

I'm not clear what the actual problem is, but I will say that libnbd & nbdkit (which are another NBD client & server, interoperable with the kernel) we support and use NBD over vsock[1]. And we could support NBD over pretty much any stream socket (Infiniband?) [2].

Quoted 6 lines

[1] https://libguestfs.org/nbd_aio_connect_vsock.3.html
https://libguestfs.org/nbdkit-service.1.html#AF_VSOCK
[2] https://libguestfs.org/nbd_connect_socket.3.html

TCP and Unix domain sockets are by far the most widely used, but I don't think it's fair to exclude other socket types.

If we have known and supported socket types, please send a patch to add them.

I asked the question last week and got nothing about vsock or other types.

Quoted 8 lines
Quoted 3 lines

https://lore.kernel.org/netdev/CANn89iLNFHBMTF2Pb6hHERYpuih9eQZb6A12+ndzBcQs_kZoBA@mail.gmail.com/

For sure, we do not want datagram sockets, RAW, netlink, and many others.

BTW vsock will probably fire lockdep warnings, I see GFP_KERNEL being used in net/vmw_vsock/virtio_transport.c

So you will have to fix this.

Rather than play whack-a-mole with this, would it make sense to mark as socket as "writeback/reclaim" safe and base the nbd decision on that rather than attempt to maintain some allow/deny list of sockets?

Signature · 1 line
Jens Axboe
#6 lore raw
Quoted 34 lines · Jens Axboe
Quoted 32 lines · Eric Dumazet
Quoted 30 lines · Eric Dumazet
Quoted 14 lines · Richard W.M. Jones
Quoted 6 lines · Eric Dumazet

Recently, syzbot started to abuse NBD with all kinds of sockets.

Commit cf1b2326b734 ("nbd: verify socket is supported during setup") made sure the socket supported a shutdown() method.

Explicitely accept TCP and UNIX stream sockets.

I'm not clear what the actual problem is, but I will say that libnbd & nbdkit (which are another NBD client & server, interoperable with the kernel) we support and use NBD over vsock[1]. And we could support NBD over pretty much any stream socket (Infiniband?) [2].

Quoted 6 lines

[1] https://libguestfs.org/nbd_aio_connect_vsock.3.html
https://libguestfs.org/nbdkit-service.1.html#AF_VSOCK
[2] https://libguestfs.org/nbd_connect_socket.3.html

TCP and Unix domain sockets are by far the most widely used, but I don't think it's fair to exclude other socket types.

If we have known and supported socket types, please send a patch to add them.

I asked the question last week and got nothing about vsock or other types.

https://lore.kernel.org/netdev/CANn89iLNFHBMTF2Pb6hHERYpuih9eQZb6A12+ndzBcQs_kZoBA@mail.gmail.com/

For sure, we do not want datagram sockets, RAW, netlink, and many others.

Quoted 8 lines
Quoted 4 lines

BTW vsock will probably fire lockdep warnings, I see GFP_KERNEL being used in net/vmw_vsock/virtio_transport.c

So you will have to fix this.

Rather than play whack-a-mole with this, would it make sense to mark as socket as "writeback/reclaim" safe and base the nbd decision on that rather than attempt to maintain some allow/deny list of sockets?

Even if a socket type was writeback/reclaim safe, probably NBD would not support arbitrary socket type, like netlink, af_packet, or af_netrom.

An allow list seems safer to me, with commits with a clear owner.

If future syzbot reports are triggered, the bisection will point to these commits.

maintainer
#7 lore raw
Quoted 44 lines · Eric Dumazet
Quoted 34 lines · On Tue, Sep 9, 2025 at 7:37?AM Jens Axboe <[email protected]> wrote:
Quoted 32 lines · Eric Dumazet
Quoted 30 lines · On Tue, Sep 9, 2025 at 7:04?AM Eric Dumazet <[email protected]> wrote:
Quoted 14 lines · On Tue, Sep 9, 2025 at 6:32?AM Richard W.M. Jones <[email protected]> wrote:
Quoted 6 lines · Eric Dumazet

Recently, syzbot started to abuse NBD with all kinds of sockets.

Commit cf1b2326b734 ("nbd: verify socket is supported during setup") made sure the socket supported a shutdown() method.

Explicitely accept TCP and UNIX stream sockets.

I'm not clear what the actual problem is, but I will say that libnbd & nbdkit (which are another NBD client & server, interoperable with the kernel) we support and use NBD over vsock[1]. And we could support NBD over pretty much any stream socket (Infiniband?) [2].

Quoted 6 lines

[1] https://libguestfs.org/nbd_aio_connect_vsock.3.html
https://libguestfs.org/nbdkit-service.1.html#AF_VSOCK
[2] https://libguestfs.org/nbd_connect_socket.3.html

TCP and Unix domain sockets are by far the most widely used, but I don't think it's fair to exclude other socket types.

If we have known and supported socket types, please send a patch to add them.

I asked the question last week and got nothing about vsock or other types.

https://lore.kernel.org/netdev/CANn89iLNFHBMTF2Pb6hHERYpuih9eQZb6A12+ndzBcQs_kZoBA@mail.gmail.com/

For sure, we do not want datagram sockets, RAW, netlink, and many others.

Quoted 8 lines
Quoted 4 lines

BTW vsock will probably fire lockdep warnings, I see GFP_KERNEL being used in net/vmw_vsock/virtio_transport.c

So you will have to fix this.

Rather than play whack-a-mole with this, would it make sense to mark as socket as "writeback/reclaim" safe and base the nbd decision on that rather than attempt to maintain some allow/deny list of sockets?

Quoted 8 lines

Even if a socket type was writeback/reclaim safe, probably NBD would not support arbitrary socket type, like netlink, af_packet, or af_netrom.

An allow list seems safer to me, with commits with a clear owner.

If future syzbot reports are triggered, the bisection will point to these commits.

That's fine too, either approach will result in fixups, at the end of the day. And followup related fixes to solve issues with socket types that we do deem useful, like the vsock one you already found.

Signature · 1 line
Jens Axboe
#8 lore raw
In reply to Eric Dumazet
Quoted 29 lines · Eric Dumazet
Quoted 28 lines · Jens Axboe
Quoted 26 lines · Eric Dumazet
Quoted 25 lines · Eric Dumazet
Quoted 14 lines · Richard W.M. Jones
Quoted 6 lines · Eric Dumazet

Recently, syzbot started to abuse NBD with all kinds of sockets.

Commit cf1b2326b734 ("nbd: verify socket is supported during setup") made sure the socket supported a shutdown() method.

Explicitely accept TCP and UNIX stream sockets.

I'm not clear what the actual problem is, but I will say that libnbd & nbdkit (which are another NBD client & server, interoperable with the kernel) we support and use NBD over vsock[1]. And we could support NBD over pretty much any stream socket (Infiniband?) [2].

Quoted 6 lines

[1] https://libguestfs.org/nbd_aio_connect_vsock.3.html
https://libguestfs.org/nbdkit-service.1.html#AF_VSOCK
[2] https://libguestfs.org/nbd_connect_socket.3.html

TCP and Unix domain sockets are by far the most widely used, but I don't think it's fair to exclude other socket types.

If we have known and supported socket types, please send a patch to add them.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

I asked the question last week and got nothing about vsock or other types.

https://lore.kernel.org/netdev/CANn89iLNFHBMTF2Pb6hHERYpuih9eQZb6A12+ndzBcQs_kZoBA@mail.gmail.com/

For sure, we do not want datagram sockets, RAW, netlink, and many others.

BTW vsock will probably fire lockdep warnings, I see GFP_KERNEL being used in net/vmw_vsock/virtio_transport.c

CC-ing Stefan & Stefano. Myself, I'm only using libnbd (ie. userspace) over vsock, not the kernel client.

Quoted 6 lines
Quoted 5 lines
Quoted 1 line

So you will have to fix this.

Rather than play whack-a-mole with this, would it make sense to mark as socket as "writeback/reclaim" safe and base the nbd decision on that rather than attempt to maintain some allow/deny list of sockets?

Quoted 7 lines

Even if a socket type was writeback/reclaim safe, probably NBD would not support arbitrary socket type, like netlink, af_packet, or af_netrom.

An allow list seems safer to me, with commits with a clear owner.

If future syzbot reports are triggered, the bisection will point to these commits.

From the outside it seems really odd to hard code a list of "good" socket types into each kernel client that can open a socket. Normally if you wanted to restrict socket types wouldn't you do that through something more flexible like nftables?

Rich.

Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v
#9 lore raw
Quoted 54 lines · Richard W.M. Jones
Quoted 29 lines · Eric Dumazet
Quoted 28 lines · Jens Axboe
Quoted 26 lines · Eric Dumazet
Quoted 25 lines · Eric Dumazet
Quoted 14 lines · Richard W.M. Jones
Quoted 6 lines · Eric Dumazet

Recently, syzbot started to abuse NBD with all kinds of sockets.

Commit cf1b2326b734 ("nbd: verify socket is supported during setup") made sure the socket supported a shutdown() method.

Explicitely accept TCP and UNIX stream sockets.

I'm not clear what the actual problem is, but I will say that libnbd & nbdkit (which are another NBD client & server, interoperable with the kernel) we support and use NBD over vsock[1]. And we could support NBD over pretty much any stream socket (Infiniband?) [2].

Quoted 6 lines

[1] https://libguestfs.org/nbd_aio_connect_vsock.3.html
https://libguestfs.org/nbdkit-service.1.html#AF_VSOCK
[2] https://libguestfs.org/nbd_connect_socket.3.html

TCP and Unix domain sockets are by far the most widely used, but I don't think it's fair to exclude other socket types.

If we have known and supported socket types, please send a patch to add them.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

I asked the question last week and got nothing about vsock or other types.

https://lore.kernel.org/netdev/CANn89iLNFHBMTF2Pb6hHERYpuih9eQZb6A12+ndzBcQs_kZoBA@mail.gmail.com/

For sure, we do not want datagram sockets, RAW, netlink, and many others.

BTW vsock will probably fire lockdep warnings, I see GFP_KERNEL being used in net/vmw_vsock/virtio_transport.c

CC-ing Stefan & Stefano. Myself, I'm only using libnbd (ie. userspace) over vsock, not the kernel client.

Quoted 11 lines
Quoted 5 lines
Quoted 1 line

So you will have to fix this.

Rather than play whack-a-mole with this, would it make sense to mark as socket as "writeback/reclaim" safe and base the nbd decision on that rather than attempt to maintain some allow/deny list of sockets?

Even if a socket type was writeback/reclaim safe, probably NBD would not support arbitrary socket type, like netlink, af_packet, or af_netrom.

An allow list seems safer to me, with commits with a clear owner.

Quoted 7 lines
Quoted 2 lines

If future syzbot reports are triggered, the bisection will point to these commits.

From the outside it seems really odd to hard code a list of "good" socket types into each kernel client that can open a socket. Normally if you wanted to restrict socket types wouldn't you do that through something more flexible like nftables?

nftables is user policy.

We need a kernel that will not crash, even if nftables is not compiled/loaded/used .

Quoted 10 lines

Rich.

--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v

#10 lore raw
Quoted 36 lines · Eric Dumazet
Quoted 35 lines · Richard W.M. Jones
Quoted 33 lines · Eric Dumazet
Quoted 32 lines · Jens Axboe
Quoted 30 lines · Eric Dumazet
Quoted 29 lines · Eric Dumazet
Quoted 14 lines · Richard W.M. Jones
Quoted 6 lines · Eric Dumazet

Recently, syzbot started to abuse NBD with all kinds of sockets.

Commit cf1b2326b734 ("nbd: verify socket is supported during setup") made sure the socket supported a shutdown() method.

Explicitely accept TCP and UNIX stream sockets.

I'm not clear what the actual problem is, but I will say that libnbd & nbdkit (which are another NBD client & server, interoperable with the kernel) we support and use NBD over vsock[1]. And we could support NBD over pretty much any stream socket (Infiniband?) [2].

Quoted 6 lines

[1] https://libguestfs.org/nbd_aio_connect_vsock.3.html
https://libguestfs.org/nbdkit-service.1.html#AF_VSOCK
[2] https://libguestfs.org/nbd_connect_socket.3.html

TCP and Unix domain sockets are by far the most widely used, but I don't think it's fair to exclude other socket types.

If we have known and supported socket types, please send a patch to add them.

I asked the question last week and got nothing about vsock or other types.

https://lore.kernel.org/netdev/CANn89iLNFHBMTF2Pb6hHERYpuih9eQZb6A12+ndzBcQs_kZoBA@mail.gmail.com/

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

For sure, we do not want datagram sockets, RAW, netlink, and many others.

BTW vsock will probably fire lockdep warnings, I see GFP_KERNEL being used in net/vmw_vsock/virtio_transport.c

CC-ing Stefan & Stefano. Myself, I'm only using libnbd (ie. userspace) over vsock, not the kernel client.

Thanks Rich for cceing me!

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

So you will have to fix this.

How we should fix that?

IIUC GFP_KERNEL in virtio_transport.c is used only by workqueue's functions, but we have GFP_ATOMIC in the fast path that can be called when the user is sending a packet.

This is basically the driver for the virtio-vsock device that can allocates extra buffers to be exposed to the device.
In this case the allocation can happen in virtqueue_add_sgs() for virtio indirect buffer, that IIRC virtio-vsock is not using currently (but we don't know in the future).

In any case, we use GFP_KERNEL also in virtio_transport_common.c to allocate the sk_buff, so that should be the same issue.

Thanks,
Stefano

reviewer
#11 lore raw
In reply to Eric Dumazet
Quoted 7 lines · Eric Dumazet
Quoted 6 lines · Richard W.M. Jones
Quoted 5 lines · Eric Dumazet
Quoted 4 lines · Jens Axboe
Quoted 3 lines · Eric Dumazet
Quoted 2 lines · Eric Dumazet
Quoted 1 line · Richard W.M. Jones

On Tue, Sep 09, 2025 at 01:22:43PM +0000, Eric Dumazet wrote:

...

Quoted 9 lines
Quoted 4 lines

From the outside it seems really odd to hard code a list of "good" socket types into each kernel client that can open a socket. Normally if you wanted to restrict socket types wouldn't you do that through something more flexible like nftables?

nftables is user policy.

We need a kernel that will not crash, even if nftables is not compiled/loaded/used .

Hi Rich, Eric, all,

FWIIW, I think that the kernel maintaining a list of acceptable and known to work socket types is a reasonable measure. It reduces the surface where problems can arise - a surface that has real bugs. And can be expanded as necessary.

For sure it is not perfect. There is a risk of entering wack-a-mole territory. And a more flexible mechanism may be nice.

But, OTOH, we may be speculating about a problem that doesn't exist. If, very occasionally, a new socket type comes along and has to be used. Or perhaps more likely, there is a follow-up to this change for some cases it missed (i.e. the topic of this thread). And if that is very occasional. Is there really a problem?

The answer is of course subjective. But I lean towards no.

...

#12 lore raw
In reply to Richard W.M. Jones

So I was playing with this (see commands at end if you want to try) and it turns out that the nbd-client program doesn't support vsock anyway. Of course you could still call the kernel APIs directly to set up the socket, but it wouldn't be straightforward.

nbd-client did support Sockets Direct Protocol (SDP) but support was removed in 2023.

The userspace tools like nbdinfo (part of libnbd) work fine, but of course that's not relevant to the kernel NBD client.

Rich.

Commands to test vsock:

  $ virt-builder fedora-42
  $ nbdkit --vsock memory 1G \
           --run '
      qemu-system-x86_64 -machine accel=kvm:tcg \
                         -cpu host -m 4096 \
                         -drive file=fedora-42.img,format=raw,if=virtio \
                         -device vhost-vsock-pci,guest-cid=3
   '

Inside the guest:

  # dnf install nbdinfo
  # nbdinfo nbd+vsock:///
  (details of the 1G RAM disk will be shown here)
Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v
#13 lore raw
In reply to Eric Dumazet

Hi!

Quoted 6 lines

Recently, syzbot started to abuse NBD with all kinds of sockets.

Commit cf1b2326b734 ("nbd: verify socket is supported during setup") made sure the socket supported a shutdown() method.

Explicitely accept TCP and UNIX stream sockets.

Note that running nbd server and client on same machine is not safe in read-write mode. It may deadlock under low memory conditions.

Thus I'm not sure if we should accept UNIX sockets.

Best regards,
Pavel

Signature · 2 lines
I don't work for Nazis and criminals, and neither should you.
Boycott Putin, Trump, Netanyahu and Musk!
#14 lore raw
Quoted 7 lines · Pavel Machek

Hi!

Quoted 5 lines

Recently, syzbot started to abuse NBD with all kinds of sockets.

Commit cf1b2326b734 ("nbd: verify socket is supported during setup") made sure the socket supported a shutdown() method.

Quoted 6 lines
Quoted 1 line

Explicitely accept TCP and UNIX stream sockets.

Note that running nbd server and client on same machine is not safe in read-write mode. It may deadlock under low memory conditions.

Thus I'm not sure if we should accept UNIX sockets.

Both nbd-client and nbdkit have modes where they can mlock themselves into RAM.

Rich.

Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
#15 lore raw

Userland used in writeback path was Re: [PATCH] nbd: restrict sockets to TCP and UDP

Quoted 10 lines · Richard W.M. Jones
Quoted 9 lines · Pavel Machek

Hi!

Quoted 6 lines

Recently, syzbot started to abuse NBD with all kinds of sockets.

Commit cf1b2326b734 ("nbd: verify socket is supported during setup") made sure the socket supported a shutdown() method.

Explicitely accept TCP and UNIX stream sockets.

Quoted 7 lines
Quoted 4 lines

Note that running nbd server and client on same machine is not safe in read-write mode. It may deadlock under low memory conditions.

Thus I'm not sure if we should accept UNIX sockets.

Both nbd-client and nbdkit have modes where they can mlock themselves into RAM.

kernel needs memory. It issues write-back to get some. nbd-client does syscall. Maybe writing to storage? That syscall does kmalloc().
That kmalloc now needs something like PF_MEMALLOC flag.

mlock() is not enough.

Best regards,
Pavel

Signature · 2 lines
I don't work for Nazis and criminals, and neither should you.
Boycott Putin, Trump, Netanyahu and Musk!
#16 lore raw

Re: Userland used in writeback path was Re: [PATCH] nbd: restrict sockets to TCP and UDP

Quoted 19 lines · Pavel Machek
Quoted 10 lines · Richard W.M. Jones
Quoted 9 lines · Pavel Machek

Hi!

Quoted 6 lines

Recently, syzbot started to abuse NBD with all kinds of sockets.

Commit cf1b2326b734 ("nbd: verify socket is supported during setup") made sure the socket supported a shutdown() method.

Explicitely accept TCP and UNIX stream sockets.

Quoted 7 lines
Quoted 4 lines

Note that running nbd server and client on same machine is not safe in read-write mode. It may deadlock under low memory conditions.

Thus I'm not sure if we should accept UNIX sockets.

Both nbd-client and nbdkit have modes where they can mlock themselves into RAM.

Quoted 6 lines

kernel needs memory. It issues write-back to get some. nbd-client does syscall. Maybe writing to storage? That syscall does kmalloc().
That kmalloc now needs something like PF_MEMALLOC flag.

mlock() is not enough.

There are loads of use cases for NBD over a Unix domain socket that have nothing to do with storage. nbdkit supports all sorts of purely virtual and remote devices.

Practically, we use this feature successfully all the time without any issues, so we'd appreciate it not being broken over some very theoretical concern that you haven't even been able to demonstrate in a test case.

Rich.

Signature · 5 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v