Skip to content

Commit

Permalink
some glibc's check the mode arg for O_CREAT & O_TMPFILE
Browse files Browse the repository at this point in the history
Make sure we fill it in, or we get killed.
  • Loading branch information
kernelslacker committed Aug 26, 2015
1 parent 0f7305e commit 08bcce0
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions syscalls/open.c
Expand Up @@ -31,11 +31,39 @@ unsigned long get_o_flags(void)
return mask;
}

static void sanitise_open(struct syscallrecord *rec)
{
unsigned long flags;

flags = get_o_flags();

rec->a2 |= flags;

if (rec->a2 & O_CREAT)
rec->a3 = 0666;

if (rec->a2 & O_TMPFILE)
rec->a3 = 0666;
}

static void sanitise_openat(struct syscallrecord *rec)
{
unsigned long flags;

flags = get_o_flags();

rec->a3 |= flags;

if (rec->a3 & O_CREAT)
rec->a4 = 0666;

if (rec->a3 & O_TMPFILE)
rec->a4 = 0666;
}

/*
* SYSCALL_DEFINE3(open, const char __user *, filename, int, flags, int, mode)
*/
static void sanitise_open(struct syscallrecord *rec);

struct syscallentry syscall_open = {
.name = "open",
.num_args = 3,
Expand All @@ -52,20 +80,9 @@ struct syscallentry syscall_open = {
.sanitise = sanitise_open,
};

static void sanitise_open(struct syscallrecord *rec)
{
unsigned long flags;

flags = get_o_flags();

rec->a2 |= flags;
}

/*
* SYSCALL_DEFINE4(openat, int, dfd, const char __user *, filename, int, flags, int, mode)
*/
static void sanitise_openat(struct syscallrecord *rec);

struct syscallentry syscall_openat = {
.name = "openat",
.num_args = 4,
Expand All @@ -85,15 +102,6 @@ struct syscallentry syscall_openat = {
.sanitise = sanitise_openat,
};

static void sanitise_openat(struct syscallrecord *rec)
{
unsigned long flags;

flags = get_o_flags();

rec->a3 |= flags;
}

/*
* SYSCALL_DEFINE3(open_by_handle_at, int, mountdirfd,
* struct file_handle __user *, handle,
Expand Down

0 comments on commit 08bcce0

Please sign in to comment.