Skip to content

Commit

Permalink
src/drivers/efi/efivars.c: avoid overwriting rdev
Browse files Browse the repository at this point in the history
Signed-off-by: Michał Żygowski <[email protected]>
  • Loading branch information
miczyg1 authored and mkopec committed Oct 3, 2023
1 parent dbb2621 commit ebf42a8
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/drivers/efi/efivars.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,13 @@ enum cb_err efi_fv_print_options(struct region_device *rdev)
{
enum cb_err ret;
bool auth_format;
struct region_device store_rdev = *rdev;

ret = efi_fv_init(rdev, &auth_format);
ret = efi_fv_init(&store_rdev, &auth_format);
if (ret != CB_SUCCESS)
return ret;

return walk_variables(rdev, auth_format, print_var, NULL);
return walk_variables(&store_rdev, auth_format, print_var, NULL);
}

/*
Expand All @@ -435,8 +436,9 @@ enum cb_err efi_fv_get_option(struct region_device *rdev,
struct efi_find_args args;
bool auth_format;
enum cb_err ret;
struct region_device store_rdev = *rdev;

ret = efi_fv_init(rdev, &auth_format);
ret = efi_fv_init(&store_rdev, &auth_format);
if (ret != CB_SUCCESS)
return ret;

Expand All @@ -445,7 +447,7 @@ enum cb_err efi_fv_get_option(struct region_device *rdev,
args.size = size;
args.data = dest;

return walk_variables(rdev, auth_format, find_and_copy, &args);
return walk_variables(&store_rdev, auth_format, find_and_copy, &args);
}

static enum cb_err write_auth_hdr(struct region_device *rdev, const EFI_GUID *guid,
Expand Down Expand Up @@ -588,13 +590,14 @@ enum cb_err efi_fv_set_option(struct region_device *rdev,
uint32_t size)
{
struct region_device rdev_old;
struct region_device store_rdev = *rdev;
struct efi_find_compare_args args;
bool found_existing;
VARIABLE_HEADER hdr;
bool auth_format;
enum cb_err ret;

ret = efi_fv_init(rdev, &auth_format);
ret = efi_fv_init(&store_rdev, &auth_format);
if (ret != CB_SUCCESS)
return ret;

Expand All @@ -605,7 +608,7 @@ enum cb_err efi_fv_set_option(struct region_device *rdev,
args.match = false;
args.data = data;

ret = walk_variables(rdev, auth_format, find_and_compare, &args);
ret = walk_variables(&store_rdev, auth_format, find_and_compare, &args);
found_existing = ret == CB_SUCCESS;

if (found_existing) {
Expand All @@ -614,17 +617,17 @@ enum cb_err efi_fv_set_option(struct region_device *rdev,
if (args.match)
return CB_SUCCESS;

rdev_old = *rdev;
rdev_old = store_rdev;

/* Mark as to be deleted */
hdr.State = VAR_IN_DELETED_TRANSITION;
if (rdev_writeat(rdev, &hdr.State, offsetof(VARIABLE_HEADER, State),
if (rdev_writeat(&store_rdev, &hdr.State, offsetof(VARIABLE_HEADER, State),
sizeof(hdr.State)) != sizeof(hdr.State))
return CB_EFI_ACCESS_ERROR;
}

/* Walk to end of variable store */
ret = walk_variables(rdev, auth_format, noop, NULL);
ret = walk_variables(&store_rdev, auth_format, noop, NULL);
if (ret != CB_EFI_OPTION_NOT_FOUND)
return ret;

Expand All @@ -636,9 +639,9 @@ enum cb_err efi_fv_set_option(struct region_device *rdev,
*/

if (auth_format)
ret = write_auth_hdr(rdev, guid, name, data, size);
ret = write_auth_hdr(&store_rdev, guid, name, data, size);
else
ret = write_hdr(rdev, guid, name, data, size);
ret = write_hdr(&store_rdev, guid, name, data, size);
if (ret != CB_SUCCESS)
return ret;

Expand Down

0 comments on commit ebf42a8

Please sign in to comment.