NBD Client Fails to Parse /etc/nbdtab Correctly on Ubuntu 22.04 and 20.04

Bug #2054470 reported by Thiago Martins
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
nbd
Unknown
Unknown
nbd (Ubuntu)
Fix Released
Undecided
Unassigned
Jammy
Fix Released
Undecided
Sergio Durigan Junior

Bug Description

[ Impact ]

NBD users who want to specify IPv4 addresses on /etc/nbdtab will get a parsing error which renders the program useless in this case:

parse error parsing /etc/nbdtab: syntax errorERROR: no valid configuration for specified device found

[ Test Plan ]

Inside a Jammy VM (not a container):

# apt update
# apt install -y nbd-client nbd-server
# modprobe nbd
# truncate -s 1T /vol-0.img
# cat > /etc/nbd-server/conf.d/exports.conf << _EOF_
[vol0]
exportname = /vol-0.img
_EOF_
# systemctl restart nbd-server.service

Verify that NBD is working properly:

# nbd-client 127.0.0.1 /dev/nbd0 -name vol0

Now, trigger the problem:

# cat >> /etc/nbdtab << _EOF_
nbd0 127.0.0.1 vol0
_EOF_
# nbd-client nbd0

With an unpatched package, you should see the error:

# nbd-client nbd0
parse error parsing /etc/nbdtab: syntax errorERROR: no valid configuration for specified device found

Usage: nbd-client -name|-N name host [port] nbd_device
        [-block-size|-b block size] [-timeout|-t timeout] [-swap|-s] [-sdp|-S]
        [-persist|-p] [-nofork|-n] [-systemd-mark|-m] [-nonetlink|-L]
...

With a patched package, you should see:

# /home/ubuntu/nbd/nbd/nbd-client nbd0
Negotiation: ..size = 1048576MB
Connected /dev/nbd0

[ Where problems could go wrong ]

This is an extremely simple fix, implemented by upstream more than a year ago, and that has been present in multiple Ubuntu releases ever since. Noble and Mantic are not affected, which means that they are already carrying the fix. Fortunately, upstream switched to flex+bison which means that it's easier to understand the fix and track down the problem. I am not expecting any downfall from this, but if there are any, it will likely be an obscure corner case when parsing IPv4 addresses.

[ Original Description ]

Description:

Hello,

I've encountered an issue with the NBD (Network Block Device) client on Ubuntu 22.04 and 20.04, where it fails to correctly parse the `/etc/nbdtab` file, leading to errors when attempting to establish NBD connections using `systemd` services. This issue significantly impacts automation and system startup processes that rely on NBD devices being available at boot time.

### Steps to Reproduce:

1. Prepare an NBD server with a disk image to share. For instance:
   ```bash
   truncate -s 1T /vol-0.img
   ```

2. Configure the NBD server by adding the following to `/etc/nbd-server/conf.d/exports.conf`:
   ```
   [vol0]
   exportname = /vol-0.img
   ```

3. Restart the NBD server to apply the configuration:
   ```bash
   systemctl restart nbd-server.service
   ```

4. Manually connecting to the NBD server works as expected:
   ```bash
   nbd-client 127.0.0.1 /dev/nbd0 -name vol0
   ```
   This successfully establishes the connection, and the NBD device is usable.

5. However, configuring the client connection in `/etc/nbdtab` and attempting to use it results in a parsing error:

Contents of `/etc/nbdtab`:

   ```
   nbd0 127.0.0.1 vol0
   ```

Attempting to initiate the connection with:
   ```bash
   nbd-client nbd0
   ```
   Results in the following error:
   ```
   parse error parsing /etc/nbdtab: syntax errorERROR: no valid configuration for specified device found
   ```

### Impact:

This parsing issue prevents using `systemd` services like `systemctl enable nbd@nbd0 --now` for automating NBD device connections at boot, a significant limitation for environments relying on NBD.

### Additional Information:

- This issue is present in `nbd-client` version 3.23, available in the Ubuntu 22.04 (also affects 20.04) repositories.
- Testing on the Ubuntu 24.04 development branch, which includes `nbd-client` version 3.25, does not exhibit this issue, suggesting a fix has already been implemented in later versions.

### Suggested Action:

Considering the impact of this issue and its resolution in newer versions of NBD, I propose that a backport of `nbd-client` version 3.25 (or newer) to Ubuntu 22.04 and 20.04 would resolve this problem, improving system automation and reliability for users relying on NBD.

Thank you for your attention to this matter. I am looking forward to any updates or recommendations on workarounds in the meantime.

Related branches

Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

Thanks for the report.

I was able to reproduce the problem. I also confirmed that Noble isn't affected.

The fix is probably:

https://github.com/NetworkBlockDevice/nbd/commit/5750003711b8050bad3ddaf5196201ef419ce15d

and there's an upstream bug too:

https://github.com/NetworkBlockDevice/nbd/issues/131

I'll work on preparing the SRUs.

tags: added: server-todo
Changed in nbd (Ubuntu):
status: New → Fix Released
Changed in nbd (Ubuntu Focal):
assignee: nobody → Sergio Durigan Junior (sergiodj)
Changed in nbd (Ubuntu Jammy):
assignee: nobody → Sergio Durigan Junior (sergiodj)
Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

Actually, I could *not* reproduce the problem on Focal:

# cat >> /etc/nbdtab
nbd0 127.0.0.1 vol0
^C
# nbd-client nbd0
Negotiation: ..size = 1048576MB
Error: Failed to setup device, check dmesg

Exiting.

@Thiago, could you please double check? Thanks!

no longer affects: nbd (Ubuntu Focal)
Changed in nbd (Ubuntu Jammy):
status: New → Triaged
description: updated
Revision history for this message
Thiago Martins (martinx) wrote :

Hello, Sergio!

Thank you for your fast support!

Using `localhost` instead of `127.0.0.1` did the trick on Ubuntu 22.04! I haven't tested again on Ubuntu 20.04.

But I do remember seeing an issue with Ubuntu 20.04. But I think it might be related to the service not coming up on the system's boot. Look:

After booting the system, the NBD isn't running.

```
root@cephao-1-ceph-osd-1:~# systemctl status nbd@nbd0
○ <email address hidden> - NBD client connection for nbd0
     Loaded: loaded (/lib/systemd/system/nbd@.service; enabled; vendor preset: enabled)
     Active: inactive (dead)
       Docs: man:nbd-client

Feb 21 22:54:22 cephao-1-ceph-osd-1 systemd[1]: <email address hidden>: Dependency Before=dev-nbd0.device ignored (.device units cannot be delayed)
```

Then, after a restart, it works:

```
root@cephao-1-ceph-osd-1:~# systemctl restart nbd@nbd0
root@cephao-1-ceph-osd-1:~# systemctl status nbd@nbd0
● <email address hidden> - NBD client connection for nbd0
     Loaded: loaded (/lib/systemd/system/nbd@.service; enabled; vendor preset: enabled)
     Active: active (exited) since Wed 2024-02-21 22:57:37 UTC; 2s ago
       Docs: man:nbd-client
    Process: 1096 ExecStart=//sbin/nbd-client nbd0 (code=exited, status=0/SUCCESS)
   Main PID: 1096 (code=exited, status=0/SUCCESS)
        CPU: 4ms

Feb 21 22:57:37 cephao-1-ceph-osd-1 systemd[1]: Starting NBD client connection for nbd0...
Feb 21 22:57:37 cephao-1-ceph-osd-1 nbd-client[1096]: Negotiation: ..size = 3145728MB
Feb 21 22:57:37 cephao-1-ceph-osd-1 nbd-client[1096]: Connected /dev/nbd0
Feb 21 22:57:37 cephao-1-ceph-osd-1 systemd[1]: Finished NBD client connection for nbd0.
```

So this forces me to have the following `/etc/rc.local` file as a workaround:

```
#!/bin/bash
systemctl restart nbd@nbd0
```

I understand that this is a different issue but, worth mentioning here. And I do remember seeing this on Ubuntu 20.04... lol

Cheers!

Revision history for this message
Sergio Durigan Junior (sergiodj) wrote : Re: [Bug 2054470] Re: NBD Client Fails to Parse /etc/nbdtab Correctly on Ubuntu 22.04 and 20.04

On Wednesday, February 21 2024, Thiago Martins wrote:

> Using `localhost` instead of `127.0.0.1` did the trick on Ubuntu 22.04!
> I haven't tested again on Ubuntu 20.04.

Yeah, the problem happens because of the IPv4 there.

> But I do remember seeing an issue with Ubuntu 20.04. But I think it
> might be related to the service not coming up on the system's boot.
> Look:
>
> After booting the system, the NBD isn't running.
>
> ```
> root@cephao-1-ceph-osd-1:~# systemctl status nbd@nbd0
> ○ <email address hidden> - NBD client connection for nbd0
> Loaded: loaded (/lib/systemd/system/nbd@.service; enabled; vendor preset: enabled)
> Active: inactive (dead)
> Docs: man:nbd-client
>
> Feb 21 22:54:22 cephao-1-ceph-osd-1 systemd[1]: <email address hidden>: Dependency Before=dev-nbd0.device ignored (.device units cannot be delayed)
> ```
>
> Then, after a restart, it works:
>
> ```
> root@cephao-1-ceph-osd-1:~# systemctl restart nbd@nbd0
> root@cephao-1-ceph-osd-1:~# systemctl status nbd@nbd0
> ● <email address hidden> - NBD client connection for nbd0
> Loaded: loaded (/lib/systemd/system/nbd@.service; enabled; vendor preset: enabled)
> Active: active (exited) since Wed 2024-02-21 22:57:37 UTC; 2s ago
> Docs: man:nbd-client
> Process: 1096 ExecStart=//sbin/nbd-client nbd0 (code=exited, status=0/SUCCESS)
> Main PID: 1096 (code=exited, status=0/SUCCESS)
> CPU: 4ms
>
> Feb 21 22:57:37 cephao-1-ceph-osd-1 systemd[1]: Starting NBD client connection for nbd0...
> Feb 21 22:57:37 cephao-1-ceph-osd-1 nbd-client[1096]: Negotiation: ..size = 3145728MB
> Feb 21 22:57:37 cephao-1-ceph-osd-1 nbd-client[1096]: Connected /dev/nbd0
> Feb 21 22:57:37 cephao-1-ceph-osd-1 systemd[1]: Finished NBD client connection for nbd0.
> ```
>
> So this forces me to have the following `/etc/rc.local` file as a
> workaround:
>
> ```
> #!/bin/bash
> systemctl restart nbd@nbd0
> ```
>
> I understand that this is a different issue but, worth mentioning here.
> And I do remember seeing this on Ubuntu 20.04... lol

Thanks for the clarification. Indeed, this is a different issue so it
need its own bug :-).

Cheers,

--
Sergio
GPG key ID: E92F D0B3 6B14 F1F4 D8E0 EB2F 106D A1C8 C3CB BF14

Revision history for this message
Thiago Martins (martinx) wrote :

Hi Sergio,

Thank you for taking the taking to troubleshoot this!

I forgot to mention another step I took:

```
echo nbd > /etc/modules-load.d/nbd.conf
```

Perhaps there's also a need to `update-initramfs -k all -u`?

Revision history for this message
Thiago Martins (martinx) wrote :

Oops, wrong bug report. Ignore my previous message.

Revision history for this message
Timo Aaltonen (tjaalton) wrote : Please test proposed package

Hello Thiago, or anyone else affected,

Accepted nbd into jammy-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/nbd/1:3.23-3ubuntu1.22.04.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-jammy to verification-done-jammy. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-jammy. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in nbd (Ubuntu Jammy):
status: Triaged → Fix Committed
tags: added: verification-needed verification-needed-jammy
Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

Performing the verification on Jammy.

First, checking that the issue can be triggered:

# apt policy nbd-client
nbd-client:
  Installed: 1:3.23-3ubuntu1
  Candidate: 1:3.23-3ubuntu1
  Version table:
 *** 1:3.23-3ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
        100 /var/lib/dpkg/status
nbd-server:
  Installed: 1:3.23-3ubuntu1
  Candidate: 1:3.23-3ubuntu1
  Version table:
 *** 1:3.23-3ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages
        100 /var/lib/dpkg/status

# nbd-client nbd0
parse error parsing /etc/nbdtab: syntax errorERROR: no valid configuration for specified device found

Now, verifying that the package from -proposed fixes the bug:

# apt policy nbd-client nbd-server
nbd-client:
  Installed: 1:3.23-3ubuntu1.22.04.1
  Candidate: 1:3.23-3ubuntu1.22.04.1
  Version table:
 *** 1:3.23-3ubuntu1.22.04.1 500
        500 http://archive.ubuntu.com/ubuntu jammy-proposed/universe amd64 Packages
        100 /var/lib/dpkg/status
     1:3.23-3ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
nbd-server:
  Installed: 1:3.23-3ubuntu1.22.04.1
  Candidate: 1:3.23-3ubuntu1.22.04.1
  Version table:
 *** 1:3.23-3ubuntu1.22.04.1 500
        500 http://archive.ubuntu.com/ubuntu jammy-proposed/main amd64 Packages
        100 /var/lib/dpkg/status
     1:3.23-3ubuntu1 500
        500 http://archive.ubuntu.com/ubuntu jammy/main amd64 Packages

# nbd-client nbd0
Negotiation: ..size = 1048576MB
Connected /dev/nbd0

This concludes the verification on Jammy.

tags: added: verification-done verification-done-jammy
removed: verification-needed verification-needed-jammy
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package nbd - 1:3.23-3ubuntu1.22.04.1

---------------
nbd (1:3.23-3ubuntu1.22.04.1) jammy; urgency=medium

  * Cherry-pick "Don't disallow dots in /etc/nbdtab hostnames"
    (5750003711b8050bad3d) to accept IPv4 addresses on /etc/nbdtab.
    (LP: #2054470)
    - nbdtab_lexer.c: Update.

 -- Sergio Durigan Junior <email address hidden> Wed, 21 Feb 2024 15:41:05 -0500

Changed in nbd (Ubuntu Jammy):
status: Fix Committed → Fix Released
Revision history for this message
Chris Halse Rogers (raof) wrote : Update Released

The verification of the Stable Release Update for nbd has completed successfully and the package is now being released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.