Blame SOURCES/0003-fix-relop-in-esl_iter_next.patch

089977
From 50b302ea7b6bd41c38d50b2af9d89af5f715068a Mon Sep 17 00:00:00 2001
089977
From: Laszlo Ersek <lersek@redhat.com>
089977
Date: Wed, 16 May 2018 14:06:48 +0200
089977
Subject: [PATCH] fix relop in esl_iter_next()
089977
089977
esl_iter_next() seeks to the next EFI_SIGNATURE_LIST object in the
089977
signature database that's being processed.
089977
089977
- The position of the current (just processed) EFI_SIGNATURE_LIST object
089977
  in the signature database is "iter->offset".
089977
089977
- The size of the same is in "iter->esl->SignatureListSize".
089977
089977
- The size of the whole signature dabatase (containing the current
089977
  EFI_SIGNATURE_LIST) is in "iter->len".
089977
089977
Thus, we need to advance "iter->offset" by "iter->esl->SignatureListSize",
089977
to reach the next EFI_SIGNATURE_LIST object.
089977
089977
While advancing, we must not exceed the whole signature database. In other
089977
words, the (exclusive) end of the just processed EFI_SIGNATURE_LIST object
089977
is required to precede, or equal, the (exclusive) end of the signature
089977
database. Hence the "good" condition is:
089977
089977
  iter->offset + iter->esl->SignatureListSize <= iter->len
089977
089977
The "bad" condition is the negation of the above:
089977
089977
  iter->offset + iter->esl->SignatureListSize > iter->len
089977
089977
Because we don't trust "iter->esl->SignatureListSize" (since that was
089977
simply read from the binary blob, not computed by ourselves), we don't
089977
want to add to it or subtract from it (integer overflow!), we just want to
089977
use it naked for comparison. So we subtract "iter->offset" from both
089977
sides: "iter->offset" and "iter->len" are known-good because we've checked
089977
and computed them all along, so we can perform integer operations on them.
089977
After the subtraction, we have the following condition for *bad*:
089977
089977
  iter->esl->SignatureListSize > iter->len - iter->offset
089977
089977
Another way to put the same condition, for *bad*, is to swing the sides
089977
around the relop (giving a spin to the relop as well):
089977
089977
  iter->len - iter->offset < iter->esl->SignatureListSize
089977
089977
The controlling expression in esl_iter_next() is just this, except for the
089977
typo in the relational operator. Fix it.
089977
089977
Ref: https://bugzilla.redhat.com/show_bug.cgi?id=1508808
089977
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
089977
---
089977
 src/iter.c | 2 +-
089977
 1 file changed, 1 insertion(+), 1 deletion(-)
089977
089977
diff --git a/src/iter.c b/src/iter.c
089977
index 45ee059e74c..f19166ab276 100644
089977
--- a/src/iter.c
089977
+++ b/src/iter.c
089977
@@ -222,7 +222,7 @@ esl_iter_next(esl_iter *iter, efi_guid_t *type,
089977
 		vprintf("Getting next EFI_SIGNATURE_LIST\n");
089977
 		efi_guid_t type;
089977
 		esl_get_type(iter, &type);
089977
-		if (iter->len - iter->offset > iter->esl->SignatureListSize) {
089977
+		if (iter->len - iter->offset < iter->esl->SignatureListSize) {
089977
 			warnx("EFI Signature List is malformed");
089977
 			errx(1, "list has %zd bytes left, element is %"PRIu32" bytes",
089977
 			     iter->len - iter->offset,
089977
-- 
089977
2.29.2
089977