* [PATCH v3] selftests/capabilities: Fix possible file leak in copy_fromat_to
@ 2024-06-30 13:00 Ma Ke
2024-07-01 6:12 ` Muhammad Usama Anjum
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ma Ke @ 2024-06-30 13:00 UTC (permalink / raw)
To: shuah, usama.anjum, swarupkotikalapudi, make24, amer.shanawany,
kees, akpm, luto
Cc: linux-kselftest, linux-kernel
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. Improve the checking
of 'from' additionally.
Fixes: 32ae976ed3b5 ("selftests/capabilities: Add tests for capability evolution")
Signed-off-by: Ma Ke <make24@iscas.ac.cn>
---
Changes in v3:
- Thank you for your interest in our vulnerability detection method. We
extract vulnerability characteristics from a known vulnerability and match
the same characteristics in the project code. As our work is still in
progress, we are not able to disclose it at this time. Appreciate your
understanding, we could better focus on the potential vulnerability itself.
Reference link: https://lore.kernel.org/all/20240510003424.2016914-1-samasth.norway.ananda@oracle.com/
Changes in v2:
- modified the patch according to suggestions;
- found by customized static analysis tool.
---
tools/testing/selftests/capabilities/test_execve.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/capabilities/test_execve.c b/tools/testing/selftests/capabilities/test_execve.c
index 47bad7ddc5bc..6406ab6aa1f5 100644
--- a/tools/testing/selftests/capabilities/test_execve.c
+++ b/tools/testing/selftests/capabilities/test_execve.c
@@ -145,10 +145,14 @@ static void chdir_to_tmpfs(void)
static void copy_fromat_to(int fromfd, const char *fromname, const char *toname)
{
int from = openat(fromfd, fromname, O_RDONLY);
- if (from == -1)
+ if (from < 0)
ksft_exit_fail_msg("open copy source - %s\n", strerror(errno));
int to = open(toname, O_CREAT | O_WRONLY | O_EXCL, 0700);
+ if (to < 0) {
+ close(from);
+ ksft_exit_fail_msg("open copy destination - %s\n", strerror(errno));
+ }
while (true) {
char buf[4096];
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] selftests/capabilities: Fix possible file leak in copy_fromat_to
2024-06-30 13:00 [PATCH v3] selftests/capabilities: Fix possible file leak in copy_fromat_to Ma Ke
@ 2024-07-01 6:12 ` Muhammad Usama Anjum
2024-07-01 8:01 ` Markus Elfring
2024-07-02 16:22 ` Shuah Khan
2 siblings, 0 replies; 4+ messages in thread
From: Muhammad Usama Anjum @ 2024-07-01 6:12 UTC (permalink / raw)
To: Ma Ke, shuah, swarupkotikalapudi, amer.shanawany, kees, akpm,
luto
Cc: Muhammad Usama Anjum, linux-kselftest, linux-kernel
Thanks for the patch!
On 6/30/24 6:00 PM, 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. Improve the checking
> of 'from' additionally.
>
> Fixes: 32ae976ed3b5 ("selftests/capabilities: Add tests for capability evolution")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
LGTM
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
> ---
> Changes in v3:
> - Thank you for your interest in our vulnerability detection method. We
> extract vulnerability characteristics from a known vulnerability and match
> the same characteristics in the project code. As our work is still in
> progress, we are not able to disclose it at this time. Appreciate your
> understanding, we could better focus on the potential vulnerability itself.
> Reference link: https://lore.kernel.org/all/20240510003424.2016914-1-samasth.norway.ananda@oracle.com/
> Changes in v2:
> - modified the patch according to suggestions;
> - found by customized static analysis tool.
> ---
> tools/testing/selftests/capabilities/test_execve.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/capabilities/test_execve.c b/tools/testing/selftests/capabilities/test_execve.c
> index 47bad7ddc5bc..6406ab6aa1f5 100644
> --- a/tools/testing/selftests/capabilities/test_execve.c
> +++ b/tools/testing/selftests/capabilities/test_execve.c
> @@ -145,10 +145,14 @@ static void chdir_to_tmpfs(void)
> static void copy_fromat_to(int fromfd, const char *fromname, const char *toname)
> {
> int from = openat(fromfd, fromname, O_RDONLY);
> - if (from == -1)
> + if (from < 0)
> ksft_exit_fail_msg("open copy source - %s\n", strerror(errno));
>
> int to = open(toname, O_CREAT | O_WRONLY | O_EXCL, 0700);
> + if (to < 0) {
> + close(from);
> + ksft_exit_fail_msg("open copy destination - %s\n", strerror(errno));
> + }
>
> while (true) {
> char buf[4096];
--
BR,
Muhammad Usama Anjum
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] selftests/capabilities: Fix possible file leak in copy_fromat_to
2024-06-30 13:00 [PATCH v3] selftests/capabilities: Fix possible file leak in copy_fromat_to Ma Ke
2024-07-01 6:12 ` Muhammad Usama Anjum
@ 2024-07-01 8:01 ` Markus Elfring
2024-07-02 16:22 ` Shuah Khan
2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2024-07-01 8:01 UTC (permalink / raw)
To: Ma Ke, linux-kselftest, Amer Al Shanawany, Andrew Morton,
Andy Lutomirski, Kees Cook, Muhammad Usama Anjum, Shuah Khan,
Swarup Laxman Kotiaklapudi
Cc: kernel-janitors, LKML, Julia Lawall
> … openat() and open() initialize
> 'from' and 'to', and only 'from' validated with 'if' statement.
Why do you find such information helpful?
> If the
> initialization of variable 'to' fails,
The variable assignment will usually succeed.
A stored return value would eventually indicate a failed function call.
> we should better check the value
> of 'to' and close 'from' to avoid possible file leak. Improve the checking
> of 'from' additionally.
Please split desired changes into separate update steps.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.10-rc6#n168
How do you think about to use a summary phrase like “Complete error handling
in copy_fromat_to()”?
Under which circumstances would you become interested to take remaining
patch review concerns better into account?
…
> ---
> Changes in v3:
> - Thank you for your interest in our vulnerability detection method. We
> extract vulnerability characteristics from a known vulnerability and match
> the same characteristics in the project code. As our work is still in
> progress, we are not able to disclose it at this time. …
* In which time range do you plan to publish an official announcement?
* Will similar software research approaches be discussed further?
> - found by customized static analysis tool.
> ---
Would you like to replace a duplicate marker line by a blank line?
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] selftests/capabilities: Fix possible file leak in copy_fromat_to
2024-06-30 13:00 [PATCH v3] selftests/capabilities: Fix possible file leak in copy_fromat_to Ma Ke
2024-07-01 6:12 ` Muhammad Usama Anjum
2024-07-01 8:01 ` Markus Elfring
@ 2024-07-02 16:22 ` Shuah Khan
2 siblings, 0 replies; 4+ messages in thread
From: Shuah Khan @ 2024-07-02 16:22 UTC (permalink / raw)
To: Ma Ke, shuah, usama.anjum, swarupkotikalapudi, amer.shanawany,
kees, akpm, luto
Cc: linux-kselftest, linux-kernel, Shuah Khan
On 6/30/24 07:00, 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. Improve the checking
> of 'from' additionally.
>
> Fixes: 32ae976ed3b5 ("selftests/capabilities: Add tests for capability evolution")
> Signed-off-by: Ma Ke <make24@iscas.ac.cn>
> ---
> Changes in v3:
> - Thank you for your interest in our vulnerability detection method. We
> extract vulnerability characteristics from a known vulnerability and match
> the same characteristics in the project code. As our work is still in
> progress, we are not able to disclose it at this time. Appreciate your
> understanding, we could better focus on the potential vulnerability itself.
> Reference link: https://lore.kernel.org/all/20240510003424.2016914-1-samasth.norway.ananda@oracle.com/
Sorry it is a NACK - without more details on the tool and warning,
I can't accept this patch.
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-07-02 16:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-30 13:00 [PATCH v3] selftests/capabilities: Fix possible file leak in copy_fromat_to Ma Ke
2024-07-01 6:12 ` Muhammad Usama Anjum
2024-07-01 8:01 ` Markus Elfring
2024-07-02 16:22 ` Shuah Khan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox