$filterdir/nbdkit-protect-filter.so
The filter.
Use "nbdkit --dump-config" to find the location of $filterdir.
Write-protect parts of a plugin
nbdkit --filter=protect
plugin
protect=START-END
[protect= ...]
"nbdkit-protect-filter" is a filter for nbdkit(1) that lets you write-protect parts of the underlying plugin. This prevents clients from modifying ranges of the plugin, while still allowing the NBD connection to be writable in general.
One use for this is to prevent clients from adding a phony header to the data to make it look like a non-raw disk format (like adding a qcow2 header), since that can be used in some exploits.
To make the whole plugin readonly, use the nbdkit -r option on the command line, or nbdkit-readonly-filter(1). To give selective access to the server, use nbdkit-ip-filter(1). To serve only a subset of the plugin use nbdkit-offset-filter(1) or nbdkit-partition-filter(1).
Protect the first part of the boot sector from writes, but allow the MBR partition table to be updated:
nbdkit --filter=protect file disk.img protect=0-0x1bd
Allow clients to write to a single partition on the disk, but prevent modifications to the partition table, boot sector, other partitions, or any other metadata outside the partition:
$ fdisk -l disk.imgDevice Boot Start End Sectors Size Id Typedisk.img1 * 2048 12580863 12578816 6G 83 Linux$ start=$((2048*512))$ end=$((12580863*512+511))$ nbdkit --filter=protect file disk.img protect=~$start-$end
Notes:
Data in other partitions and parts of the disk is still readable.
The '~' character complements the range protected. You might need to escape it from the shell using quotes or backslash.
This is different from nbdkit-partition-filter(1) — that filter exposes the partition as a whole device.
protect=START-ENDProtect the bytes starting at offset "START" through to offset "END" (inclusive). Reads are permitted. Writes to the protected range are only permitted if they do not change the content. If an attempt is made to change the content, then the error "NBD_EPERM" (Operation not permitted) is returned to the client.
"START" and "END" can be expressed in decimal, octal ("0NN") or hexadecimal ("0xNN"). If omitted then they default to the start and end of the underlying plugin respectively.
This parameter can be given multiple times to protect several ranges.
protect=~START-ENDThis protects the complement of the range "START" to "END".
$filterdir/nbdkit-protect-filter.so
The filter.
Use "nbdkit --dump-config" to find the location of $filterdir.
"nbdkit-protect-filter" first appeared in nbdkit 1.30.
2 releases since Debian 12 (Bookworm); the text changed 1 time.