hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/kernel/time/ntp.c
....@@ -17,7 +17,7 @@
1717 #include <linux/mm.h>
1818 #include <linux/module.h>
1919 #include <linux/rtc.h>
20
-#include <linux/math64.h>
20
+#include <linux/audit.h>
2121
2222 #include "ntp_internal.h"
2323 #include "timekeeping_internal.h"
....@@ -190,13 +190,13 @@
190190 && (status & (STA_PPSWANDER|STA_PPSERROR)));
191191 }
192192
193
-static inline void pps_fill_timex(struct timex *txc)
193
+static inline void pps_fill_timex(struct __kernel_timex *txc)
194194 {
195195 txc->ppsfreq = shift_right((pps_freq >> PPM_SCALE_INV_SHIFT) *
196196 PPM_SCALE_INV, NTP_SCALE_SHIFT);
197197 txc->jitter = pps_jitter;
198198 if (!(time_status & STA_NANO))
199
- txc->jitter /= NSEC_PER_USEC;
199
+ txc->jitter = pps_jitter / NSEC_PER_USEC;
200200 txc->shift = pps_shift;
201201 txc->stabil = pps_stabil;
202202 txc->jitcnt = pps_jitcnt;
....@@ -222,7 +222,7 @@
222222 return status & (STA_UNSYNC|STA_CLOCKERR);
223223 }
224224
225
-static inline void pps_fill_timex(struct timex *txc)
225
+static inline void pps_fill_timex(struct __kernel_timex *txc)
226226 {
227227 /* PPS is not implemented, so these are zero */
228228 txc->ppsfreq = 0;
....@@ -556,17 +556,9 @@
556556 }
557557
558558 #ifdef CONFIG_GENERIC_CMOS_UPDATE
559
-int __weak update_persistent_clock(struct timespec now)
560
-{
561
- return -ENODEV;
562
-}
563
-
564559 int __weak update_persistent_clock64(struct timespec64 now64)
565560 {
566
- struct timespec now;
567
-
568
- now = timespec64_to_timespec(now64);
569
- return update_persistent_clock(now);
561
+ return -ENODEV;
570562 }
571563 #endif
572564
....@@ -643,7 +635,7 @@
643635 /*
644636 * Propagate a new txc->status value into the NTP state:
645637 */
646
-static inline void process_adj_status(const struct timex *txc)
638
+static inline void process_adj_status(const struct __kernel_timex *txc)
647639 {
648640 if ((time_status & STA_PLL) && !(txc->status & STA_PLL)) {
649641 time_state = TIME_OK;
....@@ -666,7 +658,8 @@
666658 }
667659
668660
669
-static inline void process_adjtimex_modes(const struct timex *txc, s32 *time_tai)
661
+static inline void process_adjtimex_modes(const struct __kernel_timex *txc,
662
+ s32 *time_tai)
670663 {
671664 if (txc->modes & ADJ_STATUS)
672665 process_adj_status(txc);
....@@ -718,7 +711,8 @@
718711 * adjtimex mainly allows reading (and writing, if superuser) of
719712 * kernel time-keeping variables. used by xntpd.
720713 */
721
-int __do_adjtimex(struct timex *txc, const struct timespec64 *ts, s32 *time_tai)
714
+int __do_adjtimex(struct __kernel_timex *txc, const struct timespec64 *ts,
715
+ s32 *time_tai, struct audit_ntp_data *ad)
722716 {
723717 int result;
724718
....@@ -729,18 +723,33 @@
729723 /* adjtime() is independent from ntp_adjtime() */
730724 time_adjust = txc->offset;
731725 ntp_update_frequency();
726
+
727
+ audit_ntp_set_old(ad, AUDIT_NTP_ADJUST, save_adjust);
728
+ audit_ntp_set_new(ad, AUDIT_NTP_ADJUST, time_adjust);
732729 }
733730 txc->offset = save_adjust;
734731 } else {
735
-
736732 /* If there are input parameters, then process them: */
737
- if (txc->modes)
733
+ if (txc->modes) {
734
+ audit_ntp_set_old(ad, AUDIT_NTP_OFFSET, time_offset);
735
+ audit_ntp_set_old(ad, AUDIT_NTP_FREQ, time_freq);
736
+ audit_ntp_set_old(ad, AUDIT_NTP_STATUS, time_status);
737
+ audit_ntp_set_old(ad, AUDIT_NTP_TAI, *time_tai);
738
+ audit_ntp_set_old(ad, AUDIT_NTP_TICK, tick_usec);
739
+
738740 process_adjtimex_modes(txc, time_tai);
741
+
742
+ audit_ntp_set_new(ad, AUDIT_NTP_OFFSET, time_offset);
743
+ audit_ntp_set_new(ad, AUDIT_NTP_FREQ, time_freq);
744
+ audit_ntp_set_new(ad, AUDIT_NTP_STATUS, time_status);
745
+ audit_ntp_set_new(ad, AUDIT_NTP_TAI, *time_tai);
746
+ audit_ntp_set_new(ad, AUDIT_NTP_TICK, tick_usec);
747
+ }
739748
740749 txc->offset = shift_right(time_offset * NTP_INTERVAL_FREQ,
741750 NTP_SCALE_SHIFT);
742751 if (!(time_status & STA_NANO))
743
- txc->offset /= NSEC_PER_USEC;
752
+ txc->offset = (u32)txc->offset / NSEC_PER_USEC;
744753 }
745754
746755 result = time_state; /* mostly `TIME_OK' */
....@@ -762,10 +771,10 @@
762771 /* fill PPS status fields */
763772 pps_fill_timex(txc);
764773
765
- txc->time.tv_sec = (time_t)ts->tv_sec;
774
+ txc->time.tv_sec = ts->tv_sec;
766775 txc->time.tv_usec = ts->tv_nsec;
767776 if (!(time_status & STA_NANO))
768
- txc->time.tv_usec /= NSEC_PER_USEC;
777
+ txc->time.tv_usec = ts->tv_nsec / NSEC_PER_USEC;
769778
770779 /* Handle leapsec adjustments */
771780 if (unlikely(ts->tv_sec >= ntp_next_leap_sec)) {