aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Stultz <john.stultz@linaro.org>2013-03-22 14:59:04 -0400
committerJohn Stultz <john.stultz@linaro.org>2013-04-04 16:18:14 -0400
commitad460967a2953496ad76b1c22091ea99f21b4e86 (patch)
treefbc2fc6d9e6e0abd6ff11e00a24826f91b2bc015
parent0ed2aef9b3bffe598045b62a31a50d912eee92d8 (diff)
ntp: Split out timex validation from do_adjtimex
Split out the timex validation done in do_adjtimex into a separate function. This will help simplify logic in following patches. Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Richard Cochran <richardcochran@gmail.com> Cc: Prarit Bhargava <prarit@redhat.com> Signed-off-by: John Stultz <john.stultz@linaro.org>
-rw-r--r--kernel/time/ntp.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 59e2749be0fa..457d2ba245fe 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -622,17 +622,13 @@ static inline void process_adjtimex_modes(struct timex *txc,
622 ntp_update_frequency(); 622 ntp_update_frequency();
623} 623}
624 624
625/* 625
626 * adjtimex mainly allows reading (and writing, if superuser) of 626
627 * kernel time-keeping variables. used by xntpd. 627/**
628 * ntp_validate_timex - Ensures the timex is ok for use in do_adjtimex
628 */ 629 */
629int do_adjtimex(struct timex *txc) 630int ntp_validate_timex(struct timex *txc)
630{ 631{
631 struct timespec ts;
632 u32 time_tai, orig_tai;
633 int result;
634
635 /* Validate the data before disabling interrupts */
636 if (txc->modes & ADJ_ADJTIME) { 632 if (txc->modes & ADJ_ADJTIME) {
637 /* singleshot must not be used with any other mode bits */ 633 /* singleshot must not be used with any other mode bits */
638 if (!(txc->modes & ADJ_OFFSET_SINGLESHOT)) 634 if (!(txc->modes & ADJ_OFFSET_SINGLESHOT))
@@ -644,7 +640,6 @@ int do_adjtimex(struct timex *txc)
644 /* In order to modify anything, you gotta be super-user! */ 640 /* In order to modify anything, you gotta be super-user! */
645 if (txc->modes && !capable(CAP_SYS_TIME)) 641 if (txc->modes && !capable(CAP_SYS_TIME))
646 return -EPERM; 642 return -EPERM;
647
648 /* 643 /*
649 * if the quartz is off by more than 10% then 644 * if the quartz is off by more than 10% then
650 * something is VERY wrong! 645 * something is VERY wrong!
@@ -655,12 +650,32 @@ int do_adjtimex(struct timex *txc)
655 return -EINVAL; 650 return -EINVAL;
656 } 651 }
657 652
653 if ((txc->modes & ADJ_SETOFFSET) && (!capable(CAP_SYS_TIME)))
654 return -EPERM;
655
656 return 0;
657}
658
659
660/*
661 * adjtimex mainly allows reading (and writing, if superuser) of
662 * kernel time-keeping variables. used by xntpd.
663 */
664int do_adjtimex(struct timex *txc)
665{
666 struct timespec ts;
667 u32 time_tai, orig_tai;
668 int result;
669
670 /* Validate the data before disabling interrupts */
671 result = ntp_validate_timex(txc);
672 if (result)
673 return result;
674
658 if (txc->modes & ADJ_SETOFFSET) { 675 if (txc->modes & ADJ_SETOFFSET) {
659 struct timespec delta; 676 struct timespec delta;
660 delta.tv_sec = txc->time.tv_sec; 677 delta.tv_sec = txc->time.tv_sec;
661 delta.tv_nsec = txc->time.tv_usec; 678 delta.tv_nsec = txc->time.tv_usec;
662 if (!capable(CAP_SYS_TIME))
663 return -EPERM;
664 if (!(txc->modes & ADJ_NANO)) 679 if (!(txc->modes & ADJ_NANO))
665 delta.tv_nsec *= 1000; 680 delta.tv_nsec *= 1000;
666 result = timekeeping_inject_offset(&delta); 681 result = timekeeping_inject_offset(&delta);