]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
time: adjtimex: Validate the ADJ_FREQUENCY values
authorSasha Levin <sasha.levin@oracle.com>
Thu, 4 Dec 2014 00:25:05 +0000 (19:25 -0500)
committerZefan Li <lizefan@huawei.com>
Tue, 14 Apr 2015 09:33:51 +0000 (17:33 +0800)
commit 5e5aeb4367b450a28f447f6d5ab57d8f2ab16a5f upstream.

Verify that the frequency value from userspace is valid and makes sense.

Unverified values can cause overflows later on.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
[jstultz: Fix up bug for negative values and drop redunent cap check]
Signed-off-by: John Stultz <john.stultz@linaro.org>
[lizf: Backported to 3.4: adjust context]
Signed-off-by: Zefan Li <lizefan@huawei.com>
kernel/time/ntp.c

index 8b707100286b8b1c3e5a1ca0c90259ce6166301c..7666b24ca9ab019968b93224a1340ab9c18924e6 100644 (file)
@@ -660,6 +660,13 @@ int do_adjtimex(struct timex *txc)
                        return result;
        }
 
+       if (txc->modes & ADJ_FREQUENCY) {
+               if (LONG_MIN / PPM_SCALE > txc->freq)
+                       return -EINVAL;
+               if (LONG_MAX / PPM_SCALE < txc->freq)
+                       return -EINVAL;
+       }
+
        getnstimeofday(&ts);
 
        spin_lock_irq(&ntp_lock);