Skip to content

Commit 031bb5a

Browse files
mgerstnerldv-alt
authored andcommitted
pam_namespace: protect_dir(): use O_DIRECTORY to prevent local DoS situations
Without O_DIRECTORY the path crawling logic is subject to e.g. FIFOs being placed in user controlled directories, causing the PAM module to block indefinitely during `openat()`. Pass O_DIRECTORY to cause the `openat()` to fail if the path does not refer to a directory. With this the check whether the final path element is a directory becomes unnecessary, drop it.
1 parent cf8c50f commit 031bb5a

1 file changed

Lines changed: 1 addition & 17 deletions

File tree

‎modules/pam_namespace/pam_namespace.c‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ static int protect_dir(const char *path, mode_t mode, int do_mkdir,
12011201
int dfd = AT_FDCWD;
12021202
int dfd_next;
12031203
int save_errno;
1204-
int flags = O_RDONLY;
1204+
int flags = O_RDONLY | O_DIRECTORY;
12051205
int rv = -1;
12061206
struct stat st;
12071207

@@ -1255,22 +1255,6 @@ static int protect_dir(const char *path, mode_t mode, int do_mkdir,
12551255
rv = openat(dfd, dir, flags);
12561256
}
12571257

1258-
if (rv != -1) {
1259-
if (fstat(rv, &st) != 0) {
1260-
save_errno = errno;
1261-
close(rv);
1262-
rv = -1;
1263-
errno = save_errno;
1264-
goto error;
1265-
}
1266-
if (!S_ISDIR(st.st_mode)) {
1267-
close(rv);
1268-
errno = ENOTDIR;
1269-
rv = -1;
1270-
goto error;
1271-
}
1272-
}
1273-
12741258
if (flags & O_NOFOLLOW) {
12751259
/* we are inside user-owned dir - protect */
12761260
if (protect_mount(rv, p, idata) == -1) {

0 commit comments

Comments
 (0)