netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [nftables PATCH] cache: check errno before invoking cache_release()
@ 2021-05-13 14:10 Marco Oliverio
  2021-05-13 23:30 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Marco Oliverio @ 2021-05-13 14:10 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Marco Oliverio

if genid changes during cache_init(), check_genid() sets errno to EINTR to force
a re-init of the cache.

cache_release() may inadvertly change errno by calling free().  Indeed free()
may invoke madvise() that changes errno to ENOSYS on system where kernel is
configured without support for this syscall.

Signed-off-by: Marco Oliverio <marco.oliverio@tanaza.com>
---
 src/cache.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/cache.c b/src/cache.c
index f59bba03..ff63e59e 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -747,10 +747,12 @@ replay:
 
 	ret = nft_cache_init(&ctx, flags);
 	if (ret < 0) {
-		nft_cache_release(cache);
-		if (errno == EINTR)
+		if (errno == EINTR) {
+			nft_cache_release(cache);
 			goto replay;
+		}
 
+		nft_cache_release(cache);
 		return -1;
 	}
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [nftables PATCH] cache: check errno before invoking cache_release()
  2021-05-13 14:10 [nftables PATCH] cache: check errno before invoking cache_release() Marco Oliverio
@ 2021-05-13 23:30 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2021-05-13 23:30 UTC (permalink / raw)
  To: Marco Oliverio; +Cc: netfilter-devel

On Thu, May 13, 2021 at 04:10:32PM +0200, Marco Oliverio wrote:
> if genid changes during cache_init(), check_genid() sets errno to EINTR to force
> a re-init of the cache.
> 
> cache_release() may inadvertly change errno by calling free().  Indeed free()
> may invoke madvise() that changes errno to ENOSYS on system where kernel is
> configured without support for this syscall.

Applied, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-13 23:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-13 14:10 [nftables PATCH] cache: check errno before invoking cache_release() Marco Oliverio
2021-05-13 23:30 ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).