Skip to content
Permalink
Browse files Browse the repository at this point in the history
lib: fix races in dump directory handling code
Florian Weimer <fweimer@redhat.com>:

    dd_opendir() should keep a file handle (opened with O_DIRECTORY) and
    use openat() and similar functions to access files in it.

    ...

    The file system manipulation functions should guard against hard
    links (check that link count is <= 1, just as in the user coredump
    code in abrt-hook-ccpp), possibly after opening the file
    with O_PATH first to avoid side effects on open/close.

Related: #1214745

Signed-off-by: Jakub Filak <jfilak@redhat.com>
  • Loading branch information
Jakub Filak committed Apr 28, 2015
1 parent 41ec59d commit 1951e72
Show file tree
Hide file tree
Showing 5 changed files with 275 additions and 181 deletions.
7 changes: 7 additions & 0 deletions src/include/dump_dir.h
Expand Up @@ -34,6 +34,12 @@ extern "C" {

/* Utility function */
int create_symlink_lockfile(const char *filename, const char *pid_str);
int create_symlink_lockfile_at(int dir_fd, const char *filename, const char *pid_str);

/* Opens filename for reading relatively to a directory represented by dir_fd.
* The function fails if the file is symbolic link, directory or hard link.
*/
int secure_openat_read(int dir_fd, const char *filename);

enum {
DD_FAIL_QUIETLY_ENOENT = (1 << 0),
Expand All @@ -57,6 +63,7 @@ struct dump_dir {
mode_t mode;
time_t dd_time;
char *dd_type;
int dd_fd;
};

void dd_close(struct dump_dir *dd);
Expand Down
4 changes: 4 additions & 0 deletions src/include/internal_libreport.h
Expand Up @@ -406,6 +406,8 @@ int xopen3(const char *pathname, int flags, int mode);
int xopen(const char *pathname, int flags);
#define xunlink libreport_xunlink
void xunlink(const char *pathname);
#define xunlinkat libreport_xunlinkat
void xunlinkat(int dir_fd, const char *pathname, int flags);

/* Just testing dent->d_type == DT_REG is wrong: some filesystems
* do not report the type, they report DT_UNKNOWN for every dirent
Expand All @@ -415,6 +417,8 @@ void xunlink(const char *pathname);
*/
#define is_regular_file libreport_is_regular_file
int is_regular_file(struct dirent *dent, const char *dirname);
#define is_regular_file_at libreport_is_regular_file_at
int is_regular_file_at(struct dirent *dent, int dir_fd);

#define dot_or_dotdot libreport_dot_or_dotdot
bool dot_or_dotdot(const char *filename);
Expand Down

0 comments on commit 1951e72

Please sign in to comment.