Skip to content

Commit 607af43

Browse files
Ali Ahmet MEMISspandruvada
authored andcommitted
tools/power/x86/intel-speed-select: Harden daemon pidfile open
Avoid symlink-based pidfile clobbering by opening the pidfile with O_NOFOLLOW and validating it with fstat() before locking/writing. The daemon currently uses a fixed pidfile path under /tmp. A local unprivileged user can pre-create a symlink at that path and cause a root-run daemon instance to write into an attacker-chosen file. Fixes: 7fd786d ("tools/power/x86/intel-speed-select: OOB daemon mode") Signed-off-by: Ali Ahmet MEMIS <dev@unknownbbqr.xyz> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Cc: stable@kernel.org
1 parent a167ae8 commit 607af43

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

tools/power/x86/intel-speed-select/isst-daemon.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ static void daemonize(char *rundir, char *pidfile)
148148
{
149149
int pid, sid, i;
150150
char str[10];
151+
struct stat st;
151152
struct sigaction sig_actions;
152153
sigset_t sig_set;
153154
int ret;
@@ -200,11 +201,17 @@ static void daemonize(char *rundir, char *pidfile)
200201
if (ret == -1)
201202
exit(EXIT_FAILURE);
202203

203-
pid_file_handle = open(pidfile, O_RDWR | O_CREAT, 0600);
204+
pid_file_handle = open(pidfile, O_RDWR | O_CREAT | O_NOFOLLOW, 0600);
204205
if (pid_file_handle == -1) {
205206
/* Couldn't open lock file */
206207
exit(1);
207208
}
209+
210+
if (fstat(pid_file_handle, &st) == -1)
211+
exit(1);
212+
213+
if (!S_ISREG(st.st_mode))
214+
exit(1);
208215
/* Try to lock file */
209216
#ifdef LOCKF_SUPPORT
210217
if (lockf(pid_file_handle, F_TLOCK, 0) == -1) {

0 commit comments

Comments
 (0)