summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Setje-Eilers <jan.setjeeilers@oracle.com>2021-03-26 21:19:14 -0700
committerPeter Jones <pjones@redhat.com>2021-03-27 18:47:59 -0400
commitca034e15aa15aa43c78ff6203feec8423b814047 (patch)
tree0c425dac53a5d74ba5ecab8dd7b47dabfb8a9803
parent08a0ce01dbe9945287f37a9b139b25f46c53f878 (diff)
downloadefi-boot-shim-ca034e15aa15aa43c78ff6203feec8423b814047.tar.gz
efi-boot-shim-ca034e15aa15aa43c78ff6203feec8423b814047.zip
Fix SBAT variable content validation.
Currently, the check for the contents of the SBAT variable has an inverted strncmp() test, causing it to delete the variable inappropriately. This patch fixes that check, preventing shim from always stepping on the sbat variable, and adds test cases to validate the correct logic. Signed-off-by: Jan Setje-Eilers <jan.setjeeilers@oracle.com>
-rw-r--r--sbat.c2
-rw-r--r--test-sbat.c57
2 files changed, 58 insertions, 1 deletions
diff --git a/sbat.c b/sbat.c
index 7bd0e4ec..4d6ddd22 100644
--- a/sbat.c
+++ b/sbat.c
@@ -309,7 +309,7 @@ preserve_sbat_uefi_variable(UINT8 *sbat, UINTN sbatsize, UINT32 attributes)
{
return check_sbat_var_attributes(attributes) &&
sbatsize >= strlen(SBAT_VAR_SIG "1") &&
- strncmp((const char *)sbat, SBAT_VAR_SIG, strlen(SBAT_VAR_SIG));
+ !strncmp((const char *)sbat, SBAT_VAR_SIG, strlen(SBAT_VAR_SIG));
}
EFI_STATUS
diff --git a/test-sbat.c b/test-sbat.c
index 780e5cbe..8b94ecf0 100644
--- a/test-sbat.c
+++ b/test-sbat.c
@@ -953,6 +953,58 @@ test_parse_and_verify(void)
}
int
+test_preserve_sbat_uefi_variable_good(void)
+{
+ char sbat[] = "sbat,1,\ncomponent,2,\n";
+ size_t sbat_size = sizeof(sbat);
+ UINT32 attributes = SBAT_VAR_ATTRS;
+
+ if (preserve_sbat_uefi_variable(sbat, sbat_size, attributes))
+ return 0;
+ else
+ return -1;
+}
+
+int
+test_preserve_sbat_uefi_variable_bad_sig(void)
+{
+ char sbat[] = "bad_sig,1,\ncomponent,2,\n";
+ size_t sbat_size = sizeof(sbat);
+ UINT32 attributes = SBAT_VAR_ATTRS;
+
+ if (preserve_sbat_uefi_variable(sbat, sbat_size, attributes))
+ return -1;
+ else
+ return 0;
+}
+
+int
+test_preserve_sbat_uefi_variable_bad_attr(void)
+{
+ char sbat[] = "sbat,1,\ncomponent,2,\n";
+ size_t sbat_size = sizeof(sbat);
+ UINT32 attributes = 0;
+
+ if (preserve_sbat_uefi_variable(sbat, sbat_size, attributes))
+ return -1;
+ else
+ return 0;
+}
+
+int
+test_preserve_sbat_uefi_variable_bad_short(void)
+{
+ char sbat[] = "sba";
+ size_t sbat_size = sizeof(sbat);
+ UINT32 attributes = SBAT_VAR_ATTRS;
+
+ if (preserve_sbat_uefi_variable(sbat, sbat_size, attributes))
+ return -1;
+ else
+ return 0;
+}
+
+int
main(void)
{
int status = 0;
@@ -989,6 +1041,11 @@ main(void)
#endif
test(test_parse_and_verify);
+ test(test_preserve_sbat_uefi_variable_good);
+ test(test_preserve_sbat_uefi_variable_bad_sig);
+ test(test_preserve_sbat_uefi_variable_bad_attr);
+ test(test_preserve_sbat_uefi_variable_bad_short);
+
return 0;
}