Never fall back to /dev/nbd0 in vitastor-nbd unmap and revive #120

Open
koolkhel wants to merge 1 commits from koolkhel/vitastor:nbd-unmap-dev-num into master
Contributor

Description

netlink-unmap read the device with uint64_value(), so a missing or mistyped device argument (nbd3, /dev/nbd3x) disconnected /dev/nbd0 instead. This change parses N and /dev/nbdN in one place and rejects anything else in every command that takes a device. It also checks that the device exists before unmapping or reviving it.

Tested as non-root, so netlink refuses the actual disconnect. Before the change, netlink-unmap went on to send the disconnect with no device, nbd3 or /dev/nbd3x (all three as device 0), and with /dev/nbd99999. Each one ended in Failed to send netlink message -28. After the change, each fails on the argument instead: device name or number is missing, invalid device name: nbd3, expected /dev/nbdN, /dev/nbd99999 does not exist.

Contributor Name

Vitaliy Idelson (MIND Software LLC, https://mindsw.io), submitted by Yury Luneff

CLA

### Description `netlink-unmap` read the device with `uint64_value()`, so a missing or mistyped device argument (`nbd3`, `/dev/nbd3x`) disconnected `/dev/nbd0` instead. This change parses `N` and `/dev/nbdN` in one place and rejects anything else in every command that takes a device. It also checks that the device exists before unmapping or reviving it. Tested as non-root, so netlink refuses the actual disconnect. Before the change, `netlink-unmap` went on to send the disconnect with no device, `nbd3` or `/dev/nbd3x` (all three as device 0), and with `/dev/nbd99999`. Each one ended in `Failed to send netlink message -28`. After the change, each fails on the argument instead: `device name or number is missing`, `invalid device name: nbd3, expected /dev/nbdN`, `/dev/nbd99999 does not exist`. ### Contributor Name Vitaliy Idelson (MIND Software LLC, https://mindsw.io), submitted by Yury Luneff ### CLA - [x] I accept Vitastor CLA agreement: https://git.yourcmc.ru/vitalif/vitastor/src/branch/master/CLA-en.md
koolkhel added 1 commit 2026-11-16 22:16:13 +03:00
netlink-unmap read the device with uint64_value(), so a missing or
mistyped device argument (nbd3, /dev/nbd3x) disconnected /dev/nbd0
instead. Parse N and /dev/nbdN in one place and reject anything else in
every command that takes a device, and check that the device exists
before unmapping or reviving it.
vitalif reviewed 2026-11-17 10:34:08 +03:00
@@ -426,0 +426,4 @@
// Accepts N and /dev/nbdN, returns -1 for anything else
static int parse_dev_num(const json11::Json & v)
{
if (v.is_number())
Owner

Тут много какой-то упоротой валидации, нужно это всё покороче и покрасивее сделать, например есть вариант проверить что вернул sscanf банально

Тут много какой-то упоротой валидации, нужно это всё покороче и покрасивее сделать, например есть вариант проверить что вернул sscanf банально
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u nbd-unmap-dev-num:koolkhel-nbd-unmap-dev-num
git checkout koolkhel-nbd-unmap-dev-num
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vitalif/vitastor#120
No description provided.