Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 366185
b: refs/heads/master
c: ad46096
h: refs/heads/master
i:
  366183: 556d810
v: v3
  • Loading branch information
John Stultz committed Apr 4, 2013
1 parent 6407ede commit 30da02f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 0ed2aef9b3bffe598045b62a31a50d912eee92d8
refs/heads/master: ad460967a2953496ad76b1c22091ea99f21b4e86
39 changes: 27 additions & 12 deletions trunk/kernel/time/ntp.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,17 +622,13 @@ static inline void process_adjtimex_modes(struct timex *txc,
ntp_update_frequency();
}

/*
* adjtimex mainly allows reading (and writing, if superuser) of
* kernel time-keeping variables. used by xntpd.


/**
* ntp_validate_timex - Ensures the timex is ok for use in do_adjtimex
*/
int do_adjtimex(struct timex *txc)
int ntp_validate_timex(struct timex *txc)
{
struct timespec ts;
u32 time_tai, orig_tai;
int result;

/* Validate the data before disabling interrupts */
if (txc->modes & ADJ_ADJTIME) {
/* singleshot must not be used with any other mode bits */
if (!(txc->modes & ADJ_OFFSET_SINGLESHOT))
Expand All @@ -644,7 +640,6 @@ int do_adjtimex(struct timex *txc)
/* In order to modify anything, you gotta be super-user! */
if (txc->modes && !capable(CAP_SYS_TIME))
return -EPERM;

/*
* if the quartz is off by more than 10% then
* something is VERY wrong!
Expand All @@ -655,12 +650,32 @@ int do_adjtimex(struct timex *txc)
return -EINVAL;
}

if ((txc->modes & ADJ_SETOFFSET) && (!capable(CAP_SYS_TIME)))
return -EPERM;

return 0;
}


/*
* adjtimex mainly allows reading (and writing, if superuser) of
* kernel time-keeping variables. used by xntpd.
*/
int do_adjtimex(struct timex *txc)
{
struct timespec ts;
u32 time_tai, orig_tai;
int result;

/* Validate the data before disabling interrupts */
result = ntp_validate_timex(txc);
if (result)
return result;

if (txc->modes & ADJ_SETOFFSET) {
struct timespec delta;
delta.tv_sec = txc->time.tv_sec;
delta.tv_nsec = txc->time.tv_usec;
if (!capable(CAP_SYS_TIME))
return -EPERM;
if (!(txc->modes & ADJ_NANO))
delta.tv_nsec *= 1000;
result = timekeeping_inject_offset(&delta);
Expand Down

0 comments on commit 30da02f

Please sign in to comment.