1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-27 18:55:40 +03:00

Merge pull request #26783 from yuwata/loop-ref-follow-up

udev: slightly extend comment and add more tests
This commit is contained in:
Daan De Meyer 2023-03-17 10:00:43 +01:00 committed by GitHub
commit 6742397921
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 7 deletions

View File

@ -287,12 +287,14 @@ static int read_loopback_backing_inode(
if (isempty((char*) info.lo_file_name) ||
strnlen((char*) info.lo_file_name, sizeof(info.lo_file_name)-1) == sizeof(info.lo_file_name)-1)
/* Don't pick up file name if it is unset or possibly truncated. (Note: we can't really know
* the file file name is truncated if it uses sizeof(info.lo_file_name)-1 as length; it could
* also just mean the string is just that long and wasn't truncated but the fact is simply
* that we cannot know in that case if it was truncated or not, hence we assume the worst and
* suppress at least for now. For shorter strings we know for sure it wasn't truncated,
* hence that's always safe.) */
/* Don't pick up file name if it is unset or possibly truncated. (Note: the kernel silently
* truncates the string passed from userspace by LOOP_SET_STATUS64 ioctl. See
* loop_set_status_from_info() in drivers/block/loop.c. Hence, we can't really know the file
* name is truncated if it uses sizeof(info.lo_file_name)-1 as length; it could also mean the
* string is just that long and wasn't truncated but the fact is simply that we cannot know
* in that case if it was truncated or not. Thus, we assume the worst and suppress at least
* for now. For shorter strings we know for sure it wasn't truncated, hence that's always
* safe.) */
fn = NULL;
else {
fn = memdup_suffix0(info.lo_file_name, sizeof(info.lo_file_name));

View File

@ -447,8 +447,28 @@ fi
# Detach by loopback device
systemd-dissect --detach "$LOOP"
# Test long reference name.
# Note, sizeof_field(struct loop_info64, lo_file_name) == 64,
# and --loop-ref accepts upto 63 characters, and udev creates symlink
# based on the name when it has upto _62_ characters.
name="$(for (( i = 0; i < 62; i++ )); do echo -n 'x'; done)"
LOOP="$(systemd-dissect --attach --loop-ref="$name" "${image}.raw")"
udevadm trigger -w "$LOOP"
# Check if the /dev/loop/by-ref/$name symlink really references the right device
test "/dev/loop/by-ref/$name" -ef "$LOOP"
# Detach by the /dev/loop/by-ref symlink
systemd-dissect --detach "/dev/loop/by-ref/$name"
name="$(for (( i = 0; i < 63; i++ )); do echo -n 'x'; done)"
LOOP="$(systemd-dissect --attach --loop-ref="$name" "${image}.raw")"
udevadm trigger -w "$LOOP"
# Check if the /dev/loop/by-ref/$name symlink does not exist
test ! -e "/dev/loop/by-ref/$name"
# Detach by backing inode
systemd-dissect --attach --loop-ref=waldo "${image}.raw"
systemd-dissect --detach "${image}.raw"
(! systemd-dissect --detach "${image}.raw")