Skip to contentSkip to conversation

mm, swap: Fix swap space leak in error path of swap_free_entries()

PATCH Applied Huang, Ying 3 participants 4 messages Apr 21, 2017 – Apr 25, 2017

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

PATCH 1/1 mm, swap: Fix swap space leak in error path of swap_free_entries()

From: Huang Ying <[email protected]>

In swapcache_free_entries(), if swap_info_get_cont() return NULL, something wrong occurs for the swap entry. But we should still continue to free the following swap entries in the array instead of skip them to avoid swap space leak. This is just problem in error path, where system may be in an inconsistent state, but it is still good to fix it.

Cc Tim Chen <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Shaohua Li <[email protected]>
Cc Minchan Kim <[email protected]>
---
 mm/swapfile.c | 2 --
 1 file changed, 2 deletions(-)
mm/swapfile.c +0 -2
index 178130880b90..71890061f653 100644
@@ -1079,8 +1079,6 @@ void swapcache_free_entries(swp_entry_t *entries, int n)
 		p = swap_info_get_cont(entries[i], prev);
 		if (p)
 			swap_entry_free(p, entries[i]);
-		else
-			break;
 		prev = p;
 	}
 	if (p)
Signature · 7 lines
2.11.0

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Ying

From: Huang Ying <[email protected]>

In swapcache_free_entries(), if swap_info_get_cont() return NULL, something wrong occurs for the swap entry.A A But we should still continue to free the following swap entries in the array instead of skip them to avoid swap space leak.A A This is just problem in error path, where system may be in an inconsistent state, but it is still good to fix it.

Quoted 7 lines
Cc Tim Chen <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Shaohua Li <[email protected]>
Cc Minchan Kim <[email protected]>

---

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

maintainer
#2 lore raw
In reply to Huang, Ying
Quoted 14 lines · Ying

From: Huang Ying <[email protected]>

In swapcache_free_entries(), if swap_info_get_cont() return NULL, something wrong occurs for the swap entry. But we should still continue to free the following swap entries in the array instead of skip them to avoid swap space leak. This is just problem in error path, where system may be in an inconsistent state, but it is still good to fix it.

...

mm/swapfile.c void swapcache_free_entries(swp_entry_t *entries, int n) · line 1082

Quoted 6 lines
mm/swapfile.c +0 -2
@@ -1079,8 +1079,6 @@ void swapcache_free_entries(swp_entry_t *entries, int n)
 		p = swap_info_get_cont(entries[i], prev);
 		if (p)
 			swap_entry_free(p, entries[i]);
-		else
-			break;
 		prev = p;

So now prev==NULL. Will this code get the locking correct in swap_info_get_cont()? I think so, but please double-check.

mm/swapfile.c void swapcache_free_entries(swp_entry_t *entries, int n) · line 1084

Quoted 2 lines
mm/swapfile.c +0 -0
 	}
 	if (p)

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
Quoted 14 lines · Andrew Morton
Quoted 12 lines · Ying

From: Huang Ying <[email protected]>

In swapcache_free_entries(), if swap_info_get_cont() return NULL, something wrong occurs for the swap entry.A A But we should still continue to free the following swap entries in the array instead of skip them to avoid swap space leak.A A This is just problem in error path, where system may be in an inconsistent state, but it is still good to fix it.

...

Quoted 12 lines

mm/swapfile.c void swapcache_free_entries(swp_entry_t *entries, int n) · line 1082

Quoted 9 lines
mm/swapfile.c +0 -2
@@ -1079,8 +1079,6 @@ void swapcache_free_entries(swp_entry_t *entries, int n)
 A 		p = swap_info_get_cont(entries[i], prev);
 A 		if (p)
 A 			swap_entry_free(p, entries[i]);
-		else
-			break;
 A 		prev = p;

So now prev==NULL.A A Will this code get the locking correct in swap_info_get_cont()?A A I think so, but please double-check.

There are 4 possible cases, and I checked that the logic in swap_info_get_cont do the expected:

entries[i]
valid? prev A Expected swap_info_get_cont behavior
---------------------------------------------------------------------
NO NULL Return NULL p, Do nothing on lock/unlock
NO NON-NULL Return NULL p, Unlock prevA
YES NULL Return non-NULL p, lock p
YES NON-NULL Return non-NULL p, (p != prev) unlock prev and lock pA

						A  A (p == prev) do nothing on lock/unlock

Thanks.

Tim

Quoted 1 line

--
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/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>