lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 6 Apr 2023 10:01:33 +0800
From:   Feng Jiang <jiangfeng@...inos.cn>
To:     David Hildenbrand <david@...hat.com>, akpm@...ux-foundation.org,
        shuah@...nel.org
Cc:     linux-mm@...ck.org, linux-kselftest@...r.kernel.org,
        linux-kernel@...r.kernel.org, Ming Xie <xieming@...inos.cn>
Subject: Re: [PATCH] selftests/mm: fix memory leak in child_memcmp_fn

On 2023/4/4 15:31, David Hildenbrand wrote:
> On 04.04.23 05:12, Feng Jiang wrote:
>> The allocated memory should be freed on return.
>>
>> Signed-off-by: Feng Jiang <jiangfeng@...inos.cn>
>> Suggested-by: Ming Xie <xieming@...inos.cn>
>> ---
>>   tools/testing/selftests/mm/cow.c | 9 ++++++++-
>>   1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/testing/selftests/mm/cow.c 
>> b/tools/testing/selftests/mm/cow.c
>> index 0eb2e8180aa5..c0dd2dfca51b 100644
>> --- a/tools/testing/selftests/mm/cow.c
>> +++ b/tools/testing/selftests/mm/cow.c
>> @@ -162,6 +162,10 @@ static int child_memcmp_fn(char *mem, size_t size,
>>   {
>>       char *old = malloc(size);
>>       char buf;
>> +    int ret;
>> +
>> +    if (!old)
>> +        return -ENOMEM;
>>         /* Backup the original content. */
>>       memcpy(old, mem, size);
>> @@ -172,7 +176,10 @@ static int child_memcmp_fn(char *mem, size_t size,
>>           ;
>>         /* See if we still read the old values. */
>> -    return memcmp(old, mem, size);
>> +    ret = memcmp(old, mem, size);
>> +    free(old);
>> +
>> +    return ret;
>>   }
>>     static int child_vmsplice_memcmp_fn(char *mem, size_t size,
>
> NAK, the whole point of this function is that the child process will 
> exit immediately after executing this function, cleaning up 
> automatically.
>
Hi David, thanks very much for your review and I think you are right.

While the OS provides a cleanup mechanism to underwrite this, I think it 
makes sense for the application to ensure that its own logic is complete 
and correct.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ