Skip to content

Commit

Permalink
posix-clocks: Check write permissions in posix syscalls
Browse files Browse the repository at this point in the history
pc_clock_settime() and pc_clock_adjtime() do not check whether the fd
was opened in write mode, so a clock can be set with a read only fd.

[ tglx: We deliberately do not return -EPERM as we want this to be
  	distingushable from the capability based permission check ]

Signed-off-by: Torben Hohn <torbenh@gmx.de>
LKML-Reference: <1299173174-348-4-git-send-email-torbenh@gmx.de>
Cc: Richard Cochran <richard.cochran@omicron.at>
Cc: John Stultz <johnstul@us.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
torbenh3 authored and KAGA-KOKO committed Mar 12, 2011
1 parent a9e7acf commit 6e6823d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions kernel/time/posix-clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,16 @@ static int pc_clock_adjtime(clockid_t id, struct timex *tx)
if (err)
return err;

if ((cd.fp->f_mode & FMODE_WRITE) == 0) {
err = -EACCES;
goto out;
}

if (cd.clk->ops.clock_adjtime)
err = cd.clk->ops.clock_adjtime(cd.clk, tx);
else
err = -EOPNOTSUPP;

out:
put_clock_desc(&cd);

return err;
Expand Down Expand Up @@ -344,11 +349,16 @@ static int pc_clock_settime(clockid_t id, const struct timespec *ts)
if (err)
return err;

if ((cd.fp->f_mode & FMODE_WRITE) == 0) {
err = -EACCES;
goto out;
}

if (cd.clk->ops.clock_settime)
err = cd.clk->ops.clock_settime(cd.clk, ts);
else
err = -EOPNOTSUPP;

out:
put_clock_desc(&cd);

return err;
Expand Down

0 comments on commit 6e6823d

Please sign in to comment.