Whamcloud - gitweb
LU-17015 gss: support large kerberos token on client 46/51946/6
authorAurelien Degremont <adegremont@nvidia.com>
Tue, 15 Aug 2023 14:03:07 +0000 (16:03 +0200)
committerOleg Drokin <green@whamcloud.com>
Thu, 31 Aug 2023 06:38:49 +0000 (06:38 +0000)
If the current Kerberos setup is using large token, like
when PAC feature is enabled for Kerberos, client can crash.

Return an error instead of asserting to avoid the crash
and increase the default buffer size to 4kB instead of 1kB.
This will only increase the SEC_CTX_INIT request size, and
the buffer is shrunk before being sent over the wire.

This will allow security token up to 2kB to be properly
handled by Lustre. Above that size, a different issue will
happen on server side that will require another patch.

Test-Parameters: trivial kerberos=true testlist=sanity-krb5
Signed-off-by: Aurelien Degremont <adegremont@nvidia.com>
Change-Id: I9ce30ee7f8c95bfe41525c49986ffac45ffac97c
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51946
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/ptlrpc/gss/gss_cli_upcall.c
lustre/ptlrpc/gss/gss_internal.h

index 94be1ed..18dabd6 100644 (file)
@@ -65,12 +65,13 @@ int ctx_init_pack_request(struct obd_import *imp,
                          long token_size,
                          char __user *token)
 {
-       struct lustre_msg       *msg = req->rq_reqbuf;
-       struct gss_sec          *gsec;
-       struct gss_header       *ghdr;
+       struct lustre_msg *msg = req->rq_reqbuf;
+       struct gss_sec *gsec;
+       struct gss_header *ghdr;
        struct ptlrpc_user_desc *pud;
-       __u32                   *p, size, offset = 2;
-       rawobj_t                 obj;
+       __u32 total_size;
+       __u32 *p, size, offset = 2;
+       rawobj_t obj;
 
        LASSERT(msg->lm_bufcount <= 4);
        LASSERT(req->rq_cli_ctx);
@@ -127,16 +128,23 @@ int ctx_init_pack_request(struct obd_import *imp,
                LBUG();
 
        /* 4. now the token */
-       LASSERT(size >= (sizeof(__u32) + token_size));
+       total_size = sizeof(__u32) + token_size;
+       if (size < total_size) {
+               CERROR("%s: security token is too large (%d > %d): rc = %d\n",
+                      imp->imp_obd->obd_name, total_size, size, -E2BIG);
+               return -E2BIG;
+       }
        *p++ = cpu_to_le32(((__u32) token_size));
        if (copy_from_user(p, token, token_size)) {
                CERROR("can't copy token\n");
                return -EFAULT;
        }
-       size -= sizeof(__u32) + round_up(token_size, 4);
 
-       req->rq_reqdata_len = lustre_shrink_msg(req->rq_reqbuf, offset,
+       if (size > sizeof(__u32) + round_up(token_size, 4)) {
+               size -= sizeof(__u32) + round_up(token_size, 4);
+               req->rq_reqdata_len = lustre_shrink_msg(req->rq_reqbuf, offset,
                                             msg->lm_buflens[offset] - size, 0);
+       }
        return 0;
 }
 
index f27779f..8fc39e8 100644 (file)
@@ -281,7 +281,7 @@ static inline struct gss_sec_keyring *sec2gsec_keyring(struct ptlrpc_sec *sec)
 # define cache_read_unlock(cdetail) read_unlock(&((cdetail)->hash_lock))
 #endif
 
-#define GSS_CTX_INIT_MAX_LEN            (1024)
+#define GSS_CTX_INIT_MAX_LEN            (4096)
 
 /*
  * This only guaranteed be enough for current krb5 des-cbc-crc . We might