Bug 2228

Summary: ssh-agent passwords do not timeout properly
Product: Portable OpenSSH Reporter: John Haxby <john.haxby>
Component: ssh-agentAssignee: Damien Miller <djm>
Status: CLOSED FIXED    
Severity: major CC: djm, dtucker
Priority: P5    
Version: 6.4p1   
Hardware: All   
OS: Linux   
Bug Depends on:    
Bug Blocks: 2226    
Attachments:
Description Flags
proposed patch
none
Try CLOCK_BOOTTIME with fallback none

Description John Haxby 2014-04-16 22:03:45 AEST
Created attachment 2425 [details]
proposed patch

I habitually run "ssh-add -t10h" when I open up my laptop in the morning and then suspend it at the end of the working day, usually a little while before the lifetime of the identities expires.

Recently, however, this hasn't worked because the agent still has the identities the following morning.

I believe that this is because monotime() uses CLOCK_MONOTONIC but in recent kernels this has changed slightly.  From clock_gettime(2):

    CLOCK_MONOTONIC
           Clock that cannot be set and  represents  monotonic  time
           since some unspecified starting point.  This clock is not
           affected by discontinuous jumps in the system time (e.g.,
           if  the system administrator manually changes the clock),
           but is affected by the incremental adjustments  performed
           by adjtime(3) and NTP.

    CLOCK_BOOTTIME (since Linux 2.6.39; Linux-specific)
           Identical to CLOCK_MONOTONIC, except it also includes any
           time  that the system is suspended.  This allows applica‐
           tions to get a suspend-aware monotonic clock without hav‐
           ing  to  deal  with  the complications of CLOCK_REALTIME,
           which may have discontinuities if  the  time  is  changed
           using settimeofday(2).

The attached patch seems to fix this: if CLOCK_MONOTONIC is available then additionally check for CLOCK_BOOTTIME.  CLOCK_BOOTTIME is Linux specific and will never be defined unless CLOCK_MONOTONIC is also defined.

So far as I can tell this has not been addressed in the current version.
Comment 1 Damien Miller 2014-04-17 09:40:48 AEST
Created attachment 2427 [details]
Try CLOCK_BOOTTIME with fallback

It's probably better to try CLOCK_BOOTTIME first and fall back to CLOCK_MONOTONIC, in case the system headers happen to have the former but the kernel lacks support.
Comment 2 John Haxby 2014-04-17 17:35:03 AEST
I agree, I had thought the same thing overnight.   There are possible cases where CLOCK_BOOTIME is defined at compile time but it not available at run time so the fallback is definitely needed.  (I actually have the opposite case: CLOCK_BOOTIME is available at run time but not defined at compile time, but that's my problem, not yours.)

Your patch has a logical problem though: it won't compile if CLOCK_BOOTTIME is defined but CLOCK_MONOTONIC is.   In practice this won't happen, but perhaps you either want to surround the CLOCK_MONOTONIC call with a #ifdef or you want to remove the test for defined(CLOCK_BOOTTIME) from the surrounding #if.
Comment 3 Damien Miller 2014-05-21 17:10:59 AEST
similar patch applied - this will be in openssh-6.7
Comment 4 Damien Miller 2014-10-08 08:00:19 AEDT
Close all bugs left open from 6.6 and 6.7 releases.