Skip to contentSkip to conversation

swapfile: swap_info_get: Check for swap_info[type] == NULL

PATCH In review Kautuk Consul 1 participant 2 messages Dec 26, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 swapfile: swap_info_get: Check for swap_info[type] == NULL

From: Kautuk Consul <[email protected]>

If the swapfile type encoded within entry.val is corrupted in such a way that the swap_info[type] == NULL, then the code in swap_info_get will cause a NULL pointer exception.

Assuming that the code in swap_info_get attempts to validate the swapfile type by checking its range, another bad_nofile check would be to check for check whether the swap_info[type] pointer is NULL.

Adding a NULL check for swap_info[type] to be reagrded as a "bad_nofile" error scenario.

---
 mm/swapfile.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
mm/swapfile.c +2 -0
index b1cd120..7bdbe91 100644
@@ -483,6 +483,8 @@ static struct swap_info_struct *swap_info_get(swp_entry_t entry)
 	if (type >= nr_swapfiles)
 		goto bad_nofile;
 	p = swap_info[type];
+	if (!p)
+		goto bad_nofile;
 	if (!(p->flags & SWP_USED))
 		goto bad_device;
 	offset = swp_offset(entry);
Signature · 8 lines
1.7.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

Hi,

Sorry, please ignore the patch file below.

I made a mistake in understanding the code logic.
I now understand that the first "bad_nofile" validation check
is good enough for checking the validity of the value in the "type" variable.

Quoted 32 lines · Kautuk Consul

From: Kautuk Consul <[email protected]>

If the swapfile type encoded within entry.val is corrupted in such a way that the swap_info[type] == NULL, then the code in swap_info_get will cause a NULL pointer exception.

Assuming that the code in swap_info_get attempts to validate the swapfile type by checking its range, another bad_nofile check would be to check for check whether the swap_info[type] pointer is NULL.

Adding a NULL check for swap_info[type] to be reagrded as a "bad_nofile" error scenario.

---
 mm/swapfile.c |    2 ++

 1 files changed, 2 insertions(+), 0 deletions(-)
mm/swapfile.c +2 -1
index b1cd120..7bdbe91 100644
@@ -483,6 +483,8 @@ static struct swap_info_struct *swap_info_get(swp_entry_t entry)
        if (type >= nr_swapfiles)
                goto bad_nofile;
        p = swap_info[type];
+       if (!p)
+               goto bad_nofile;
        if (!(p->flags & SWP_USED))
                goto bad_device;
        offset = swp_offset(entry);
--
Quoted 2 lines

1.7.6

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>