Replace all instances of time_t with time64_t i.e. change the type used for representing time from 32-bit to 64-bit. All 32-bit kernels to date use a signed 32-bit time_t type, which can only represent time until January 2038. The patch also changes the function get_seconds() that returns a 32-bit integer to ktime_get_seconds() that returns seconds as 64-bit integer and it uses monotonic instead of real time clock. Field expiry is changed to u64 in struct rxrpc_key_data_v1 and struct rxkad_key and to time64_t in key_preparsed_payload. This change is safe since field expiry is used only in this driver.
Signed-off-by: Ksenija Stanojevic ksenija.stanojevic@gmail.com --- Changes in v2: - change the type of field expiry. - modify the assignement of field put_time. - modify the assignement of variable issue.
include/keys/rxrpc-type.h | 4 ++-- include/linux/key-type.h | 2 +- net/rxrpc/ar-connection.c | 4 ++-- net/rxrpc/ar-internal.h | 6 +++--- net/rxrpc/ar-key.c | 10 +++++----- net/rxrpc/ar-transport.c | 4 ++-- net/rxrpc/rxkad.c | 15 ++++++++------- 7 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/include/keys/rxrpc-type.h b/include/keys/rxrpc-type.h index fc48754..f13b2cb 100644 --- a/include/keys/rxrpc-type.h +++ b/include/keys/rxrpc-type.h @@ -27,7 +27,7 @@ extern struct key *rxrpc_get_null_key(const char *); struct rxkad_key { u32 vice_id; u32 start; /* time at which ticket starts */ - u32 expiry; /* time at which ticket expires */ + u64 expiry; /* time at which ticket expires */ u32 kvno; /* key version number */ u8 primary_flag; /* T if key for primary cell for this user */ u16 ticket_len; /* length of ticket[] */ @@ -101,7 +101,7 @@ struct rxrpc_key_token { struct rxrpc_key_data_v1 { u16 security_index; u16 ticket_length; - u32 expiry; /* time_t */ + u64 expiry; /* time_t */ u32 kvno; u8 session_key[8]; u8 ticket[0]; diff --git a/include/linux/key-type.h b/include/linux/key-type.h index ff9f1d3..ff59683 100644 --- a/include/linux/key-type.h +++ b/include/linux/key-type.h @@ -45,7 +45,7 @@ struct key_preparsed_payload { const void *data; /* Raw data */ size_t datalen; /* Raw datalen */ size_t quotalen; /* Quota length for proposed payload */ - time_t expiry; /* Expiry time of key */ + time64_t expiry; /* Expiry time of key */ bool trusted; /* True if key is trusted */ };
diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c index 6631f4f..692b3e6 100644 --- a/net/rxrpc/ar-connection.c +++ b/net/rxrpc/ar-connection.c @@ -808,7 +808,7 @@ void rxrpc_put_connection(struct rxrpc_connection *conn)
ASSERTCMP(atomic_read(&conn->usage), >, 0);
- conn->put_time = get_seconds(); + conn->put_time = ktime_get_seconds(); if (atomic_dec_and_test(&conn->usage)) { _debug("zombie"); rxrpc_queue_delayed_work(&rxrpc_connection_reap, 0); @@ -852,7 +852,7 @@ static void rxrpc_connection_reaper(struct work_struct *work)
_enter("");
- now = get_seconds(); + now = ktime_get_seconds(); earliest = ULONG_MAX;
write_lock_bh(&rxrpc_connection_lock); diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h index aef1bd2..24207db 100644 --- a/net/rxrpc/ar-internal.h +++ b/net/rxrpc/ar-internal.h @@ -208,7 +208,7 @@ struct rxrpc_transport { struct rb_root server_conns; /* server connections on this transport */ struct list_head link; /* link in master session list */ struct sk_buff_head error_queue; /* error packets awaiting processing */ - time_t put_time; /* time at which to reap */ + time64_t put_time; /* time at which to reap */ spinlock_t client_lock; /* client connection allocation lock */ rwlock_t conn_lock; /* lock for active/dead connections */ atomic_t usage; @@ -256,7 +256,7 @@ struct rxrpc_connection { struct rxrpc_crypt csum_iv; /* packet checksum base */ unsigned long events; #define RXRPC_CONN_CHALLENGE 0 /* send challenge packet */ - time_t put_time; /* time at which to reap */ + time64_t put_time; /* time at which to reap */ rwlock_t lock; /* access lock */ spinlock_t state_lock; /* state-change lock */ atomic_t usage; @@ -541,7 +541,7 @@ extern struct key_type key_type_rxrpc_s;
int rxrpc_request_key(struct rxrpc_sock *, char __user *, int); int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int); -int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time_t, +int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t, u32);
/* diff --git a/net/rxrpc/ar-key.c b/net/rxrpc/ar-key.c index db0f39f..e48d72d 100644 --- a/net/rxrpc/ar-key.c +++ b/net/rxrpc/ar-key.c @@ -125,14 +125,14 @@ static int rxrpc_preparse_xdr_rxkad(struct key_preparsed_payload *prep, token->kad->vice_id = ntohl(xdr[0]); token->kad->kvno = ntohl(xdr[1]); token->kad->start = ntohl(xdr[4]); - token->kad->expiry = ntohl(xdr[5]); + token->kad->expiry = (long long)ntohl(xdr[5]); token->kad->primary_flag = ntohl(xdr[6]); memcpy(&token->kad->session_key, &xdr[2], 8); memcpy(&token->kad->ticket, &xdr[8], tktlen);
_debug("SCIX: %u", token->security_index); _debug("TLEN: %u", token->kad->ticket_len); - _debug("EXPY: %x", token->kad->expiry); + _debug("EXPY: %lld", token->kad->expiry); _debug("KVNO: %u", token->kad->kvno); _debug("PRIM: %u", token->kad->primary_flag); _debug("SKEY: %02x%02x%02x%02x%02x%02x%02x%02x", @@ -727,7 +727,7 @@ static int rxrpc_preparse(struct key_preparsed_payload *prep)
_debug("SCIX: %u", v1->security_index); _debug("TLEN: %u", v1->ticket_length); - _debug("EXPY: %x", v1->expiry); + _debug("EXPY: %lld", v1->expiry); _debug("KVNO: %u", v1->kvno); _debug("SKEY: %02x%02x%02x%02x%02x%02x%02x%02x", v1->session_key[0], v1->session_key[1], @@ -961,7 +961,7 @@ int rxrpc_server_keyring(struct rxrpc_sock *rx, char __user *optval, */ int rxrpc_get_server_data_key(struct rxrpc_connection *conn, const void *session_key, - time_t expiry, + time64_t expiry, u32 kvno) { const struct cred *cred = current_cred(); @@ -1175,7 +1175,7 @@ static long rxrpc_read(const struct key *key, ENCODE(token->kad->kvno); ENCODE_DATA(8, token->kad->session_key); ENCODE(token->kad->start); - ENCODE(token->kad->expiry); + ENCODE64(token->kad->expiry); ENCODE(token->kad->primary_flag); ENCODE_DATA(token->kad->ticket_len, token->kad->ticket); break; diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c index 1976dec..9946467 100644 --- a/net/rxrpc/ar-transport.c +++ b/net/rxrpc/ar-transport.c @@ -189,7 +189,7 @@ void rxrpc_put_transport(struct rxrpc_transport *trans)
ASSERTCMP(atomic_read(&trans->usage), >, 0);
- trans->put_time = get_seconds(); + trans->put_time = ktime_get_seconds(); if (unlikely(atomic_dec_and_test(&trans->usage))) { _debug("zombie"); /* let the reaper determine the timeout to avoid a race with @@ -226,7 +226,7 @@ static void rxrpc_transport_reaper(struct work_struct *work)
_enter("");
- now = get_seconds(); + now = ktime_get_seconds(); earliest = ULONG_MAX;
/* extract all the transports that have been dead too long */ diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c index f226709..7c42437 100644 --- a/net/rxrpc/rxkad.c +++ b/net/rxrpc/rxkad.c @@ -17,6 +17,7 @@ #include <linux/scatterlist.h> #include <linux/ctype.h> #include <linux/slab.h> +#include <linux/time64.h> #include <net/sock.h> #include <net/af_rxrpc.h> #include <keys/rxrpc-type.h> @@ -819,7 +820,7 @@ protocol_error: static int rxkad_decrypt_ticket(struct rxrpc_connection *conn, void *ticket, size_t ticket_len, struct rxrpc_crypt *_session_key, - time_t *_expiry, + time64_t *_expiry, u32 *_abort_code) { struct blkcipher_desc desc; @@ -827,7 +828,7 @@ static int rxkad_decrypt_ticket(struct rxrpc_connection *conn, struct scatterlist sg[1]; struct in_addr addr; unsigned int life; - time_t issue, now; + time64_t issue, now; bool little_endian; int ret; u8 *p, *q, *name, *end; @@ -915,15 +916,15 @@ static int rxkad_decrypt_ticket(struct rxrpc_connection *conn, if (little_endian) { __le32 stamp; memcpy(&stamp, p, 4); - issue = le32_to_cpu(stamp); + issue = le64_to_cpu((__le64)stamp); } else { __be32 stamp; memcpy(&stamp, p, 4); - issue = be32_to_cpu(stamp); + issue = be64_to_cpu((__be64)stamp); } p += 4; - now = get_seconds(); - _debug("KIV ISSUE: %lx [%lx]", issue, now); + now = ktime_get_seconds(); + _debug("KIV ISSUE: %lld [%lld]", issue, now);
/* check the ticket is in date */ if (issue > now) { @@ -1003,7 +1004,7 @@ static int rxkad_verify_response(struct rxrpc_connection *conn, __attribute__((aligned(8))); /* must be aligned for crypto */ struct rxrpc_skb_priv *sp; struct rxrpc_crypt session_key; - time_t expiry; + time64_t expiry; void *ticket; u32 abort_code, version, kvno, ticket_len, level; __be32 csum;
On Mon, Jun 22, 2015 at 9:31 AM, Ksenija Stanojevic ksenija.stanojevic@gmail.com wrote:
@@ -1175,7 +1175,7 @@ static long rxrpc_read(const struct key *key, ENCODE(token->kad->kvno); ENCODE_DATA(8, token->kad->session_key); ENCODE(token->kad->start);
ENCODE(token->kad->expiry);
ENCODE64(token->kad->expiry);
So this looks like it changing the size of data being copied to userspace. Does this not break ABI?
ABI, of course, needs to be preserved. So even if we convert time_t data we get to a time64_t, we have to still return time_ts to userspace interfaces that expect that data. Additional interfaces may be needed to export the 64bit time.
thanks -john