Skip to content

Commit

Permalink
Fix domain socket handling (fixes CVE-2024-35235)
Browse files Browse the repository at this point in the history
- Check status of unlink and bind system calls.
- Don't allow extra domain sockets when running from launchd/systemd.
- Validate length of domain socket path (< sizeof(sun_path))

Fixes CVE-2024-35235, written by Mike Sweet
  • Loading branch information
zdohnal committed Jun 11, 2024
1 parent 6eba4c0 commit b273a1f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
36 changes: 19 additions & 17 deletions cups/http-addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,27 +206,29 @@ httpAddrListen(http_addr_t *addr, /* I - Address to bind to */
* Remove any existing domain socket file...
*/

unlink(addr->un.sun_path);

/*
* Save the current umask and set it to 0 so that all users can access
* the domain socket...
*/

mask = umask(0);
if ((status = unlink(addr->un.sun_path)) < 0)
{
DEBUG_printf(("1httpAddrListen: Unable to unlink \"%s\": %s", addr->un.sun_path, strerror(errno)));

/*
* Bind the domain socket...
*/
if (errno == ENOENT)
status = 0;
}

status = bind(fd, (struct sockaddr *)addr, (socklen_t)httpAddrLength(addr));
if (!status)
{
// Save the current umask and set it to 0 so that all users can access
// the domain socket...
mask = umask(0);

/*
* Restore the umask and fix permissions...
*/
// Bind the domain socket...
if ((status = bind(fd, (struct sockaddr *)addr, (socklen_t)httpAddrLength(addr))) < 0)
{
DEBUG_printf(("1httpAddrListen: Unable to bind domain socket \"%s\": %s", addr->un.sun_path, strerror(errno)));
}

umask(mask);
chmod(addr->un.sun_path, 0140777);
// Restore the umask...
umask(mask);
}
}
else
#endif /* AF_LOCAL */
Expand Down
20 changes: 20 additions & 0 deletions scheduler/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3083,6 +3083,26 @@ read_cupsd_conf(cups_file_t *fp) /* I - File to read from */
cupsd_listener_t *lis; /* New listeners array */


/*
* If we are launched on-demand, do not use domain sockets from the config
* file. Also check that the domain socket path is not too long...
*/

#ifdef HAVE_ONDEMAND
if (*value == '/' && OnDemand)
{
if (strcmp(value, CUPS_DEFAULT_DOMAINSOCKET))
cupsdLogMessage(CUPSD_LOG_INFO, "Ignoring %s address %s at line %d - only using domain socket from launchd/systemd.", line, value, linenum);
continue;
}
#endif // HAVE_ONDEMAND

if (*value == '/' && strlen(value) > (sizeof(addr->addr.un.sun_path) - 1))
{
cupsdLogMessage(CUPSD_LOG_INFO, "Ignoring %s address %s at line %d - too long.", line, value, linenum);
continue;
}

/*
* Get the address list...
*/
Expand Down

0 comments on commit b273a1f

Please sign in to comment.