Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 9 additions & 20 deletions src/efivarfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,10 @@ efivarfs_get_variable(efi_guid_t guid, const char *name, uint8_t **data,
__typeof__(errno) errno_value;
int ret = -1;
size_t size = 0;
uint32_t ret_attributes = 0;
uint8_t *ret_data;
int fd = -1;
char *path = NULL;
int rc;
int ratelimit;

/*
* The kernel rate limiter hits us if we go faster than 100 efi
* variable reads per second as non-root. So if we're not root, just
* delay this long after each read. The user is not going to notice.
*
* 1s / 100 = 10000us.
*/
ratelimit = geteuid() == 0 ? 0 : 10000;

rc = make_efivarfs_path(&path, guid, name);
if (rc < 0) {
Expand All @@ -269,23 +258,23 @@ efivarfs_get_variable(efi_guid_t guid, const char *name, uint8_t **data,
goto err;
}

usleep(ratelimit);
rc = read(fd, &ret_attributes, sizeof (ret_attributes));
rc = read_file(fd, &ret_data, &size);
if (rc < 0) {
efi_error("read failed");
efi_error("read_file failed");
goto err;
}
--size; // read_file pads out 1 extra byte to NUL

usleep(ratelimit);
rc = read_file(fd, &ret_data, &size);
if (rc < 0) {
efi_error("read_file failed");
if (size < sizeof (*attributes)) {
efi_error("no attributes");
goto err;
}

*attributes = ret_attributes;
memcpy(attributes, ret_data, sizeof (*attributes));
memmove(ret_data, ret_data + sizeof (*attributes), size - sizeof (*attributes));

*data = ret_data;
*data_size = size - 1; // read_file pads out 1 extra byte to NUL it */
*data_size = size - sizeof (*attributes);

ret = 0;
err:
Expand Down
11 changes: 0 additions & 11 deletions src/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,6 @@ vars_get_variable(efi_guid_t guid, const char *name, uint8_t **data,
char *path = NULL;
int rc;
int fd = -1;
int ratelimit;

/*
* The kernel rate limiter hits us if we go faster than 100 efi
* variable reads per second as non-root. So if we're not root, just
* delay this long after each read. The user is not going to notice.
*
* 1s / 100 = 10000us.
*/
ratelimit = geteuid() == 0 ? 0 : 10000;

rc = asprintf(&path, "%s%s-" GUID_FORMAT "/raw_var", get_vars_path(),
name, GUID_FORMAT_ARGS(&guid));
Expand All @@ -314,7 +304,6 @@ vars_get_variable(efi_guid_t guid, const char *name, uint8_t **data,
goto err;
}

usleep(ratelimit);
rc = read_file(fd, &buf, &bufsize);
if (rc < 0) {
efi_error("read_file(%s) failed", path);
Expand Down