Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] daemon: Prevent new daemon created on same machine #646

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ if(WITH_GIT_SUBMODULE)
endif()

if(WITH_DLT_UNIT_TESTS)
set(DLT_IPC "UNIX_SOCKET")
find_package(GTest)
if(GTEST_FOUND)
find_package(PkgConfig REQUIRED)
Expand Down
26 changes: 15 additions & 11 deletions src/daemon/dlt-daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1590,9 +1590,13 @@
/* open named pipe(FIFO) to receive DLT messages from users */
umask(0);

/* Try to delete existing pipe, ignore result of unlink */
/* Valid fifo means there is a daemon running, stop init phase of the new */
const char *tmpFifo = daemon_local->flags.daemonFifoName;
unlink(tmpFifo);
if (access(tmpFifo, F_OK) == 0) {
dlt_vlog(LOG_WARNING, "FIFO user %s is in use (%s)!\n",
tmpFifo, strerror(errno));
return -1;
}

ret = mkfifo(tmpFifo, S_IRUSR | S_IWUSR | S_IWGRP);

Expand All @@ -1602,13 +1606,21 @@
return -1;
} /* if */

fd = open(tmpFifo, O_RDWR);

Check failure

Code scanning / CodeQL

Time-of-check time-of-use filesystem race condition High

The
filename
being operated upon was previously
checked
, but the underlying file may have been changed since then.

if (fd == -1) {
dlt_vlog(LOG_WARNING, "FIFO user %s cannot be opened (%s)!\n",
tmpFifo, strerror(errno));
return -1;
} /* if */

/* Set group of daemon FIFO */
if (daemon_local->flags.daemonFifoGroup[0] != 0) {
errno = 0;
struct group *group_dlt = getgrnam(daemon_local->flags.daemonFifoGroup);

if (group_dlt) {
ret = chown(tmpFifo, -1, group_dlt->gr_gid);
ret = fchown(fd, -1, group_dlt->gr_gid);

if (ret == -1)
dlt_vlog(LOG_ERR, "FIFO user %s cannot be chowned to group %s (%s)\n",
Expand All @@ -1628,14 +1640,6 @@
}
}

fd = open(tmpFifo, O_RDWR);

if (fd == -1) {
dlt_vlog(LOG_WARNING, "FIFO user %s cannot be opened (%s)!\n",
tmpFifo, strerror(errno));
return -1;
} /* if */

#ifdef __linux__
/* F_SETPIPE_SZ and F_GETPIPE_SZ are only supported for Linux.
* For other OSes it depends on its system e.g. pipe manager.
Expand Down
Loading