Re: [PATCH] kmemcheck: Test the full object in kmemcheck_is_obj_initialized()

From: roel kluin
Date: Mon Feb 08 2010 - 09:38:37 EST


On Mon, Feb 8, 2010 at 12:16 PM, Catalin Marinas
<catalin.marinas@xxxxxxx> wrote:
> 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.

> Âenum kmemcheck_shadow kmemcheck_shadow_test(void *shadow, unsigned int size)
> Â{
> +#ifdef CONFIG_KMEMCHECK_PARTIAL_OK
> Â Â Â Âuint8_t *x;
> Â Â Â Âunsigned int i;
>
> Â Â Â Âx = shadow;
>
> -#ifdef CONFIG_KMEMCHECK_PARTIAL_OK
> Â Â Â Â/*
> Â Â Â Â * Make sure _some_ bytes are initialized. Gcc frequently generates
> Â Â Â Â * 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)
> Â Â Â Â Â Â Â Â Â Â Â Âreturn x[i];
> Â Â Â Â}
> +
> + Â Â Â return x[0];
> Â#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. */
> Â Â Â Âfor (i = 0; i < size; ++i) {
> Â Â Â Â Â Â Â Âif (x[i] != KMEMCHECK_SHADOW_INITIALIZED)
> Â Â Â Â Â Â Â Â Â Â Â Âreturn x[i];
> Â Â Â Â}
> -#endif
>
> Â Â Â Âreturn x[0];
> Â}

Are we certain that size cannot be 0 in kmemcheck_shadow_test()
and kmemcheck_shadow_test_all() or other functions in
arch/x86/mm/kmemcheck/shadow.c with these unsigned
comparisons in loops?

Roel
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/