drivers/xen/grant-table.c: Be sure of unsigned value never comparing with 0
PATCH 1/1 drivers/xen/grant-table.c: Be sure of unsigned value never comparing with 0
In grow_gnttab_list(), 'i' is 'unsigned int', and 'nr_glist_frames' may be 0 because 'nr_grant_frames' may be 0. So 'i' may never be less than 'nr_glist_frames' in failure processing, which cause infinite looping.
--- drivers/xen/grant-table.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/grant-table.c +2 -2
@@ -592,8 +592,8 @@ static int grow_gnttab_list(unsigned int more_frames)return 0 ; grow_nomem: -for ( ; i >= nr_glist_frames; i--) -free_page ((unsigned long ) gnttab_list[i]); +while (i > nr_glist_frames) +free_page ((unsigned long ) gnttab_list[--i]);return -ENOMEM ; }
Signature · 1 line
1.9.3
Quoted 3 lines · Chen Gang
In
grow_gnttab_list(), 'i' is 'unsigned int', and 'nr_glist_frames' may be 0 because 'nr_grant_frames' may be 0. So 'i' may never be less than 'nr_glist_frames' in failure processing, which cause infinite looping.
nr_grant_frames is at least 1. See gnttab_init().
drivers/xen/grant-table.c static int grow_gnttab_list(unsigned int more_frames) · line 596
Quoted 10 lines
drivers/xen/grant-table.c +2
-2@@ -592,8 +592,8 @@ static int grow_gnttab_list(unsigned int more_frames)return 0 ; grow_nomem: -for ( ; i >= nr_glist_frames; i--) -free_page ((unsigned long ) gnttab_list[i]); +while (i > nr_glist_frames) +free_page ((unsigned long ) gnttab_list[--i]);
while (i-- > nr_glist_frames)
...
Would have been better.
David
Quoted 3 lines · Chen Gang
In
grow_gnttab_list(), 'i' is 'unsigned int', and 'nr_glist_frames' may be 0 because 'nr_grant_frames' may be 0. So 'i' may never be less than 'nr_glist_frames' in failure processing, which cause infinite looping.
nr_grant_frames is at least 1. See gnttab_init().
drivers/xen/grant-table.c static int grow_gnttab_list(unsigned int more_frames) · line 596
Quoted 10 lines
drivers/xen/grant-table.c +2
-2@@ -592,8 +592,8 @@ static int grow_gnttab_list(unsigned int more_frames)return 0 ; grow_nomem: -for ( ; i >= nr_glist_frames; i--) -free_page ((unsigned long ) gnttab_list[i]); +while (i > nr_glist_frames) +free_page ((unsigned long ) gnttab_list[--i]);
while (i-- > nr_glist_frames)
...
Would have been better.
David
Quoted 7 lines · David Vrabel
Quoted 3 lines · Chen Gang
In
grow_gnttab_list(), 'i' is 'unsigned int', and 'nr_glist_frames' may be 0 because 'nr_grant_frames' may be 0. So 'i' may never be less than 'nr_glist_frames' in failure processing, which cause infinite looping.
nr_grant_framesis at least 1. Seegnttab_init().
OK, thanks, that sounds reasonable to me, it is not a real wold bug, it is my fault. :-)
Quoted 12 lines
drivers/xen/grant-table.c static int grow_gnttab_list(unsigned int more_frames) · line 596
Quoted 10 lines
drivers/xen/grant-table.c +2
-2@@ -592,8 +592,8 @@ static int grow_gnttab_list(unsigned int more_frames)return 0 ; grow_nomem: -for ( ; i >= nr_glist_frames; i--) -free_page ((unsigned long ) gnttab_list[i]); +while (i > nr_glist_frames) +free_page ((unsigned long ) gnttab_list[--i]);while (i-- >
nr_glist_frames)
Quoted 4 lines
...Would have been better.
OK, thanks, that sounds reasonable to me.
If necessary to send patch v2 (change comments and contents), please let me know, and I shall send.
Thanks.
Signature · 3 lines
Chen Gang Open share and attitude like air water and life which God blessed
Quoted 7 lines · David Vrabel
Quoted 3 lines · Chen Gang
In
grow_gnttab_list(), 'i' is 'unsigned int', and 'nr_glist_frames' may be 0 because 'nr_grant_frames' may be 0. So 'i' may never be less than 'nr_glist_frames' in failure processing, which cause infinite looping.
nr_grant_framesis at least 1. Seegnttab_init().
OK, thanks, that sounds reasonable to me, it is not a real wold bug, it is my fault. :-)
Quoted 12 lines
drivers/xen/grant-table.c static int grow_gnttab_list(unsigned int more_frames) · line 596
Quoted 10 lines
drivers/xen/grant-table.c +2
-2@@ -592,8 +592,8 @@ static int grow_gnttab_list(unsigned int more_frames)return 0 ; grow_nomem: -for ( ; i >= nr_glist_frames; i--) -free_page ((unsigned long ) gnttab_list[i]); +while (i > nr_glist_frames) +free_page ((unsigned long ) gnttab_list[--i]);while (i-- >
nr_glist_frames)
Quoted 4 lines
...Would have been better.
OK, thanks, that sounds reasonable to me.
If necessary to send patch v2 (change comments and contents), please let me know, and I shall send.
Thanks.
Signature · 3 lines
Chen Gang Open share and attitude like air water and life which God blessed
David Vrabel
AppliedQuoted 26 lines · Chen Gang
Quoted 7 lines · David Vrabel
Quoted 3 lines · Chen Gang
In
grow_gnttab_list(), 'i' is 'unsigned int', and 'nr_glist_frames' may be 0 because 'nr_grant_frames' may be 0. So 'i' may never be less than 'nr_glist_frames' in failure processing, which cause infinite looping.
nr_grant_framesis at least 1. Seegnttab_init().OK, thanks, that sounds reasonable to me, it is not a real wold bug, it is my fault. :-)
Quoted 14 lines
drivers/xen/grant-table.c static int grow_gnttab_list(unsigned int more_frames) · line 596
Quoted 10 lines
drivers/xen/grant-table.c +2
-2@@ -592,8 +592,8 @@ static int grow_gnttab_list(unsigned int more_frames)return 0 ; grow_nomem: -for ( ; i >= nr_glist_frames; i--) -free_page ((unsigned long ) gnttab_list[i]); +while (i > nr_glist_frames) +free_page ((unsigned long ) gnttab_list[--i]);while (i-- >
nr_glist_frames)...
Quoted 7 lines
Quoted 2 lines
Would have been better.
OK, thanks, that sounds reasonable to me.
If necessary to send patch v2 (change comments and contents), please let me know, and I shall send.
Applied to devel/for-linus-3.18 with this description:
xen/grant-table: refactor error cleanup in grow_gnttab_list()
The cleanup loop in grow_gnttab_list() is safe from the underflow of the unsigned 'i' since nr_glist_frames is >= 1, but refactor it anyway.
Thanks.
David
David Vrabel
AppliedQuoted 26 lines · Chen Gang
Quoted 7 lines · David Vrabel
Quoted 3 lines · Chen Gang
In
grow_gnttab_list(), 'i' is 'unsigned int', and 'nr_glist_frames' may be 0 because 'nr_grant_frames' may be 0. So 'i' may never be less than 'nr_glist_frames' in failure processing, which cause infinite looping.
nr_grant_framesis at least 1. Seegnttab_init().OK, thanks, that sounds reasonable to me, it is not a real wold bug, it is my fault. :-)
Quoted 14 lines
drivers/xen/grant-table.c static int grow_gnttab_list(unsigned int more_frames) · line 596
Quoted 10 lines
drivers/xen/grant-table.c +2
-2@@ -592,8 +592,8 @@ static int grow_gnttab_list(unsigned int more_frames)return 0 ; grow_nomem: -for ( ; i >= nr_glist_frames; i--) -free_page ((unsigned long ) gnttab_list[i]); +while (i > nr_glist_frames) +free_page ((unsigned long ) gnttab_list[--i]);while (i-- >
nr_glist_frames)...
Quoted 7 lines
Quoted 2 lines
Would have been better.
OK, thanks, that sounds reasonable to me.
If necessary to send patch v2 (change comments and contents), please let me know, and I shall send.
Applied to devel/for-linus-3.18 with this description:
xen/grant-table: refactor error cleanup in grow_gnttab_list()
The cleanup loop in grow_gnttab_list() is safe from the underflow of the unsigned 'i' since nr_glist_frames is >= 1, but refactor it anyway.
Thanks.
David
Quoted 9 lines · David Vrabel
Applied to devel/for-linus-3.18 with this description:
xen/grant-table: refactor error cleanup in
grow_gnttab_list()The cleanup loop in
grow_gnttab_list()is safe from the underflow of the unsigned 'i' sincenr_glist_framesis >= 1, but refactor it anyway.
OK, thank you very much for your encouragement! And next, I shall try to provide another patches for Xen (hope I can finish within this month). And I should be more careful about the patches which I shall send.
Also I want to consult: "Is there a common test for Xen"? If there is, please let me know, and I should try to perform the common test before send any patches.
Welcome any additional ideas, suggestions, and completions.
Thanks.
Signature · 3 lines
Chen Gang Open, share, and attitude like air, water, and life which God blessed
Quoted 9 lines · David Vrabel
Applied to devel/for-linus-3.18 with this description:
xen/grant-table: refactor error cleanup in
grow_gnttab_list()The cleanup loop in
grow_gnttab_list()is safe from the underflow of the unsigned 'i' sincenr_glist_framesis >= 1, but refactor it anyway.
OK, thank you very much for your encouragement! And next, I shall try to provide another patches for Xen (hope I can finish within this month). And I should be more careful about the patches which I shall send.
Also I want to consult: "Is there a common test for Xen"? If there is, please let me know, and I should try to perform the common test before send any patches.
Welcome any additional ideas, suggestions, and completions.
Thanks.
Signature · 3 lines
Chen Gang Open, share, and attitude like air, water, and life which God blessed