Skip to content

Commit

Permalink
blktrace: avoid using timespec
Browse files Browse the repository at this point in the history
The blktrace code stores the current time in a 32-bit word in its
user interface. This is a bad idea because 32-bit seconds overflow
at some point.

We probably have until 2106 before this one overflows, as it seems
to use an 'unsigned' variable, but we should confirm that user
space treats it the same way.

Aside from this, we want to stop using 'struct timespec' here,
so I'm adding a comment about the overflow and change the code
to use timespec64 instead to make the loss of range more obvious.

Signed-off-by: Arnd Bergmann <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
arndb authored and axboe committed Jun 17, 2016
1 parent e1f3b94 commit 59a37f8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions kernel/trace/blktrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@ static void trace_note_tsk(struct task_struct *tsk)

static void trace_note_time(struct blk_trace *bt)
{
struct timespec now;
struct timespec64 now;
unsigned long flags;
u32 words[2];

getnstimeofday(&now);
words[0] = now.tv_sec;
/* need to check user space to see if this breaks in y2038 or y2106 */
ktime_get_real_ts64(&now);
words[0] = (u32)now.tv_sec;
words[1] = now.tv_nsec;

local_irq_save(flags);
Expand Down

0 comments on commit 59a37f8

Please sign in to comment.