Переглянути джерело

ntp: fix non privileged system time shifting

The ADJ_SETOFFSET bit added in commit 094aa188 ("ntp: Add ADJ_SETOFFSET
mode bit") also introduced a way for any user to change the system time.
Sneaky or buggy calls to adjtimex() could set

    ADJ_OFFSET_SS_READ | ADJ_SETOFFSET

which would result in a successful call to timekeeping_inject_offset().
This patch fixes the issue by adding the capability check.

Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Richard Cochran 14 роки тому
батько
коміт
4352d9d44b
1 змінених файлів з 2 додано та 0 видалено
  1. 2 0
      kernel/time/ntp.c

+ 2 - 0
kernel/time/ntp.c

@@ -652,6 +652,8 @@ int do_adjtimex(struct timex *txc)
 		struct timespec delta;
 		struct timespec delta;
 		delta.tv_sec  = txc->time.tv_sec;
 		delta.tv_sec  = txc->time.tv_sec;
 		delta.tv_nsec = txc->time.tv_usec;
 		delta.tv_nsec = txc->time.tv_usec;
+		if (!capable(CAP_SYS_TIME))
+			return -EPERM;
 		if (!(txc->modes & ADJ_NANO))
 		if (!(txc->modes & ADJ_NANO))
 			delta.tv_nsec *= 1000;
 			delta.tv_nsec *= 1000;
 		result = timekeeping_inject_offset(&delta);
 		result = timekeeping_inject_offset(&delta);