Skip to contentSkip to conversation

efi/efi_test: Prevent an Oops in efi_runtime_query_capsulecaps()

PATCH Applied Dan Carpenter 3 participants 4 messages Sep 30, 2017 – Oct 11, 2017 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi/efi_test: Prevent an Oops in efi_runtime_query_capsulecaps()

If "qcaps.capsule_count" is ULONG_MAX then "qcaps.capsule_count + 1" will overflow to zero and kcalloc() will return the ZERO_SIZE_PTR. We try to dereference it inside the loop and crash.

Fixes ff6301dabc3c ("efi: Add efi_test driver for exporting UEFI runtime service interfaces")
drivers/firmware/efi/test/efi_test.c +3 -0
index 08129b7b80ab..41c48a1e8baa 100644
@@ -593,6 +593,9 @@ static long efi_runtime_query_capsulecaps(unsigned long arg)
 	if (copy_from_user(&qcaps, qcaps_user, sizeof(qcaps)))
 		return -EFAULT;
 
+	if (qcaps.capsule_count = ULONG_MAX)
+		return -EINVAL;
+
 	capsules = kcalloc(qcaps.capsule_count + 1,
 			   sizeof(efi_capsule_header_t), GFP_KERNEL);
 	if (!capsules)
#1 lore raw
Quoted 12 lines · Dan Carpenter

If "qcaps.capsule_count" is ULONG_MAX then "qcaps.capsule_count + 1" will overflow to zero and kcalloc() will return the ZERO_SIZE_PTR. We try to dereference it inside the loop and crash.

Fixes ff6301dabc3c ("efi: Add efi_test driver for exporting UEFI runtime service interfaces")
drivers/firmware/efi/test/efi_test.c +0 -0
index 08129b7b80ab..41c48a1e8baa 100644

drivers/firmware/efi/test/efi_test.c static long efi_runtime_query_capsulecaps(unsigned long arg) · line 601

Quoted 9 lines
drivers/firmware/efi/test/efi_test.c +3 -0
@@ -593,6 +593,9 @@ static long efi_runtime_query_capsulecaps(unsigned long arg)
 	if (copy_from_user(&qcaps, qcaps_user, sizeof(qcaps)))
 		return -EFAULT;
 
+	if (qcaps.capsule_count = ULONG_MAX)
+		return -EINVAL;
+
 	capsules = kcalloc(qcaps.capsule_count + 1,
 			   sizeof(efi_capsule_header_t), GFP_KERNEL);
 	if (!capsules)

This looks OK to me. Ivan?

A message that is not in the archive (sent off-list or not yet received): 20171006121939.GC3314-mF/unelCI9GS6iBeEJttW/[email protected]

maintainer Acked-by
#3 lore raw

ACK: [PATCH] efi/efi_test: Prevent an Oops in efi_runtime_query_capsulecaps()

Quoted 16 lines · Matt Fleming
Quoted 15 lines · Dan Carpenter

If "qcaps.capsule_count" is ULONG_MAX then "qcaps.capsule_count + 1" will overflow to zero and kcalloc() will return the ZERO_SIZE_PTR. We try to dereference it inside the loop and crash.

Fixes ff6301dabc3c ("efi: Add efi_test driver for exporting UEFI runtime service interfaces")
drivers/firmware/efi/test/efi_test.c +0 -0
index 08129b7b80ab..41c48a1e8baa 100644
@@ -593,6 +593,9 @@ static long efi_runtime_query_capsulecaps(unsigned long arg)
  	if (copy_from_user(&qcaps, qcaps_user, sizeof(qcaps)))
  		return -EFAULT;
 
Quoted 9 lines

drivers/firmware/efi/test/efi_test.c static long efi_runtime_query_capsulecaps(unsigned long arg) · line 601

Quoted 6 lines
drivers/firmware/efi/test/efi_test.c +3 -0
+	if (qcaps.capsule_count = ULONG_MAX)
+		return -EINVAL;
+
  	capsules = kcalloc(qcaps.capsule_count + 1,
  			   sizeof(efi_capsule_header_t), GFP_KERNEL);
  	if (!capsules)

This looks OK to me. Ivan?

Applied
#4 lore raw

Re: ACK: [PATCH] efi/efi_test: Prevent an Oops in efi_runtime_query_capsulecaps()

Quoted 29 lines · Ivan Hu
Quoted 8 lines · Matt Fleming
Quoted 7 lines · Dan Carpenter

If "qcaps.capsule_count" is ULONG_MAX then "qcaps.capsule_count + 1" will overflow to zero and kcalloc() will return the ZERO_SIZE_PTR. We try to dereference it inside the loop and crash.

Fixes ff6301dabc3c ("efi: Add efi_test driver for exporting UEFI runtime service interfaces")
Quoted 16 lines

drivers/firmware/efi/test/efi_test.c static long efi_runtime_query_capsulecaps(unsigned long arg) · line 600

Quoted 13 lines
drivers/firmware/efi/test/efi_test.c +3 -0
index 08129b7b80ab..41c48a1e8baa 100644
@@ -593,6 +593,9 @@ static long efi_runtime_query_capsulecaps(unsigned long arg)
 	if (copy_from_user(&qcaps, qcaps_user, sizeof(qcaps)))
 		return -EFAULT;
+	if (qcaps.capsule_count = ULONG_MAX)
+		return -EINVAL;
+
 	capsules = kcalloc(qcaps.capsule_count + 1,
 			   sizeof(efi_capsule_header_t), GFP_KERNEL);
 	if (!capsules)

This looks OK to me. Ivan?

Quoted 1 line

Thanks, applied.