1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

_create_and_load_v4: propagate ioctl errors back to caller

When setting up dm-verity devices with signed root hashes it is very
useful to have a recognizable error code when a key is not present in
the kernel keyring. Turns out the kernel actually returns ENOKEY in that
case, but this gets lost in libdevmapper.

This fixes this: in _create_and_load_v4() it copies the error code from
the ioctl from the sub-tasks back to the main task field on failure.

This is not enough to make libcryptsetup actually propagate the ENOKEY
correctly, that also needs a patch to libcryptsetup, but this is part of
the puzzle.
This commit is contained in:
Lennart Poettering 2023-10-11 15:35:33 +02:00
parent 63b469c160
commit 25ef7a7b1a

View File

@ -1478,7 +1478,7 @@ static int _create_and_load_v4(struct dm_task *dmt)
{ {
struct dm_info info; struct dm_info info;
struct dm_task *task; struct dm_task *task;
int r; int r, ioctl_errno = 0;
uint32_t cookie; uint32_t cookie;
/* Use new task struct to create the device */ /* Use new task struct to create the device */
@ -1504,8 +1504,10 @@ static int _create_and_load_v4(struct dm_task *dmt)
task->cookie_set = dmt->cookie_set; task->cookie_set = dmt->cookie_set;
task->add_node = dmt->add_node; task->add_node = dmt->add_node;
if (!dm_task_run(task)) if (!dm_task_run(task)) {
ioctl_errno = task->ioctl_errno;
goto_bad; goto_bad;
}
if (!dm_task_get_info(task, &info) || !info.exists) if (!dm_task_get_info(task, &info) || !info.exists)
goto_bad; goto_bad;
@ -1536,6 +1538,8 @@ static int _create_and_load_v4(struct dm_task *dmt)
task->ima_measurement = dmt->ima_measurement; task->ima_measurement = dmt->ima_measurement;
r = dm_task_run(task); r = dm_task_run(task);
if (!r)
ioctl_errno = task->ioctl_errno;
task->head = NULL; task->head = NULL;
task->tail = NULL; task->tail = NULL;
@ -1582,12 +1586,18 @@ static int _create_and_load_v4(struct dm_task *dmt)
if (!dm_task_run(dmt)) if (!dm_task_run(dmt))
log_error("Failed to revert device creation."); log_error("Failed to revert device creation.");
if (ioctl_errno != 0)
dmt->ioctl_errno = ioctl_errno;
return 0; return 0;
bad: bad:
dm_task_destroy(task); dm_task_destroy(task);
_udev_complete(dmt); _udev_complete(dmt);
if (ioctl_errno != 0)
dmt->ioctl_errno = ioctl_errno;
return 0; return 0;
} }