Skip to content

Commit 04257da

Browse files
covanamIngo Molnar
authored andcommitted
hrtimers: Make callback function pointer private
Make the struct hrtimer::function field private, to prevent users from changing this field in an unsafe way. hrtimer_update_function() should be used if the callback function needs to be changed. Signed-off-by: Nam Cao <namcao@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/all/7d0e6e0c5c59a64a9bea940051aac05d750bc0c2.1738746927.git.namcao@linutronix.de
1 parent 87d82cf commit 04257da

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

include/linux/hrtimer_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ enum hrtimer_restart {
3939
struct hrtimer {
4040
struct timerqueue_node node;
4141
ktime_t _softexpires;
42-
enum hrtimer_restart (*function)(struct hrtimer *);
42+
enum hrtimer_restart (*__private function)(struct hrtimer *);
4343
struct hrtimer_clock_base *base;
4444
u8 state;
4545
u8 is_rel;

include/trace/events/timer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ TRACE_EVENT(hrtimer_start,
235235

236236
TP_fast_assign(
237237
__entry->hrtimer = hrtimer;
238-
__entry->function = hrtimer->function;
238+
__entry->function = ACCESS_PRIVATE(hrtimer, function);
239239
__entry->expires = hrtimer_get_expires(hrtimer);
240240
__entry->softexpires = hrtimer_get_softexpires(hrtimer);
241241
__entry->mode = mode;
@@ -271,7 +271,7 @@ TRACE_EVENT(hrtimer_expire_entry,
271271
TP_fast_assign(
272272
__entry->hrtimer = hrtimer;
273273
__entry->now = *now;
274-
__entry->function = hrtimer->function;
274+
__entry->function = ACCESS_PRIVATE(hrtimer, function);
275275
),
276276

277277
TP_printk("hrtimer=%p function=%ps now=%llu",

kernel/time/hrtimer.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ void hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
13161316
struct hrtimer_clock_base *base;
13171317
unsigned long flags;
13181318

1319-
if (WARN_ON_ONCE(!timer->function))
1319+
if (WARN_ON_ONCE(!ACCESS_PRIVATE(timer, function)))
13201320
return;
13211321
/*
13221322
* Check whether the HRTIMER_MODE_SOFT bit and hrtimer.is_soft
@@ -1629,9 +1629,9 @@ static void __hrtimer_setup(struct hrtimer *timer,
16291629
timerqueue_init(&timer->node);
16301630

16311631
if (WARN_ON_ONCE(!function))
1632-
timer->function = hrtimer_dummy_timeout;
1632+
ACCESS_PRIVATE(timer, function) = hrtimer_dummy_timeout;
16331633
else
1634-
timer->function = function;
1634+
ACCESS_PRIVATE(timer, function) = function;
16351635
}
16361636

16371637
/**
@@ -1743,7 +1743,7 @@ static void __run_hrtimer(struct hrtimer_cpu_base *cpu_base,
17431743
raw_write_seqcount_barrier(&base->seq);
17441744

17451745
__remove_hrtimer(timer, base, HRTIMER_STATE_INACTIVE, 0);
1746-
fn = timer->function;
1746+
fn = ACCESS_PRIVATE(timer, function);
17471747

17481748
/*
17491749
* Clear the 'is relative' flag for the TIME_LOW_RES case. If the

kernel/time/timer_list.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static void
4646
print_timer(struct seq_file *m, struct hrtimer *taddr, struct hrtimer *timer,
4747
int idx, u64 now)
4848
{
49-
SEQ_printf(m, " #%d: <%p>, %ps", idx, taddr, timer->function);
49+
SEQ_printf(m, " #%d: <%p>, %ps", idx, taddr, ACCESS_PRIVATE(timer, function));
5050
SEQ_printf(m, ", S:%02x", timer->state);
5151
SEQ_printf(m, "\n");
5252
SEQ_printf(m, " # expires at %Lu-%Lu nsecs [in %Ld to %Ld nsecs]\n",

0 commit comments

Comments
 (0)