kmemcheck: Test the full object in kmemcheck_is_obj_initialized()
This is a fix for bug #14845 (bugzilla.kernel.org). The update_checksum() function in mm/kmemleak.c calls kmemcheck_is_obj_initialised() before scanning an object. When KMEMCHECK_PARTIAL_OK is enabled, this function returns true. However, the crc32_le() reads smaller intervals (32-bit) for which kmemleak_is_obj_initialised() may be false leading to a kmemcheck warning. Note that kmemcheck_is_obj_initialized() is currently only used by kmemleak before scanning a memory location. Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Christian Casteyde <casteyde.christian@free.fr> Cc: Vegard Nossum <vegardno@ifi.uio.no> Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
This commit is contained in:
Родитель
724e6d3fe8
Коммит
81fc03909a
|
@ -337,7 +337,7 @@ bool kmemcheck_is_obj_initialized(unsigned long addr, size_t size)
|
||||||
if (!shadow)
|
if (!shadow)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
status = kmemcheck_shadow_test(shadow, size);
|
status = kmemcheck_shadow_test_all(shadow, size);
|
||||||
|
|
||||||
return status == KMEMCHECK_SHADOW_INITIALIZED;
|
return status == KMEMCHECK_SHADOW_INITIALIZED;
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,12 +125,12 @@ void kmemcheck_mark_initialized_pages(struct page *p, unsigned int n)
|
||||||
|
|
||||||
enum kmemcheck_shadow kmemcheck_shadow_test(void *shadow, unsigned int size)
|
enum kmemcheck_shadow kmemcheck_shadow_test(void *shadow, unsigned int size)
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_KMEMCHECK_PARTIAL_OK
|
||||||
uint8_t *x;
|
uint8_t *x;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
x = shadow;
|
x = shadow;
|
||||||
|
|
||||||
#ifdef CONFIG_KMEMCHECK_PARTIAL_OK
|
|
||||||
/*
|
/*
|
||||||
* Make sure _some_ bytes are initialized. Gcc frequently generates
|
* Make sure _some_ bytes are initialized. Gcc frequently generates
|
||||||
* code to access neighboring bytes.
|
* code to access neighboring bytes.
|
||||||
|
@ -139,13 +139,25 @@ enum kmemcheck_shadow kmemcheck_shadow_test(void *shadow, unsigned int size)
|
||||||
if (x[i] == KMEMCHECK_SHADOW_INITIALIZED)
|
if (x[i] == KMEMCHECK_SHADOW_INITIALIZED)
|
||||||
return x[i];
|
return x[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return x[0];
|
||||||
#else
|
#else
|
||||||
|
return kmemcheck_shadow_test_all(shadow, size);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
enum kmemcheck_shadow kmemcheck_shadow_test_all(void *shadow, unsigned int size)
|
||||||
|
{
|
||||||
|
uint8_t *x;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
x = shadow;
|
||||||
|
|
||||||
/* All bytes must be initialized. */
|
/* All bytes must be initialized. */
|
||||||
for (i = 0; i < size; ++i) {
|
for (i = 0; i < size; ++i) {
|
||||||
if (x[i] != KMEMCHECK_SHADOW_INITIALIZED)
|
if (x[i] != KMEMCHECK_SHADOW_INITIALIZED)
|
||||||
return x[i];
|
return x[i];
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return x[0];
|
return x[0];
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@ enum kmemcheck_shadow {
|
||||||
void *kmemcheck_shadow_lookup(unsigned long address);
|
void *kmemcheck_shadow_lookup(unsigned long address);
|
||||||
|
|
||||||
enum kmemcheck_shadow kmemcheck_shadow_test(void *shadow, unsigned int size);
|
enum kmemcheck_shadow kmemcheck_shadow_test(void *shadow, unsigned int size);
|
||||||
|
enum kmemcheck_shadow kmemcheck_shadow_test_all(void *shadow,
|
||||||
|
unsigned int size);
|
||||||
void kmemcheck_shadow_set(void *shadow, unsigned int size);
|
void kmemcheck_shadow_set(void *shadow, unsigned int size);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Загрузка…
Ссылка в новой задаче