Skip to content

Commit 294ec5b

Browse files
committed
sunrpc: convert to time64_t for expiry
Using signed 32-bit types for UTC time leads to the y2038 overflow, which is what happens in the sunrpc code at the moment. This changes the sunrpc code over to use time64_t where possible. The one exception is the gss_import_v{1,2}_context() function for kerberos5, which uses 32-bit timestamps in the protocol. Here, we can at least treat the numbers as 'unsigned', which extends the range from 2038 to 2106. Signed-off-by: Arnd Bergmann <arnd@arndb.de>
1 parent 38c4a4c commit 294ec5b

8 files changed

Lines changed: 30 additions & 24 deletions

File tree

‎include/linux/sunrpc/gss_api.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int gss_import_sec_context(
4848
size_t bufsize,
4949
struct gss_api_mech *mech,
5050
struct gss_ctx **ctx_id,
51-
time_t *endtime,
51+
time64_t *endtime,
5252
gfp_t gfp_mask);
5353
u32 gss_get_mic(
5454
struct gss_ctx *ctx_id,
@@ -108,7 +108,7 @@ struct gss_api_ops {
108108
const void *input_token,
109109
size_t bufsize,
110110
struct gss_ctx *ctx_id,
111-
time_t *endtime,
111+
time64_t *endtime,
112112
gfp_t gfp_mask);
113113
u32 (*gss_get_mic)(
114114
struct gss_ctx *ctx_id,

‎include/linux/sunrpc/gss_krb5.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ struct krb5_ctx {
106106
struct crypto_sync_skcipher *initiator_enc_aux;
107107
u8 Ksess[GSS_KRB5_MAX_KEYLEN]; /* session key */
108108
u8 cksum[GSS_KRB5_MAX_KEYLEN];
109-
s32 endtime;
110109
atomic_t seq_send;
111110
atomic64_t seq_send64;
111+
time64_t endtime;
112112
struct xdr_netobj mech_used;
113113
u8 initiator_sign[GSS_KRB5_MAX_KEYLEN];
114114
u8 acceptor_sign[GSS_KRB5_MAX_KEYLEN];

‎net/sunrpc/auth_gss/gss_krb5_mech.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ gss_import_v1_context(const void *p, const void *end, struct krb5_ctx *ctx)
253253
{
254254
u32 seq_send;
255255
int tmp;
256+
u32 time32;
256257

257258
p = simple_get_bytes(p, end, &ctx->initiate, sizeof(ctx->initiate));
258259
if (IS_ERR(p))
@@ -290,9 +291,11 @@ gss_import_v1_context(const void *p, const void *end, struct krb5_ctx *ctx)
290291
p = ERR_PTR(-ENOSYS);
291292
goto out_err;
292293
}
293-
p = simple_get_bytes(p, end, &ctx->endtime, sizeof(ctx->endtime));
294+
p = simple_get_bytes(p, end, &time32, sizeof(time32));
294295
if (IS_ERR(p))
295296
goto out_err;
297+
/* unsigned 32-bit time overflows in year 2106 */
298+
ctx->endtime = (time64_t)time32;
296299
p = simple_get_bytes(p, end, &seq_send, sizeof(seq_send));
297300
if (IS_ERR(p))
298301
goto out_err;
@@ -587,15 +590,18 @@ gss_import_v2_context(const void *p, const void *end, struct krb5_ctx *ctx,
587590
{
588591
u64 seq_send64;
589592
int keylen;
593+
u32 time32;
590594

591595
p = simple_get_bytes(p, end, &ctx->flags, sizeof(ctx->flags));
592596
if (IS_ERR(p))
593597
goto out_err;
594598
ctx->initiate = ctx->flags & KRB5_CTX_FLAG_INITIATOR;
595599

596-
p = simple_get_bytes(p, end, &ctx->endtime, sizeof(ctx->endtime));
600+
p = simple_get_bytes(p, end, &time32, sizeof(time32));
597601
if (IS_ERR(p))
598602
goto out_err;
603+
/* unsigned 32-bit time overflows in year 2106 */
604+
ctx->endtime = (time64_t)time32;
599605
p = simple_get_bytes(p, end, &seq_send64, sizeof(seq_send64));
600606
if (IS_ERR(p))
601607
goto out_err;
@@ -659,7 +665,7 @@ gss_import_v2_context(const void *p, const void *end, struct krb5_ctx *ctx,
659665
static int
660666
gss_import_sec_context_kerberos(const void *p, size_t len,
661667
struct gss_ctx *ctx_id,
662-
time_t *endtime,
668+
time64_t *endtime,
663669
gfp_t gfp_mask)
664670
{
665671
const void *end = (const void *)((const char *)p + len);

‎net/sunrpc/auth_gss/gss_krb5_seal.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,14 @@ gss_get_mic_v1(struct krb5_ctx *ctx, struct xdr_buf *text,
131131
struct xdr_netobj md5cksum = {.len = sizeof(cksumdata),
132132
.data = cksumdata};
133133
void *ptr;
134-
s32 now;
134+
time64_t now;
135135
u32 seq_send;
136136
u8 *cksumkey;
137137

138138
dprintk("RPC: %s\n", __func__);
139139
BUG_ON(ctx == NULL);
140140

141-
now = get_seconds();
141+
now = ktime_get_real_seconds();
142142

143143
ptr = setup_token(ctx, token);
144144

@@ -170,7 +170,7 @@ gss_get_mic_v2(struct krb5_ctx *ctx, struct xdr_buf *text,
170170
struct xdr_netobj cksumobj = { .len = sizeof(cksumdata),
171171
.data = cksumdata};
172172
void *krb5_hdr;
173-
s32 now;
173+
time64_t now;
174174
u8 *cksumkey;
175175
unsigned int cksum_usage;
176176
__be64 seq_send_be64;
@@ -198,7 +198,7 @@ gss_get_mic_v2(struct krb5_ctx *ctx, struct xdr_buf *text,
198198

199199
memcpy(krb5_hdr + GSS_KRB5_TOK_HDR_LEN, cksumobj.data, cksumobj.len);
200200

201-
now = get_seconds();
201+
now = ktime_get_real_seconds();
202202

203203
return (ctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE;
204204
}

‎net/sunrpc/auth_gss/gss_krb5_unseal.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ gss_verify_mic_v1(struct krb5_ctx *ctx,
124124

125125
/* it got through unscathed. Make sure the context is unexpired */
126126

127-
now = get_seconds();
127+
now = ktime_get_real_seconds();
128128

129129
if (now > ctx->endtime)
130130
return GSS_S_CONTEXT_EXPIRED;
@@ -149,7 +149,7 @@ gss_verify_mic_v2(struct krb5_ctx *ctx,
149149
char cksumdata[GSS_KRB5_MAX_CKSUM_LEN];
150150
struct xdr_netobj cksumobj = {.len = sizeof(cksumdata),
151151
.data = cksumdata};
152-
s32 now;
152+
time64_t now;
153153
u8 *ptr = read_token->data;
154154
u8 *cksumkey;
155155
u8 flags;
@@ -194,7 +194,7 @@ gss_verify_mic_v2(struct krb5_ctx *ctx,
194194
return GSS_S_BAD_SIG;
195195

196196
/* it got through unscathed. Make sure the context is unexpired */
197-
now = get_seconds();
197+
now = ktime_get_real_seconds();
198198
if (now > ctx->endtime)
199199
return GSS_S_CONTEXT_EXPIRED;
200200

‎net/sunrpc/auth_gss/gss_krb5_wrap.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ gss_wrap_kerberos_v1(struct krb5_ctx *kctx, int offset,
163163
.data = cksumdata};
164164
int blocksize = 0, plainlen;
165165
unsigned char *ptr, *msg_start;
166-
s32 now;
166+
time64_t now;
167167
int headlen;
168168
struct page **tmp_pages;
169169
u32 seq_send;
@@ -172,7 +172,7 @@ gss_wrap_kerberos_v1(struct krb5_ctx *kctx, int offset,
172172

173173
dprintk("RPC: %s\n", __func__);
174174

175-
now = get_seconds();
175+
now = ktime_get_real_seconds();
176176

177177
blocksize = crypto_sync_skcipher_blocksize(kctx->enc);
178178
gss_krb5_add_padding(buf, offset, blocksize);
@@ -268,7 +268,7 @@ gss_unwrap_kerberos_v1(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
268268
char cksumdata[GSS_KRB5_MAX_CKSUM_LEN];
269269
struct xdr_netobj md5cksum = {.len = sizeof(cksumdata),
270270
.data = cksumdata};
271-
s32 now;
271+
time64_t now;
272272
int direction;
273273
s32 seqnum;
274274
unsigned char *ptr;
@@ -359,7 +359,7 @@ gss_unwrap_kerberos_v1(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
359359

360360
/* it got through unscathed. Make sure the context is unexpired */
361361

362-
now = get_seconds();
362+
now = ktime_get_real_seconds();
363363

364364
if (now > kctx->endtime)
365365
return GSS_S_CONTEXT_EXPIRED;
@@ -439,7 +439,7 @@ gss_wrap_kerberos_v2(struct krb5_ctx *kctx, u32 offset,
439439
struct xdr_buf *buf, struct page **pages)
440440
{
441441
u8 *ptr, *plainhdr;
442-
s32 now;
442+
time64_t now;
443443
u8 flags = 0x00;
444444
__be16 *be16ptr;
445445
__be64 *be64ptr;
@@ -481,14 +481,14 @@ gss_wrap_kerberos_v2(struct krb5_ctx *kctx, u32 offset,
481481
if (err)
482482
return err;
483483

484-
now = get_seconds();
484+
now = ktime_get_real_seconds();
485485
return (kctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE;
486486
}
487487

488488
static u32
489489
gss_unwrap_kerberos_v2(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
490490
{
491-
s32 now;
491+
time64_t now;
492492
u8 *ptr;
493493
u8 flags = 0x00;
494494
u16 ec, rrc;
@@ -557,7 +557,7 @@ gss_unwrap_kerberos_v2(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
557557
/* do sequencing checks */
558558

559559
/* it got through unscathed. Make sure the context is unexpired */
560-
now = get_seconds();
560+
now = ktime_get_real_seconds();
561561
if (now > kctx->endtime)
562562
return GSS_S_CONTEXT_EXPIRED;
563563

‎net/sunrpc/auth_gss/gss_mech_switch.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ int
376376
gss_import_sec_context(const void *input_token, size_t bufsize,
377377
struct gss_api_mech *mech,
378378
struct gss_ctx **ctx_id,
379-
time_t *endtime,
379+
time64_t *endtime,
380380
gfp_t gfp_mask)
381381
{
382382
if (!(*ctx_id = kzalloc(sizeof(**ctx_id), gfp_mask)))

‎net/sunrpc/auth_gss/svcauth_gss.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ static int rsc_parse(struct cache_detail *cd,
436436
int id;
437437
int len, rv;
438438
struct rsc rsci, *rscp = NULL;
439-
time_t expiry;
439+
time64_t expiry;
440440
int status = -EINVAL;
441441
struct gss_api_mech *gm = NULL;
442442

@@ -1221,7 +1221,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
12211221
static atomic64_t ctxhctr;
12221222
long long ctxh;
12231223
struct gss_api_mech *gm = NULL;
1224-
time_t expiry;
1224+
time64_t expiry;
12251225
int status = -EINVAL;
12261226

12271227
memset(&rsci, 0, sizeof(rsci));

0 commit comments

Comments
 (0)