|
|
fc8f74 |
From 66b9f92ef41de90fc2b0359247c36bc6d128233d Mon Sep 17 00:00:00 2001
|
|
|
fc8f74 |
From: Phil Sutter <phil@nwl.cc>
|
|
|
fc8f74 |
Date: Fri, 28 Feb 2020 20:32:13 +0100
|
|
|
fc8f74 |
Subject: [PATCH] nft: cache: Fix nft_release_cache() under stress
|
|
|
fc8f74 |
|
|
|
fc8f74 |
iptables-nft-restore calls nft_action(h, NFT_COMPAT_COMMIT) for each
|
|
|
fc8f74 |
COMMIT line in input. When restoring a dump containing multiple large
|
|
|
fc8f74 |
tables, chances are nft_rebuild_cache() has to run multiple times.
|
|
|
fc8f74 |
|
|
|
fc8f74 |
If the above happens, consecutive table contents are added to __cache[1]
|
|
|
fc8f74 |
which nft_rebuild_cache() then frees, so next commit attempt accesses
|
|
|
fc8f74 |
invalid memory.
|
|
|
fc8f74 |
|
|
|
fc8f74 |
Fix this by making nft_release_cache() (called after each successful
|
|
|
fc8f74 |
commit) return things into pre-rebuild state again, but keeping the
|
|
|
fc8f74 |
fresh cache copy.
|
|
|
fc8f74 |
|
|
|
fc8f74 |
Fixes: f6ad231d698c7 ("nft: keep original cache in case of ERESTART")
|
|
|
fc8f74 |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
fc8f74 |
(cherry picked from commit c550c81fd373e5753103d20f7902171f0fa79807)
|
|
|
fc8f74 |
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
|
|
fc8f74 |
---
|
|
|
fc8f74 |
iptables/nft-cache.c | 10 ++++++++--
|
|
|
fc8f74 |
1 file changed, 8 insertions(+), 2 deletions(-)
|
|
|
fc8f74 |
|
|
|
fc8f74 |
diff --git a/iptables/nft-cache.c b/iptables/nft-cache.c
|
|
|
fc8f74 |
index 7345a27e2894b..6f21f2283e0fb 100644
|
|
|
fc8f74 |
--- a/iptables/nft-cache.c
|
|
|
fc8f74 |
+++ b/iptables/nft-cache.c
|
|
|
fc8f74 |
@@ -647,8 +647,14 @@ void nft_rebuild_cache(struct nft_handle *h)
|
|
|
fc8f74 |
|
|
|
fc8f74 |
void nft_release_cache(struct nft_handle *h)
|
|
|
fc8f74 |
{
|
|
|
fc8f74 |
- if (h->cache_index)
|
|
|
fc8f74 |
- flush_cache(h, &h->__cache[0], NULL);
|
|
|
fc8f74 |
+ if (!h->cache_index)
|
|
|
fc8f74 |
+ return;
|
|
|
fc8f74 |
+
|
|
|
fc8f74 |
+ flush_cache(h, &h->__cache[0], NULL);
|
|
|
fc8f74 |
+ memcpy(&h->__cache[0], &h->__cache[1], sizeof(h->__cache[0]));
|
|
|
fc8f74 |
+ memset(&h->__cache[1], 0, sizeof(h->__cache[1]));
|
|
|
fc8f74 |
+ h->cache_index = 0;
|
|
|
fc8f74 |
+ h->cache = &h->__cache[0];
|
|
|
fc8f74 |
}
|
|
|
fc8f74 |
|
|
|
fc8f74 |
struct nftnl_table_list *nftnl_table_list_get(struct nft_handle *h)
|
|
|
fc8f74 |
--
|
|
|
fc8f74 |
2.25.1
|
|
|
fc8f74 |
|