aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author鞠明岐 <jumingqi@xiaomi.corp-partner.google.com>2023-08-08 07:52:32 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-08-08 07:52:32 +0000
commitd259478e2d61c121380ff9ece35ca03cd6ab6ba5 (patch)
tree8957b4dbf609ac90eff835d5a0043e97981ff859
parent707cddb3d1871c7df473fb21972259c777c41b04 (diff)
parentd815a20c05c4f4110a322db15c6735282d932e6e (diff)
downloadlibese-d259478e2d61c121380ff9ece35ca03cd6ab6ba5.tar.gz
WeaverApplet:Increase failure count before key compare for security am: 9339e797ef am: cca11ea21b am: a4960d26c5 am: d815a20c05
Original change: https://android-review.googlesource.com/c/platform/external/libese/+/2671178 Change-Id: I60e58d4b2a841f04815281149fc8c945f213c96b Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--apps/weaver/card/src/com/android/weaver/core/CoreSlots.java31
1 files changed, 16 insertions, 15 deletions
diff --git a/apps/weaver/card/src/com/android/weaver/core/CoreSlots.java b/apps/weaver/card/src/com/android/weaver/core/CoreSlots.java
index b2ef6b7..4fb86cd 100644
--- a/apps/weaver/card/src/com/android/weaver/core/CoreSlots.java
+++ b/apps/weaver/card/src/com/android/weaver/core/CoreSlots.java
@@ -156,22 +156,11 @@ class CoreSlots implements Slots {
return Consts.READ_BACK_OFF;
}
- // Check the key matches in constant time and copy out the value if it does
- byte result = (Util.arrayCompare(
- keyBuffer, keyOffset, mKey, (short) 0, Consts.SLOT_KEY_BYTES) == 0) ?
- Consts.READ_SUCCESS : Consts.READ_WRONG_KEY;
-
- // Keep track of the number of failures
- if (result == Consts.READ_WRONG_KEY) {
- if (mFailureCount != 0x7fff) {
- mFailureCount += 1;
- }
- } else {
- // This read was successful so reset the failures
- if (mFailureCount != 0) { // attempt to maintain constant time
- mFailureCount = 0;
- }
+ // Assume this read will fail
+ if (mFailureCount != 0x7fff) {
+ mFailureCount += 1;
}
+ byte result = Consts.READ_WRONG_KEY;
// Start the timer on a failure
if (throttle(sRemainingBackoff, (short) 0, mFailureCount)) {
@@ -182,6 +171,18 @@ class CoreSlots implements Slots {
mBackoffTimer.stopTimer();
}
+ // Check the key matches in constant time and copy out the value if it does
+ result = (Util.arrayCompare(
+ keyBuffer, keyOffset, mKey, (short) 0, Consts.SLOT_KEY_BYTES) == 0) ?
+ Consts.READ_SUCCESS : result;
+
+ // Keep track of the number of failures
+ if (result == Consts.READ_SUCCESS) {
+ // This read was successful so reset the failures
+ mFailureCount = 0;
+ mBackoffTimer.stopTimer();
+ }
+
final byte[] data = (result == Consts.READ_SUCCESS) ? mValue : sRemainingBackoff;
Util.arrayCopyNonAtomic(data, (short) 0, outBuffer, outOffset, Consts.SLOT_VALUE_BYTES);