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] [day] [month] [year] [list]
Message-ID: <67828a44-9730-45fd-bc4e-73075cd3dc4e@linuxfoundation.org>
Date: Wed, 26 Jun 2024 13:37:06 -0600
From: Shuah Khan <skhan@...uxfoundation.org>
To: Ma Ke <make24@...as.ac.cn>, shuah@...nel.org, usama.anjum@...labora.com,
 amer.shanawany@...il.com, swarupkotikalapudi@...il.com, kees@...nel.org,
 luto@...nel.org, akpm@...ux-foundation.org
Cc: linux-kselftest@...r.kernel.org, linux-kernel@...r.kernel.org,
 Shuah Khan <skhan@...uxfoundation.org>
Subject: Re: [PATCH] selftests/capabilities: Fix possible file leak in
 copy_fromat_to

On 6/26/24 13:33, Shuah Khan wrote:
> On 6/26/24 01:20, Ma Ke wrote:
>> The open() function returns -1 on error. openat() and open() initialize
>> 'from' and 'to', and only 'from' validated with 'if' statement. If the
>> initialization of variable 'to' fails, we should better check the value
>> of 'to' and close 'from' to avoid possible file leak.
>>
>> Fixes: 32ae976ed3b5 ("selftests/capabilities: Add tests for capability evolution")
>> Signed-off-by: Ma Ke <make24@...as.ac.cn>
>> ---
>> Found this error through static analysis.
> 
> Please add this line to change adding details about the tool you used
> to find this problem.
> 
>> ---
>>   tools/testing/selftests/capabilities/test_execve.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/tools/testing/selftests/capabilities/test_execve.c b/tools/testing/selftests/capabilities/test_execve.c
>> index 47bad7ddc5bc..de187eff177d 100644
>> --- a/tools/testing/selftests/capabilities/test_execve.c
>> +++ b/tools/testing/selftests/capabilities/test_execve.c
>> @@ -149,6 +149,10 @@ static void copy_fromat_to(int fromfd, const char *fromname, const char *toname)
>>           ksft_exit_fail_msg("open copy source - %s\n", strerror(errno));
>>       int to = open(toname, O_CREAT | O_WRONLY | O_EXCL, 0700);
>> +    if (to == -1) {
> 
> Changing this check to < instead of checking for just -1 can catch
> other error returns.

While you are fining this, can you fix this as well:

  int from = openat(fromfd, fromname, O_RDONLY);
         if (from == -1)
                 ksft_exit_fail_msg("open copy source - %s\n", strerror(errno));

Same change to check for <

thanks,
-- Shuah




Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ