From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202410 header.b=EKaWaT6y; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id B48C25A061D for ; Wed, 06 Nov 2024 07:54:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202410; t=1730876064; bh=LbbNlWGSj0BE+gKJEqzjOIGxYI5NqKPmTxrjPkZtYUs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EKaWaT6ySdP3WBww+Mj3bjfmavqxLE/WWxuRGs4gSHJOxp6RDY21taa/unVLm43wV 5wBEw+PoVo7v2axCo9A7SpifZRxnabtV7UFyisMpt0aHQYkhjt6i0NsendtjpNWnE8 qIVkk/MV4o4/85MCvUaOy5/QLo03Q5Xmw34szZ0Giiuuw4TI3vvyaOlLSbZ22RKSHm yhx25+l6rVMbmlN4ywVLDgFhiqurPx9dX6m91KMGnk5tDEj298D9cf8NJToArLgOtE QAxtiT1zge48iD/5kKvX7EqH4AdzvJ8HWjf/sJgo9BCIl8r3NpZjzF+mXtubpfdc1+ 065E2v+nwKH8g== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Xjwt80qqtz4xD9; Wed, 6 Nov 2024 17:54:24 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 4/8] linux_dep: Fix CLOSE_RANGE_UNSHARE availability handling Date: Wed, 6 Nov 2024 17:54:17 +1100 Message-ID: <20241106065421.2568179-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241106065421.2568179-1-david@gibson.dropbear.id.au> References: <20241106065421.2568179-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: WSUUCRWMFGPXHV5V4YMAT2L5ZL5DBOHQ X-Message-ID-Hash: WSUUCRWMFGPXHV5V4YMAT2L5ZL5DBOHQ X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: If CLOSE_RANGE_UNSHARE isn't defined, we define a fallback version of close_range() which is a (successful) no-op. This is broken in several ways: * It doesn't actually fix compile if using old kernel headers, because the caller of close_range() still directly uses CLOSE_RANGE_UNSHARE unprotected by ifdefs * Even if it did fix the compile, it means inconsistent behaviour between a compile time failure to find the value (we silently don't close files) and a runtime failure (we die with an error from close_range()) * Silently not closing the files we intend to close for security reasons is probably not a good idea in any case As bonus this fixes a cppcheck error I see with some different options I'm looking to apply in future. Signed-off-by: David Gibson --- linux_dep.h | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/linux_dep.h b/linux_dep.h index 3a41e42..240f50a 100644 --- a/linux_dep.h +++ b/linux_dep.h @@ -127,22 +127,18 @@ struct tcp_info_linux { #include -#ifdef CLOSE_RANGE_UNSHARE /* Linux kernel >= 5.9 */ /* glibc < 2.34 and musl as of 1.2.5 need these */ #ifndef SYS_close_range #define SYS_close_range 436 #endif +#ifndef CLOSE_RANGE_UNSHARE /* Linux kernel < 5.9 */ +#define CLOSE_RANGE_UNSHARE (1U << 1) +#endif + __attribute__ ((weak)) /* cppcheck-suppress funcArgNamesDifferent */ int close_range(unsigned int first, unsigned int last, int flags) { return syscall(SYS_close_range, first, last, flags); } -#else -/* No reasonable fallback option */ -/* cppcheck-suppress funcArgNamesDifferent */ -int close_range(unsigned int first, unsigned int last, int flags) { - return 0; -} -#endif #endif /* LINUX_DEP_H */ -- 2.47.0