makedumpfile: Fix the variable pfn_needed leaking
Subsystems (2)
PATCH 1/1 makedumpfile: Fix the variable pfn_needed leaking
If the page pfn calculated by read_from_splitblock_table is bigger than pfn_needed, the variable pfn_needed will leak.
makedumpfile cannot assign the pfn averagely bacause of condition pfn_needed invalid.
--- makedumpfile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
makedumpfile.c +3 -2
@@ -8415,7 +8415,7 @@ calculate_end_pfn_by_splitblock(mdf_pfn_t start_pfn,return info->max_mapnr;mdf_pfn_t end_pfn; -long long pfn_needed, offset; +long long pfn_needed, offset, per_splitblock_pfn;char *splitblock_value_offset; pfn_needed = info->num_dumpable / info->num_dumpfile;
@@ -8424,7 +8424,8 @@ calculate_end_pfn_by_splitblock(mdf_pfn_t start_pfn, end_pfn = start_pfn;while (*cur_splitblock_num < splitblock->num && pfn_needed >0 ) { - pfn_needed -=read_from_splitblock_table (splitblock_value_offset); + per_splitblock_pfn =read_from_splitblock_table (splitblock_value_offset); + pfn_needed = pfn_needed < per_splitblock_pfn ?0 : pfn_needed - per_splitblock_pfn; splitblock_value_offset += splitblock->entry_size; ++*cur_splitblock_num; }
Signature · 7 lines
1.8.3.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Quoted 25 lines · Minfei Huang
If the page pfn calculated by
read_from_splitblock_tableis bigger thanpfn_needed, the variablepfn_neededwill leak.makedumpfile cannot assign the pfn averagely bacause of condition
pfn_neededinvalid.Signed-off-by Minfei Huang<[email protected]>--- makedumpfile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)makedumpfile.c +1
-1@@ -8415,7 +8415,7 @@ calculate_end_pfn_by_splitblock(mdf_pfn_t start_pfn,return info->max_mapnr;mdf_pfn_t end_pfn; -long long pfn_needed, offset; +long long pfn_needed, offset, per_splitblock_pfn;char *splitblock_value_offset; pfn_needed = info->num_dumpable / info->num_dumpfile;
makedumpfile.c calculate_end_pfn_by_splitblock(mdf_pfn_t start_pfn, · line 8431
Quoted 9 lines
makedumpfile.c +2
-1@@ -8424,7 +8424,8 @@ calculate_end_pfn_by_splitblock(mdf_pfn_t start_pfn, end_pfn = start_pfn;while (*cur_splitblock_num< splitblock->num&& pfn_needed>0 ) { - pfn_needed -=read_from_splitblock_table (splitblock_value_offset); + per_splitblock_pfn =read_from_splitblock_table (splitblock_value_offset); + pfn_needed = pfn_needed< per_splitblock_pfn ?0 : pfn_needed - per_splitblock_pfn; splitblock_value_offset += splitblock->entry_size; ++*cur_splitblock_num; }
Hello Huang,
Actually, pfn_needed is used to indicate whether the dumpfile have enough pfn or not. It doesn't matter whether pfn_needed == 0 or pfn_needed < 0.
I know what you want to express. Maybe you can get some useful information at
http://lists.infradead.org/pipermail/kexec/2014-October/012805.html
Signature · 7 lines
Thanks Zhou Wenjian _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Quoted 25 lines · Minfei Huang
If the page pfn calculated by
read_from_splitblock_tableis bigger thanpfn_needed, the variablepfn_neededwill leak.makedumpfile cannot assign the pfn averagely bacause of condition
pfn_neededinvalid.Signed-off-by Minfei Huang <[email protected]>--- makedumpfile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)makedumpfile.c +1
-1@@ -8415,7 +8415,7 @@ calculate_end_pfn_by_splitblock(mdf_pfn_t start_pfn,return info->max_mapnr;mdf_pfn_t end_pfn; -long long pfn_needed, offset; +long long pfn_needed, offset, per_splitblock_pfn;char *splitblock_value_offset; pfn_needed = info->num_dumpable / info->num_dumpfile;
makedumpfile.c calculate_end_pfn_by_splitblock(mdf_pfn_t start_pfn, · line 8428
Quoted 6 lines
makedumpfile.c +2
-1@@ -8424,7 +8424,8 @@ calculate_end_pfn_by_splitblock(mdf_pfn_t start_pfn, end_pfn = start_pfn;while (*cur_splitblock_num < splitblock->num && pfn_needed >0 ) { - pfn_needed -=read_from_splitblock_table (splitblock_value_offset); + per_splitblock_pfn =read_from_splitblock_table (splitblock_value_offset); + pfn_needed = pfn_needed < per_splitblock_pfn ?0 : pfn_needed - per_splitblock_pfn;
Hi, Wenjiang!
Sorry, my emall client didnot receive the mail by you, so I reply it here.
The split->table is an array to record the pfn count which we need dump. And the memory is divided by the size of info->splitblock_size, the pfn count in each entry will be stored in the entry of split->table.
For the purpose, we want to average allocation to the pfns.
Here is a case:
There are 5 entries in the split->table, and the value is 4, 6, 4, 5, 5. We want to split four pieces to write to four files, and every file will be write 6 pfns.
Using the function calculate_end_pfn_by_splitblock, the first file will be assigned all of the pfns(24 pfns).
pfn_needed is 6((4+6+4+5+5) / 4) when entry the function.
By the end of first loop, the variable pfn_needed = 2(6 - 4). Then move on, the variable will leak to become huge number by the end of second loop, because the return value of function read_from_splitblock_table is 6. The variable pfn_needed is ~4(2 - 6), it is huge.
And the loop will break util *cur_splitblock_num == splitblock->num.
For above case, it is no sense to use split function, so we should add the condition whether pfn_needed is bigger than the value of read_from_splitblock_table.
Thanks
Minfei
Quoted 6 lines
makedumpfile.c +0
-0splitblock_value_offset += splitblock->entry_size; ++*cur_splitblock_num; }Signature · 1 line
1.8.3.1
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 50 lines · Minfei Huang
Quoted 25 lines · Minfei Huang
If the page pfn calculated by
read_from_splitblock_tableis bigger thanpfn_needed, the variablepfn_neededwill leak.makedumpfile cannot assign the pfn averagely bacause of condition
pfn_neededinvalid.Signed-off-by Minfei Huang<[email protected]>--- makedumpfile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)makedumpfile.c +1
-1@@ -8415,7 +8415,7 @@ calculate_end_pfn_by_splitblock(mdf_pfn_t start_pfn,return info->max_mapnr;mdf_pfn_t end_pfn; -long long pfn_needed, offset; +long long pfn_needed, offset, per_splitblock_pfn;char *splitblock_value_offset; pfn_needed = info->num_dumpable / info->num_dumpfile;makedumpfile.c calculate_end_pfn_by_splitblock(mdf_pfn_t start_pfn, · line 8428
Quoted 6 lines
makedumpfile.c +2
-1@@ -8424,7 +8424,8 @@ calculate_end_pfn_by_splitblock(mdf_pfn_t start_pfn, end_pfn = start_pfn;while (*cur_splitblock_num< splitblock->num&& pfn_needed>0 ) { - pfn_needed -=read_from_splitblock_table (splitblock_value_offset); + per_splitblock_pfn =read_from_splitblock_table (splitblock_value_offset); + pfn_needed = pfn_needed< per_splitblock_pfn ?0 : pfn_needed - per_splitblock_pfn;Hi, Wenjiang!
Sorry, my emall client didnot receive the mail by you, so I reply it here.
The
split->tableis an array to record the pfn count which we need dump. And the memory is divided by the size ofinfo->splitblock_size, the pfn count in each entry will be stored in the entry ofsplit->table.For the purpose, we want to average allocation to the pfns.
Here is a case:
There are 5 entries in thesplit->table, and the value is 4, 6, 4, 5, 5. We want to split four pieces to write to four files, and every file will be write 6 pfns.
Using the functioncalculate_end_pfn_by_splitblock, the first file will be assigned all of the pfns(24 pfns).
Quoted 6 lines
pfn_neededis 6((4+6+4+5+5) / 4) when entry the function.
By the end of first loop, the variablepfn_needed= 2(6 - 4). Then move on, the variable will leak to become huge number by the end of second loop, because the return value of functionread_from_splitblock_tableis 6. The variablepfn_neededis ~4(2 - 6), it is huge.
And the loop will break util*cur_splitblock_num==splitblock->num.
pfn_needed is (long long). If it is -4, won't the loop break?
Quoted 13 lines
For above case, it is no sense to use split function, so we should add the condition whether
pfn_neededis bigger than the value ofread_from_splitblock_table.Thanks
MinfeiQuoted 6 lines
makedumpfile.c +0
-1splitblock_value_offset += splitblock->entry_size; ++*cur_splitblock_num; } --1.8.3.1
Signature · 7 lines
Thanks Zhou Wenjian _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Quoted 51 lines · Wenjian/周文剑
Quoted 50 lines · Minfei Huang
Quoted 25 lines · Minfei Huang
If the page pfn calculated by
read_from_splitblock_tableis bigger thanpfn_needed, the variablepfn_neededwill leak.makedumpfile cannot assign the pfn averagely bacause of condition
pfn_neededinvalid.Signed-off-by Minfei Huang<[email protected]>--- makedumpfile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)makedumpfile.c +1
-1@@ -8415,7 +8415,7 @@ calculate_end_pfn_by_splitblock(mdf_pfn_t start_pfn,return info->max_mapnr;mdf_pfn_t end_pfn; -long long pfn_needed, offset; +long long pfn_needed, offset, per_splitblock_pfn;char *splitblock_value_offset; pfn_needed = info->num_dumpable / info->num_dumpfile;makedumpfile.c calculate_end_pfn_by_splitblock(mdf_pfn_t start_pfn, · line 8428
Quoted 6 lines
makedumpfile.c +2
-1@@ -8424,7 +8424,8 @@ calculate_end_pfn_by_splitblock(mdf_pfn_t start_pfn, end_pfn = start_pfn;while (*cur_splitblock_num< splitblock->num&& pfn_needed>0 ) { - pfn_needed -=read_from_splitblock_table (splitblock_value_offset); + per_splitblock_pfn =read_from_splitblock_table (splitblock_value_offset); + pfn_needed = pfn_needed< per_splitblock_pfn ?0 : pfn_needed - per_splitblock_pfn;Hi, Wenjiang!
Sorry, my emall client didnot receive the mail by you, so I reply it here.
The
split->tableis an array to record the pfn count which we need dump. And the memory is divided by the size ofinfo->splitblock_size, the pfn count in each entry will be stored in the entry ofsplit->table.For the purpose, we want to average allocation to the pfns.
Here is a case:
There are 5 entries in thesplit->table, and the value is 4, 6, 4, 5, 5. We want to split four pieces to write to four files, and every file will be write 6 pfns.
Using the functioncalculate_end_pfn_by_splitblock, the first file will be assigned all of the pfns(24 pfns).
Quoted 8 lines
Quoted 6 lines
pfn_neededis 6((4+6+4+5+5) / 4) when entry the function.
By the end of first loop, the variablepfn_needed= 2(6 - 4). Then move on, the variable will leak to become huge number by the end of second loop, because the return value of functionread_from_splitblock_tableis 6. The variablepfn_neededis ~4(2 - 6), it is huge.
And the loop will break util*cur_splitblock_num==splitblock->num.
pfn_neededis (long long). If it is -4, won't the loop break?
Oops!
Sorry, I got a mistake. You are right.
Quoted 6 lines
Quoted 6 lines
For above case, it is no sense to use split function, so we should add the condition whether
pfn_neededis bigger than the value ofread_from_splitblock_table.
Quoted 18 lines
Quoted 8 lines
Thanks
MinfeiQuoted 6 lines
makedumpfile.c +0
-1splitblock_value_offset += splitblock->entry_size; ++*cur_splitblock_num; } --1.8.3.1
Signature · 7 lines
Thanks Zhou Wenjian _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec