summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Bauer <sbauer@plzdonthack.me>2017-04-06 18:35:40 -0600
committerJakub Pawlowski <jpawlowski@google.com>2017-09-28 18:27:08 +0000
commit636b754cfa8a35c99c18db1725e471ce6fcc9878 (patch)
treee33714503714071e0a9b40f135a36ce6f8dd402c
parent5af8ec6e8598059765c4da93fc12494f86af3ada (diff)
downloadandroid_system_bt-636b754cfa8a35c99c18db1725e471ce6fcc9878.tar.gz
android_system_bt-636b754cfa8a35c99c18db1725e471ce6fcc9878.tar.bz2
android_system_bt-636b754cfa8a35c99c18db1725e471ce6fcc9878.zip
Read the correct amount of attributes
bta_gattc_cache_load currently attempts to read 0xFF attributes into an allocation sized to num_attr attributes, which can be smaller than 0xFF. There aren't more than num_attr bytes in correct data, but this breaks with dynamic buffer overflow checking in CopperheadOS for the read system call since fread ends up calling read, which obtains the size of the allocation from the malloc implementation and then aborts due to the (potential) overflow. This would also fail with the default enabled _FORTIFY_SOURCE=2 feature in the Android Open Source Project if osi_malloc was marked with the alloc_size attribute. The way it wraps malloc loses that information so fortify checks aren't done for calls like this. Bug: 37160362 Change-Id: I68bd170d5378c9d9d21cbda376083bc0b857e15c Signed-off-by: Scott Bauer <sbauer@plzdonthack.me> [migrated to C++ file, added 0xFFFF limit and wrote commit message] Signed-off-by: Daniel Micay <danielmicay@gmail.com>
-rw-r--r--bta/gatt/bta_gattc_cache.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/bta/gatt/bta_gattc_cache.c b/bta/gatt/bta_gattc_cache.c
index e2c904de7..d283b382d 100644
--- a/bta/gatt/bta_gattc_cache.c
+++ b/bta/gatt/bta_gattc_cache.c
@@ -1550,7 +1550,7 @@ bool bta_gattc_cache_load(tBTA_GATTC_CLCB *p_clcb)
attr = osi_malloc(sizeof(tBTA_GATTC_NV_ATTR) * num_attr);
- if (fread(attr, sizeof(tBTA_GATTC_NV_ATTR), 0xFF, fd) != num_attr) {
+ if (fread(attr, sizeof(tBTA_GATTC_NV_ATTR), num_attr, fd) != num_attr) {
APPL_TRACE_ERROR("%s: can't read GATT attributes: %s", __func__, fname);
goto done;
}