Re: [PATCH 2/2] test_overflow: Regularize test reporting output

From: Rasmus Villemoes
Date: Tue Sep 21 2021 - 02:56:27 EST


On 21/09/2021 00.10, Nick Desaulniers wrote:
> On Mon, Sep 20, 2021 at 11:09 AM Kees Cook <keescook@xxxxxxxxxxxx> wrote:
>>

>> @@ -544,10 +544,7 @@ DEFINE_TEST_ALLOC(kmalloc, kfree, 0, 1, 0);
>> DEFINE_TEST_ALLOC(kmalloc_node, kfree, 0, 1, 1);
>> DEFINE_TEST_ALLOC(kzalloc, kfree, 0, 1, 0);
>> DEFINE_TEST_ALLOC(kzalloc_node, kfree, 0, 1, 1);
>> -DEFINE_TEST_ALLOC(vmalloc, vfree, 0, 0, 0);
>> -DEFINE_TEST_ALLOC(vmalloc_node, vfree, 0, 0, 1);
>> -DEFINE_TEST_ALLOC(vzalloc, vfree, 0, 0, 0);
>> -DEFINE_TEST_ALLOC(vzalloc_node, vfree, 0, 0, 1);
>> +DEFINE_TEST_ALLOC(__vmalloc, vfree, 0, 1, 0);
>> DEFINE_TEST_ALLOC(kvmalloc, kvfree, 0, 1, 0);
>> DEFINE_TEST_ALLOC(kvmalloc_node, kvfree, 0, 1, 1);
>> DEFINE_TEST_ALLOC(kvzalloc, kvfree, 0, 1, 0);
>> @@ -559,8 +556,14 @@ static int __init test_overflow_allocation(void)
>> {
>> const char device_name[] = "overflow-test";
>> struct device *dev;
>> + int count = 0;
>> int err = 0;
>>
>> +#define check_allocation_overflow(alloc) ({ \
>> + count++; \
>> + test_ ## alloc(dev); \
>> +})
>> +
>> /* Create dummy device for devm_kmalloc()-family tests. */
>> dev = root_device_register(device_name);
>> if (IS_ERR(dev)) {
>> @@ -568,23 +571,22 @@ static int __init test_overflow_allocation(void)
>> return 1;
>> }
>>
>> - err |= test_kmalloc(NULL);
>> - err |= test_kmalloc_node(NULL);
>> - err |= test_kzalloc(NULL);
>> - err |= test_kzalloc_node(NULL);
>> - err |= test_kvmalloc(NULL);
>> - err |= test_kvmalloc_node(NULL);
>> - err |= test_kvzalloc(NULL);
>> - err |= test_kvzalloc_node(NULL);
>> - err |= test_vmalloc(NULL);
>> - err |= test_vmalloc_node(NULL);
>> - err |= test_vzalloc(NULL);
>> - err |= test_vzalloc_node(NULL);
>> - err |= test_devm_kmalloc(dev);
>> - err |= test_devm_kzalloc(dev);
>> + err |= check_allocation_overflow(kmalloc);
>> + err |= check_allocation_overflow(kmalloc_node);
>> + err |= check_allocation_overflow(kzalloc);
>> + err |= check_allocation_overflow(kzalloc_node);
>> + err |= check_allocation_overflow(__vmalloc);
>> + err |= check_allocation_overflow(kvmalloc);
>> + err |= check_allocation_overflow(kvmalloc_node);
>> + err |= check_allocation_overflow(kvzalloc);
>> + err |= check_allocation_overflow(kvzalloc_node);
>> + err |= check_allocation_overflow(devm_kmalloc);
>> + err |= check_allocation_overflow(devm_kzalloc);
>>
>> device_unregister(dev);

I'd prefer if such a local helper macro was defined immediately prior to
the sequence of uses, and then #undef'ed at the end.

Other than that:

Acked-by: Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx>