]> Git Repo - linux.git/commitdiff
posix-clocks: Check write permissions in posix syscalls
authorTorben Hohn <[email protected]>
Thu, 3 Mar 2011 17:26:14 +0000 (18:26 +0100)
committerThomas Gleixner <[email protected]>
Sat, 12 Mar 2011 20:27:07 +0000 (21:27 +0100)
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 <[email protected]>
LKML-Reference: <1299173174[email protected]>
Cc: Richard Cochran <[email protected]>
Cc: John Stultz <[email protected]>
Cc: Thomas Gleixner <[email protected]>
kernel/time/posix-clock.c

index 04498cbf600291fabf3c8179367fb0ab3dff8187..25028dd4fa18044846caa1098bf87b28c1c81be4 100644 (file)
@@ -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;
@@ -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;
This page took 0.058018 seconds and 4 git commands to generate.