[openssh-commits] [openssh] 09/13: upstream: Make StreamLocalBindUnlink check that the thing that
git+noreply at mindrot.org
git+noreply at mindrot.org
Fri Nov 27 08:18:25 AEDT 2026
This is an automated email from the git hooks/post-receive script.
djm pushed a commit to branch master
in repository openssh.
commit a21faee8776ca1252e023ce34db296ae0c363ec1
Author: djm at openbsd.org <djm at openbsd.org>
AuthorDate: Thu Nov 26 20:05:40 2026 +0000
upstream: Make StreamLocalBindUnlink check that the thing that
it's deleting is actually a socket first
Anthropic ANT-2026-Z6F3MIXQ
OpenBSD-Commit-ID: 52fda4d07f86c7c283d5ce131d7a5508a89e353c
---
misc.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/misc.c b/misc.c
index b1761fe97..8558246cb 100644
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.224 2026/11/26 19:25:34 djm Exp $ */
+/* $OpenBSD: misc.c,v 1.225 2026/11/26 20:05:40 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
* Copyright (c) 2005-2020 Damien Miller. All rights reserved.
@@ -2029,6 +2029,7 @@ int
unix_listener(const char *path, int backlog, int unlink_first)
{
struct sockaddr_un sunaddr;
+ struct stat st;
int saved_errno, sock;
memset(&sunaddr, 0, sizeof(sunaddr));
@@ -2048,6 +2049,17 @@ unix_listener(const char *path, int backlog, int unlink_first)
return -1;
}
if (unlink_first == 1) {
+ /*
+ * Only ever remove an existing socket; the path may have been
+ * supplied by a remote peer (e.g. streamlocal-forward) and must
+ * not be usable to delete arbitrary files.
+ */
+ if (lstat(path, &st) == 0 && !S_ISSOCK(st.st_mode)) {
+ error_f("refusing to unlink non-socket %s", path);
+ close(sock);
+ errno = EADDRINUSE;
+ return -1;
+ }
if (unlink(path) != 0 && errno != ENOENT)
error("unlink(%s): %.100s", path, strerror(errno));
}
--
To stop receiving notification emails like this one, please contact
djm at mindrot.org.
More information about the openssh-commits
mailing list