* [PATCH] x86: mkpiggy.c: fix resource leakage
@ 2013-10-07 22:16 Geyslan G. Bem
2013-10-07 22:36 ` H. Peter Anvin
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Geyslan G. Bem @ 2013-10-07 22:16 UTC (permalink / raw)
To: hpa, tglx, mingo, x86; +Cc: linux-kernel, kernel-br, Geyslan G. Bem
Even though the resource is released when the application is closed or
when returned from main function, modified to make it in accordance.
Now FILE pointer is always verified.
Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
---
arch/x86/boot/compressed/mkpiggy.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c
index 958a641..b669ab6 100644
--- a/arch/x86/boot/compressed/mkpiggy.c
+++ b/arch/x86/boot/compressed/mkpiggy.c
@@ -36,11 +36,12 @@ int main(int argc, char *argv[])
uint32_t olen;
long ilen;
unsigned long offs;
- FILE *f;
+ FILE *f = NULL;
+ int retval = 1;
if (argc < 2) {
fprintf(stderr, "Usage: %s compressed_file\n", argv[0]);
- return 1;
+ goto bail;
}
/* Get the information for the compressed kernel image first */
@@ -48,7 +49,7 @@ int main(int argc, char *argv[])
f = fopen(argv[1], "r");
if (!f) {
perror(argv[1]);
- return 1;
+ goto bail;
}
@@ -58,12 +59,11 @@ int main(int argc, char *argv[])
if (fread(&olen, sizeof(olen), 1, f) != 1) {
perror(argv[1]);
- return 1;
+ goto bail;
}
ilen = ftell(f);
olen = get_unaligned_le32(&olen);
- fclose(f);
/*
* Now we have the input (compressed) and output (uncompressed)
@@ -91,5 +91,9 @@ int main(int argc, char *argv[])
printf(".incbin \"%s\"\n", argv[1]);
printf("input_data_end:\n");
- return 0;
+ retval = 0;
+bail:
+ if (f)
+ fclose(f);
+ return retval;
}
--
1.8.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] x86: mkpiggy.c: fix resource leakage
2013-10-07 22:16 [PATCH] x86: mkpiggy.c: fix resource leakage Geyslan G. Bem
@ 2013-10-07 22:36 ` H. Peter Anvin
2013-10-07 22:44 ` H. Peter Anvin
2013-10-08 18:39 ` [tip:x86/cleanups] x86: mkpiggy.c: Explicitly close the output file tip-bot for Geyslan G. Bem
2 siblings, 0 replies; 5+ messages in thread
From: H. Peter Anvin @ 2013-10-07 22:36 UTC (permalink / raw)
To: Geyslan G. Bem; +Cc: tglx, mingo, x86, linux-kernel, kernel-br
On 10/07/2013 03:16 PM, Geyslan G. Bem wrote:
> Even though the resource is released when the application is closed or
> when returned from main function, modified to make it in accordance.
> Now FILE pointer is always verified.
>
> Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
Perhaps you could explain what problem is solved by this patch?
Note that for correctness we really should check the return value from
fclose().
-hpa
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86: mkpiggy.c: fix resource leakage
2013-10-07 22:16 [PATCH] x86: mkpiggy.c: fix resource leakage Geyslan G. Bem
2013-10-07 22:36 ` H. Peter Anvin
@ 2013-10-07 22:44 ` H. Peter Anvin
2013-10-07 23:41 ` Geyslan Gregório Bem
2013-10-08 18:39 ` [tip:x86/cleanups] x86: mkpiggy.c: Explicitly close the output file tip-bot for Geyslan G. Bem
2 siblings, 1 reply; 5+ messages in thread
From: H. Peter Anvin @ 2013-10-07 22:44 UTC (permalink / raw)
To: Geyslan G. Bem; +Cc: tglx, mingo, x86, linux-kernel, kernel-br
On 10/07/2013 03:16 PM, Geyslan G. Bem wrote:
> Even though the resource is released when the application is closed or
> when returned from main function, modified to make it in accordance.
> Now FILE pointer is always verified.
By the way, the subject is misleading - there is no resource leakage
since the program is terminated anyway.
-hpa
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86: mkpiggy.c: fix resource leakage
2013-10-07 22:44 ` H. Peter Anvin
@ 2013-10-07 23:41 ` Geyslan Gregório Bem
0 siblings, 0 replies; 5+ messages in thread
From: Geyslan Gregório Bem @ 2013-10-07 23:41 UTC (permalink / raw)
To: H. Peter Anvin; +Cc: tglx, mingo, x86, linux-kernel, kernel-br
Peter,
Yes, Really doesn't have leakage, I explained it. The changes are just
to cleanup the code following a secure pattern.
Geyslan Gregório Bem
hackingbits.com
2013/10/7 H. Peter Anvin <hpa@zytor.com>:
> On 10/07/2013 03:16 PM, Geyslan G. Bem wrote:
>> Even though the resource is released when the application is closed or
>> when returned from main function, modified to make it in accordance.
>> Now FILE pointer is always verified.
>
> By the way, the subject is misleading - there is no resource leakage
> since the program is terminated anyway.
>
> -hpa
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tip:x86/cleanups] x86: mkpiggy.c: Explicitly close the output file
2013-10-07 22:16 [PATCH] x86: mkpiggy.c: fix resource leakage Geyslan G. Bem
2013-10-07 22:36 ` H. Peter Anvin
2013-10-07 22:44 ` H. Peter Anvin
@ 2013-10-08 18:39 ` tip-bot for Geyslan G. Bem
2 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Geyslan G. Bem @ 2013-10-08 18:39 UTC (permalink / raw)
To: linux-tip-commits; +Cc: linux-kernel, geyslan, hpa, mingo, tglx, hpa
Commit-ID: 49449c30c4d1514486364d1e0dbea6938914b86f
Gitweb: http://git.kernel.org/tip/49449c30c4d1514486364d1e0dbea6938914b86f
Author: Geyslan G. Bem <geyslan@gmail.com>
AuthorDate: Mon, 7 Oct 2013 19:16:59 -0300
Committer: H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Tue, 8 Oct 2013 11:36:09 -0700
x86: mkpiggy.c: Explicitly close the output file
Even though the resource is released when the application is closed or
when returned from main function, modify the code to make it obvious,
and to keep static analysis tools from complaining.
Signed-off-by: Geyslan G. Bem <geyslan@gmail.com>
Link: http://lkml.kernel.org/r/1381184219-10985-1-git-send-email-geyslan@gmail.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
arch/x86/boot/compressed/mkpiggy.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c
index 958a641..b669ab6 100644
--- a/arch/x86/boot/compressed/mkpiggy.c
+++ b/arch/x86/boot/compressed/mkpiggy.c
@@ -36,11 +36,12 @@ int main(int argc, char *argv[])
uint32_t olen;
long ilen;
unsigned long offs;
- FILE *f;
+ FILE *f = NULL;
+ int retval = 1;
if (argc < 2) {
fprintf(stderr, "Usage: %s compressed_file\n", argv[0]);
- return 1;
+ goto bail;
}
/* Get the information for the compressed kernel image first */
@@ -48,7 +49,7 @@ int main(int argc, char *argv[])
f = fopen(argv[1], "r");
if (!f) {
perror(argv[1]);
- return 1;
+ goto bail;
}
@@ -58,12 +59,11 @@ int main(int argc, char *argv[])
if (fread(&olen, sizeof(olen), 1, f) != 1) {
perror(argv[1]);
- return 1;
+ goto bail;
}
ilen = ftell(f);
olen = get_unaligned_le32(&olen);
- fclose(f);
/*
* Now we have the input (compressed) and output (uncompressed)
@@ -91,5 +91,9 @@ int main(int argc, char *argv[])
printf(".incbin \"%s\"\n", argv[1]);
printf("input_data_end:\n");
- return 0;
+ retval = 0;
+bail:
+ if (f)
+ fclose(f);
+ return retval;
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-10-08 18:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-07 22:16 [PATCH] x86: mkpiggy.c: fix resource leakage Geyslan G. Bem
2013-10-07 22:36 ` H. Peter Anvin
2013-10-07 22:44 ` H. Peter Anvin
2013-10-07 23:41 ` Geyslan Gregório Bem
2013-10-08 18:39 ` [tip:x86/cleanups] x86: mkpiggy.c: Explicitly close the output file tip-bot for Geyslan G. Bem
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).