Skip to contentSkip to conversation

main: _exit() if setuid

PATCH In review Florian Westphal 2 participants 4 messages Oct 16, 2021 – Oct 19, 2021 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 main: _exit() if setuid

Apparently some people think its a good idea to make nft setuid so unrivilged users can change settings.

"nft -f /etc/shadow" is just one example of why this is a bad idea. Disable this. Do not print anything, fd cannot be trusted.

---
 src/main.c | 4 ++++
 1 file changed, 4 insertions(+)
src/main.c +4 -0
index 21096fc7398b..5847fc4ad514 100644
@@ -363,6 +363,10 @@ int main(int argc, char * const *argv)
 	unsigned int len;
 	int i, val, rc;
 
+	/* nftables cannot be used with setuid in a safe way. */
+	if (getuid() != geteuid())
+		_exit(111);
+
 	if (!nft_options_check(argc, argv))
 		exit(EXIT_FAILURE);
 
Signature · 1 line
2.31.1
#1 lore raw
Quoted 16 lines · Florian Westphal

Apparently some people think its a good idea to make nft setuid so unrivilged users can change settings.

"nft -f /etc/shadow" is just one example of why this is a bad idea. Disable this. Do not print anything, fd cannot be trusted.

---
 src/main.c | 4 ++++
 1 file changed, 4 insertions(+)
src/main.c +0 -0
index 21096fc7398b..5847fc4ad514 100644

src/main.c int main(int argc, char * const *argv) · line 368

Quoted 6 lines
src/main.c +3 -0
@@ -363,6 +363,10 @@ int main(int argc, char * const *argv)
 	unsigned int len;
 	int i, val, rc;
 
+	/* nftables cannot be used with setuid in a safe way. */
+	if (getuid() != geteuid())
+		_exit(111);

Applications using libnftables would still face the same issue.

Quoted 6 lines
src/main.c +0 -0
 	if (!nft_options_check(argc, argv))
 		exit(EXIT_FAILURE);
 
Signature · 1 line
2.31.1
author maintainer
#2 lore raw
Quoted 20 lines · Pablo Neira Ayuso
Quoted 19 lines · Florian Westphal

Apparently some people think its a good idea to make nft setuid so unrivilged users can change settings.

"nft -f /etc/shadow" is just one example of why this is a bad idea. Disable this. Do not print anything, fd cannot be trusted.

---
 src/main.c | 4 ++++
 1 file changed, 4 insertions(+)
src/main.c +0 -0
index 21096fc7398b..5847fc4ad514 100644
@@ -363,6 +363,10 @@ int main(int argc, char * const *argv)
 	unsigned int len;
 	int i, val, rc;
 
Quoted 5 lines

src/main.c int main(int argc, char * const *argv) · line 368

Quoted 3 lines
src/main.c +3 -0
+	/* nftables cannot be used with setuid in a safe way. */
+	if (getuid() != geteuid())
+		_exit(111);

Applications using libnftables would still face the same issue.

Yes, but there is an off-chance they know what they are doing.

#3 lore raw
Quoted 21 lines · Florian Westphal
Quoted 20 lines · Pablo Neira Ayuso
Quoted 19 lines · Florian Westphal

Apparently some people think its a good idea to make nft setuid so unrivilged users can change settings.

"nft -f /etc/shadow" is just one example of why this is a bad idea. Disable this. Do not print anything, fd cannot be trusted.

---
 src/main.c | 4 ++++
 1 file changed, 4 insertions(+)
src/main.c +0 -0
index 21096fc7398b..5847fc4ad514 100644
@@ -363,6 +363,10 @@ int main(int argc, char * const *argv)
 	unsigned int len;
 	int i, val, rc;
 
Quoted 7 lines
Quoted 5 lines

src/main.c int main(int argc, char * const *argv) · line 368

Quoted 3 lines
src/main.c +3 -0
+	/* nftables cannot be used with setuid in a safe way. */
+	if (getuid() != geteuid())
+		_exit(111);

Applications using libnftables would still face the same issue.

Yes, but there is an off-chance they know what they are doing.

Sounds sensible, I'd suggest you document this in the commit before pushing.