Skip to content

Commit b8a052a

Browse files
committed
auditd: use O_PATH to avoid blocking on special files
1 parent 50094f5 commit b8a052a

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

audisp/audispd-pconfig.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <unistd.h>
3232
#include <stdlib.h>
3333
#include <libgen.h>
34+
#include <linux/limits.h>
3435
#include "audispd-pconfig.h"
3536
#include "private.h"
3637

@@ -143,12 +144,10 @@ int load_pconfig(plugin_conf_t *config, int dirfd, char *file)
143144

144145
clear_pconfig(config);
145146

146-
/* O_NONBLOCK avoids blocking when opening a FIFO file accidentially.
147-
* It does however block if someone symlinks /dev/ttyX into the plugin directory.
147+
/* O_PATH avoids blocking, as no read/seek is done.
148148
* We do not pass O_NOFOLLOW, which allows for symlinked configs.
149149
*/
150-
mode = O_RDONLY | O_NONBLOCK;
151-
rc = openat(dirfd, file, mode);
150+
rc = openat(dirfd, file, O_PATH);
152151
if (rc < 0) {
153152
if (errno != ENOENT) {
154153
audit_msg(LOG_ERR, "Error opening %s (%s)", file,
@@ -190,13 +189,22 @@ int load_pconfig(plugin_conf_t *config, int dirfd, char *file)
190189
return 1;
191190
}
192191

193-
if (fcntl(fd, F_SETFL, mode & (~O_NONBLOCK)) < 0) {
194-
audit_msg(LOG_ERR, "Error - Failed to remove nonblock flag for %s",
192+
// reopen with read perms
193+
char fname[PATH_MAX];
194+
snprintf(fname, PATH_MAX, "/proc/self/fd/%i", fd);
195+
mode = O_RDONLY;
196+
rc = open(fname, mode);
197+
198+
if (rc < 0) {
199+
audit_msg(LOG_ERR, "Error - Failed to reopen %s for reading",
195200
file);
196201
close(fd);
197202
return 1;
198203
}
199204

205+
close(fd);
206+
fd = rc;
207+
200208
/* it's ok, read line by line */
201209
f = fdopen(fd, "rm");
202210
if (f == NULL) {

0 commit comments

Comments
 (0)