History

ntp: Audit NTP parameters adjustment

Emit an audit record every time selected NTP parameters are modified from userspace (via adjtimex(2) or clock_adjtime(2)). These parameters may be used to indirectly change system clock, and thus their modifications should be audited. Such events will now generate records of type AUDIT_TIME_ADJNTPVAL containing the following fields: - op -- which value was adjusted: - offset -- corresponding to the time_offset variable - freq -- corresponding to the time_freq variable - status -- corresponding to the time_status variable - adjust -- corresponding to the time_adjust variable - tick -- corresponding to the tick_usec variable - tai -- corresponding to the timekeeping's TAI offset - old -- the old value - new -- the new value Example records: type=TIME_ADJNTPVAL msg=audit(1530616044.507:7): op=status old=64 new=8256 type=TIME_ADJNTPVAL msg=audit(1530616044.511:11): op=freq old=0 new=49180377088000 The records of this type will be associated with the corresponding syscall records. An overview of parameter changes that can be done via do_adjtimex() (based on information from Miroslav Lichvar) and whether they are audited: __timekeeping_set_tai_offset() -- sets the offset from the International Atomic Time (AUDITED) NTP variables: time_offset -- can adjust the clock by up to 0.5 seconds per call and also speed it up or slow down by up to about 0.05% (43 seconds per day) (AUDITED) time_freq -- can speed up or slow down by up to about 0.05% (AUDITED) time_status -- can insert/delete leap seconds and it also enables/ disables synchronization of the hardware real-time clock (AUDITED) time_maxerror, time_esterror -- change error estimates used to inform userspace applications (NOT AUDITED) time_constant -- controls the speed of the clock adjustments that are made when time_offset is set (NOT AUDITED) time_adjust -- can temporarily speed up or slow down the clock by up to 0.05% (AUDITED) tick_usec -- a more extreme version of time_freq; can speed up or slow down the clock by up to 10% (AUDITED)

Ondrej Mosnacek committed 7 years ago

Commit 7e8eda71 parent 2d87a066 files · +112 −5Browse files

Showing the changes to include/linux (1 of 6 files). Show all

Unified · Split

include/linux/audit.h+61−0
@@ -86,6 +86,29 @@ struct audit_field { · 85 unmodified lines
8686 u32 op;
8787 };
8888
89+enum audit_ntp_type {
90+ AUDIT_NTP_OFFSET,
91+ AUDIT_NTP_FREQ,
92+ AUDIT_NTP_STATUS,
93+ AUDIT_NTP_TAI,
94+ AUDIT_NTP_TICK,
95+ AUDIT_NTP_ADJUST,
96+
97+ AUDIT_NTP_NVALS /* count */
98+};
99+
100+#ifdef CONFIG_AUDITSYSCALL
101+struct audit_ntp_val {
102+ long long oldval, newval;
103+};
104+
105+struct audit_ntp_data {
106+ struct audit_ntp_val vals[AUDIT_NTP_NVALS];
107+};
108+#else
109+struct audit_ntp_data {};
110+#endif
111+
89112 extern int is_audit_feature_set(int which);
90113
91114 extern int __init audit_register_class(int class, unsigned *list);
@@ -366,6 +389,7 @@ extern void __audit_mmap_fd(int fd, int flags); · 274 unmodified lines
366389 extern void __audit_log_kern_module(char *name);
367390 extern void __audit_fanotify(unsigned int response);
368391 extern void __audit_tk_injoffset(struct timespec64 offset);
392+extern void __audit_ntp_log(const struct audit_ntp_data *ad);
369393
370394 static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
371395 {
@@ -478,6 +502,29 @@ static inline void audit_tk_injoffset(struct timespec64 offset) · 106 unmodified lines
478502 __audit_tk_injoffset(offset);
479503 }
480504
505+static inline void audit_ntp_init(struct audit_ntp_data *ad)
506+{
507+ memset(ad, 0, sizeof(*ad));
508+}
509+
510+static inline void audit_ntp_set_old(struct audit_ntp_data *ad,
511+ enum audit_ntp_type type, long long val)
512+{
513+ ad->vals[type].oldval = val;
514+}
515+
516+static inline void audit_ntp_set_new(struct audit_ntp_data *ad,
517+ enum audit_ntp_type type, long long val)
518+{
519+ ad->vals[type].newval = val;
520+}
521+
522+static inline void audit_ntp_log(const struct audit_ntp_data *ad)
523+{
524+ if (!audit_dummy_context())
525+ __audit_ntp_log(ad);
526+}
527+
481528 extern int audit_n_rules;
482529 extern int audit_signals;
483530 #else /* CONFIG_AUDITSYSCALL */
@@ -594,6 +641,20 @@ static inline void audit_fanotify(unsigned int response) · 110 unmodified lines
594641 static inline void audit_tk_injoffset(struct timespec64 offset)
595642 { }
596643
644+static inline void audit_ntp_init(struct audit_ntp_data *ad)
645+{ }
646+
647+static inline void audit_ntp_set_old(struct audit_ntp_data *ad,
648+ enum audit_ntp_type type, long long val)
649+{ }
650+
651+static inline void audit_ntp_set_new(struct audit_ntp_data *ad,
652+ enum audit_ntp_type type, long long val)
653+{ }
654+
655+static inline void audit_ntp_log(const struct audit_ntp_data *ad)
656+{ }
657+
597658 static inline void audit_ptrace(struct task_struct *t)
598659 { }
599660 #define audit_n_rules 0

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t