Skip to content

Commit

Permalink
sunrpc: convert to time64_t for expiry
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Anna Schumaker <[email protected]>
  • Loading branch information
arndb authored and amschuma-ntap committed Jan 15, 2020
1 parent ce8866f commit 52879b4
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 24 deletions.
4 changes: 2 additions & 2 deletions include/linux/sunrpc/gss_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int gss_import_sec_context(
size_t bufsize,
struct gss_api_mech *mech,
struct gss_ctx **ctx_id,
time_t *endtime,
time64_t *endtime,
gfp_t gfp_mask);
u32 gss_get_mic(
struct gss_ctx *ctx_id,
Expand Down Expand Up @@ -108,7 +108,7 @@ struct gss_api_ops {
const void *input_token,
size_t bufsize,
struct gss_ctx *ctx_id,
time_t *endtime,
time64_t *endtime,
gfp_t gfp_mask);
u32 (*gss_get_mic)(
struct gss_ctx *ctx_id,
Expand Down
2 changes: 1 addition & 1 deletion include/linux/sunrpc/gss_krb5.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ struct krb5_ctx {
struct crypto_sync_skcipher *initiator_enc_aux;
u8 Ksess[GSS_KRB5_MAX_KEYLEN]; /* session key */
u8 cksum[GSS_KRB5_MAX_KEYLEN];
s32 endtime;
atomic_t seq_send;
atomic64_t seq_send64;
time64_t endtime;
struct xdr_netobj mech_used;
u8 initiator_sign[GSS_KRB5_MAX_KEYLEN];
u8 acceptor_sign[GSS_KRB5_MAX_KEYLEN];
Expand Down
12 changes: 9 additions & 3 deletions net/sunrpc/auth_gss/gss_krb5_mech.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ gss_import_v1_context(const void *p, const void *end, struct krb5_ctx *ctx)
{
u32 seq_send;
int tmp;
u32 time32;

p = simple_get_bytes(p, end, &ctx->initiate, sizeof(ctx->initiate));
if (IS_ERR(p))
Expand Down Expand Up @@ -290,9 +291,11 @@ gss_import_v1_context(const void *p, const void *end, struct krb5_ctx *ctx)
p = ERR_PTR(-ENOSYS);
goto out_err;
}
p = simple_get_bytes(p, end, &ctx->endtime, sizeof(ctx->endtime));
p = simple_get_bytes(p, end, &time32, sizeof(time32));
if (IS_ERR(p))
goto out_err;
/* unsigned 32-bit time overflows in year 2106 */
ctx->endtime = (time64_t)time32;
p = simple_get_bytes(p, end, &seq_send, sizeof(seq_send));
if (IS_ERR(p))
goto out_err;
Expand Down Expand Up @@ -587,15 +590,18 @@ gss_import_v2_context(const void *p, const void *end, struct krb5_ctx *ctx,
{
u64 seq_send64;
int keylen;
u32 time32;

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

p = simple_get_bytes(p, end, &ctx->endtime, sizeof(ctx->endtime));
p = simple_get_bytes(p, end, &time32, sizeof(time32));
if (IS_ERR(p))
goto out_err;
/* unsigned 32-bit time overflows in year 2106 */
ctx->endtime = (time64_t)time32;
p = simple_get_bytes(p, end, &seq_send64, sizeof(seq_send64));
if (IS_ERR(p))
goto out_err;
Expand Down Expand Up @@ -659,7 +665,7 @@ gss_import_v2_context(const void *p, const void *end, struct krb5_ctx *ctx,
static int
gss_import_sec_context_kerberos(const void *p, size_t len,
struct gss_ctx *ctx_id,
time_t *endtime,
time64_t *endtime,
gfp_t gfp_mask)
{
const void *end = (const void *)((const char *)p + len);
Expand Down
8 changes: 4 additions & 4 deletions net/sunrpc/auth_gss/gss_krb5_seal.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ gss_get_mic_v1(struct krb5_ctx *ctx, struct xdr_buf *text,
struct xdr_netobj md5cksum = {.len = sizeof(cksumdata),
.data = cksumdata};
void *ptr;
s32 now;
time64_t now;
u32 seq_send;
u8 *cksumkey;

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

now = get_seconds();
now = ktime_get_real_seconds();

ptr = setup_token(ctx, token);

Expand Down Expand Up @@ -170,7 +170,7 @@ gss_get_mic_v2(struct krb5_ctx *ctx, struct xdr_buf *text,
struct xdr_netobj cksumobj = { .len = sizeof(cksumdata),
.data = cksumdata};
void *krb5_hdr;
s32 now;
time64_t now;
u8 *cksumkey;
unsigned int cksum_usage;
__be64 seq_send_be64;
Expand Down Expand Up @@ -198,7 +198,7 @@ gss_get_mic_v2(struct krb5_ctx *ctx, struct xdr_buf *text,

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

now = get_seconds();
now = ktime_get_real_seconds();

return (ctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE;
}
Expand Down
6 changes: 3 additions & 3 deletions net/sunrpc/auth_gss/gss_krb5_unseal.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ gss_verify_mic_v1(struct krb5_ctx *ctx,

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

now = get_seconds();
now = ktime_get_real_seconds();

if (now > ctx->endtime)
return GSS_S_CONTEXT_EXPIRED;
Expand All @@ -149,7 +149,7 @@ gss_verify_mic_v2(struct krb5_ctx *ctx,
char cksumdata[GSS_KRB5_MAX_CKSUM_LEN];
struct xdr_netobj cksumobj = {.len = sizeof(cksumdata),
.data = cksumdata};
s32 now;
time64_t now;
u8 *ptr = read_token->data;
u8 *cksumkey;
u8 flags;
Expand Down Expand Up @@ -194,7 +194,7 @@ gss_verify_mic_v2(struct krb5_ctx *ctx,
return GSS_S_BAD_SIG;

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

Expand Down
16 changes: 8 additions & 8 deletions net/sunrpc/auth_gss/gss_krb5_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ gss_wrap_kerberos_v1(struct krb5_ctx *kctx, int offset,
.data = cksumdata};
int blocksize = 0, plainlen;
unsigned char *ptr, *msg_start;
s32 now;
time64_t now;
int headlen;
struct page **tmp_pages;
u32 seq_send;
Expand All @@ -172,7 +172,7 @@ gss_wrap_kerberos_v1(struct krb5_ctx *kctx, int offset,

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

now = get_seconds();
now = ktime_get_real_seconds();

blocksize = crypto_sync_skcipher_blocksize(kctx->enc);
gss_krb5_add_padding(buf, offset, blocksize);
Expand Down Expand Up @@ -268,7 +268,7 @@ gss_unwrap_kerberos_v1(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
char cksumdata[GSS_KRB5_MAX_CKSUM_LEN];
struct xdr_netobj md5cksum = {.len = sizeof(cksumdata),
.data = cksumdata};
s32 now;
time64_t now;
int direction;
s32 seqnum;
unsigned char *ptr;
Expand Down Expand Up @@ -359,7 +359,7 @@ gss_unwrap_kerberos_v1(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)

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

now = get_seconds();
now = ktime_get_real_seconds();

if (now > kctx->endtime)
return GSS_S_CONTEXT_EXPIRED;
Expand Down Expand Up @@ -439,7 +439,7 @@ gss_wrap_kerberos_v2(struct krb5_ctx *kctx, u32 offset,
struct xdr_buf *buf, struct page **pages)
{
u8 *ptr, *plainhdr;
s32 now;
time64_t now;
u8 flags = 0x00;
__be16 *be16ptr;
__be64 *be64ptr;
Expand Down Expand Up @@ -481,14 +481,14 @@ gss_wrap_kerberos_v2(struct krb5_ctx *kctx, u32 offset,
if (err)
return err;

now = get_seconds();
now = ktime_get_real_seconds();
return (kctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE;
}

static u32
gss_unwrap_kerberos_v2(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
{
s32 now;
time64_t now;
u8 *ptr;
u8 flags = 0x00;
u16 ec, rrc;
Expand Down Expand Up @@ -557,7 +557,7 @@ gss_unwrap_kerberos_v2(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
/* do sequencing checks */

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

Expand Down
2 changes: 1 addition & 1 deletion net/sunrpc/auth_gss/gss_mech_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ int
gss_import_sec_context(const void *input_token, size_t bufsize,
struct gss_api_mech *mech,
struct gss_ctx **ctx_id,
time_t *endtime,
time64_t *endtime,
gfp_t gfp_mask)
{
if (!(*ctx_id = kzalloc(sizeof(**ctx_id), gfp_mask)))
Expand Down
4 changes: 2 additions & 2 deletions net/sunrpc/auth_gss/svcauth_gss.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ static int rsc_parse(struct cache_detail *cd,
int id;
int len, rv;
struct rsc rsci, *rscp = NULL;
time_t expiry;
time64_t expiry;
int status = -EINVAL;
struct gss_api_mech *gm = NULL;

Expand Down Expand Up @@ -1221,7 +1221,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
static atomic64_t ctxhctr;
long long ctxh;
struct gss_api_mech *gm = NULL;
time_t expiry;
time64_t expiry;
int status = -EINVAL;

memset(&rsci, 0, sizeof(rsci));
Expand Down

0 comments on commit 52879b4

Please sign in to comment.