Skip to contentSkip to conversation

ebtablesu: add O_NOFOLLOW to prevent symlink attack

PATCH New [email protected] 1 participant 1 message Nov 3 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ebtablesu: add O_NOFOLLOW to prevent symlink attack

From: jiangjixiang <[email protected]>

The FIFO pipe path /tmp/ebtables-vX.Y.Z/ebtablesd_pipe is in a world-writable directory. A local unprivileged user can pre-place a symlink at this path. When ebtablesu is invoked by root, the open(O_WRONLY) call follows the symlink and overwrites an arbitrary pre-existing file.

Adding O_NOFOLLOW makes open() fail with ELOOP if the last component of the path is a symbolic link, preventing the attack.

---
 ebtablesu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ebtablesu.c +1 -1
index 3cee145..b1e0ec3 100644
@@ -66,7 +66,7 @@ int main(int argc, char *argv[])
 		return -1;
 	}
 
-	if ((writefd = open(EBTD_PIPE, O_WRONLY, 0)) == -1) {
+	if ((writefd = open(EBTD_PIPE, O_WRONLY | O_NOFOLLOW, 0)) == -1) {
 		fprintf(stderr, "Could not open the pipe, perhaps ebtablesd is "
 		        "not running or you don't have write permission (try "
 		        "running as root).\n");
Signature · 1 line
2.55.0.windows.3