Skip to content

Commit b273a1f

Browse files
committed
Fix domain socket handling (fixes CVE-2024-35235)
- 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
1 parent 6eba4c0 commit b273a1f

2 files changed

Lines changed: 39 additions & 17 deletions

File tree

cups/http-addr.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -206,27 +206,29 @@ httpAddrListen(http_addr_t *addr, /* I - Address to bind to */
206206
* Remove any existing domain socket file...
207207
*/
208208

209-
unlink(addr->un.sun_path);
210-
211-
/*
212-
* Save the current umask and set it to 0 so that all users can access
213-
* the domain socket...
214-
*/
215-
216-
mask = umask(0);
209+
if ((status = unlink(addr->un.sun_path)) < 0)
210+
{
211+
DEBUG_printf(("1httpAddrListen: Unable to unlink \"%s\": %s", addr->un.sun_path, strerror(errno)));
217212

218-
/*
219-
* Bind the domain socket...
220-
*/
213+
if (errno == ENOENT)
214+
status = 0;
215+
}
221216

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

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

228-
umask(mask);
229-
chmod(addr->un.sun_path, 0140777);
229+
// Restore the umask...
230+
umask(mask);
231+
}
230232
}
231233
else
232234
#endif /* AF_LOCAL */

scheduler/conf.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3083,6 +3083,26 @@ read_cupsd_conf(cups_file_t *fp) /* I - File to read from */
30833083
cupsd_listener_t *lis; /* New listeners array */
30843084

30853085

3086+
/*
3087+
* If we are launched on-demand, do not use domain sockets from the config
3088+
* file. Also check that the domain socket path is not too long...
3089+
*/
3090+
3091+
#ifdef HAVE_ONDEMAND
3092+
if (*value == '/' && OnDemand)
3093+
{
3094+
if (strcmp(value, CUPS_DEFAULT_DOMAINSOCKET))
3095+
cupsdLogMessage(CUPSD_LOG_INFO, "Ignoring %s address %s at line %d - only using domain socket from launchd/systemd.", line, value, linenum);
3096+
continue;
3097+
}
3098+
#endif // HAVE_ONDEMAND
3099+
3100+
if (*value == '/' && strlen(value) > (sizeof(addr->addr.un.sun_path) - 1))
3101+
{
3102+
cupsdLogMessage(CUPSD_LOG_INFO, "Ignoring %s address %s at line %d - too long.", line, value, linenum);
3103+
continue;
3104+
}
3105+
30863106
/*
30873107
* Get the address list...
30883108
*/

0 commit comments

Comments
 (0)