Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * The ASB.1/BER parsing code is derived from ip_nat_snmp_basic.c which was in |
| 4 | * turn derived from the gxsnmp package by Gregory McLean & Jochen Friedrich |
| 5 | * |
| 6 | * Copyright (c) 2000 RP Internet (www.rpi.net.au). |
| 7 | */ |
| 8 | |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/types.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/mm.h> |
| 13 | #include <linux/slab.h> |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 14 | #include <linux/oid_registry.h> |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 15 | |
| 16 | #include "glob.h" |
| 17 | |
| 18 | #include "asn1.h" |
| 19 | #include "connection.h" |
| 20 | #include "auth.h" |
Hyunchul Lee | 99f4525 | 2021-06-09 10:06:57 +0900 | [diff] [blame] | 21 | #include "ksmbd_spnego_negtokeninit.asn1.h" |
| 22 | #include "ksmbd_spnego_negtokentarg.asn1.h" |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 23 | |
| 24 | #define SPNEGO_OID_LEN 7 |
| 25 | #define NTLMSSP_OID_LEN 10 |
| 26 | #define KRB5_OID_LEN 7 |
| 27 | #define KRB5U2U_OID_LEN 8 |
| 28 | #define MSKRB5_OID_LEN 7 |
| 29 | static unsigned long SPNEGO_OID[7] = { 1, 3, 6, 1, 5, 5, 2 }; |
| 30 | static unsigned long NTLMSSP_OID[10] = { 1, 3, 6, 1, 4, 1, 311, 2, 2, 10 }; |
| 31 | static unsigned long KRB5_OID[7] = { 1, 2, 840, 113554, 1, 2, 2 }; |
| 32 | static unsigned long KRB5U2U_OID[8] = { 1, 2, 840, 113554, 1, 2, 2, 3 }; |
| 33 | static unsigned long MSKRB5_OID[7] = { 1, 2, 840, 48018, 1, 2, 2 }; |
| 34 | |
| 35 | static char NTLMSSP_OID_STR[NTLMSSP_OID_LEN] = { 0x2b, 0x06, 0x01, 0x04, 0x01, |
| 36 | 0x82, 0x37, 0x02, 0x02, 0x0a }; |
| 37 | |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 38 | static bool |
| 39 | asn1_subid_decode(const unsigned char **begin, const unsigned char *end, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 40 | unsigned long *subid) |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 41 | { |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 42 | const unsigned char *ptr = *begin; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 43 | unsigned char ch; |
| 44 | |
| 45 | *subid = 0; |
| 46 | |
| 47 | do { |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 48 | if (ptr >= end) |
| 49 | return false; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 50 | |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 51 | ch = *ptr++; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 52 | *subid <<= 7; |
| 53 | *subid |= ch & 0x7F; |
| 54 | } while ((ch & 0x80) == 0x80); |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 55 | |
| 56 | *begin = ptr; |
| 57 | return true; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 58 | } |
| 59 | |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 60 | static bool asn1_oid_decode(const unsigned char *value, size_t vlen, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 61 | unsigned long **oid, size_t *oidlen) |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 62 | { |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 63 | const unsigned char *iptr = value, *end = value + vlen; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 64 | unsigned long *optr; |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 65 | unsigned long subid; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 66 | |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 67 | vlen += 1; |
Namjae Jeon | c8ed115 | 2021-05-26 16:42:12 +0900 | [diff] [blame] | 68 | if (vlen < 2 || vlen > UINT_MAX / sizeof(unsigned long)) |
Colin Ian King | 5fb6886 | 2021-06-18 09:54:53 +0900 | [diff] [blame] | 69 | goto fail_nullify; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 70 | |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 71 | *oid = kmalloc(vlen * sizeof(unsigned long), GFP_KERNEL); |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 72 | if (!*oid) |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 73 | return false; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 74 | |
| 75 | optr = *oid; |
| 76 | |
Namjae Jeon | cdd1039 | 2021-05-26 15:22:37 +0900 | [diff] [blame] | 77 | if (!asn1_subid_decode(&iptr, end, &subid)) |
| 78 | goto fail; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 79 | |
| 80 | if (subid < 40) { |
| 81 | optr[0] = 0; |
| 82 | optr[1] = subid; |
| 83 | } else if (subid < 80) { |
| 84 | optr[0] = 1; |
| 85 | optr[1] = subid - 40; |
| 86 | } else { |
| 87 | optr[0] = 2; |
| 88 | optr[1] = subid - 80; |
| 89 | } |
| 90 | |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 91 | *oidlen = 2; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 92 | optr += 2; |
| 93 | |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 94 | while (iptr < end) { |
Namjae Jeon | cdd1039 | 2021-05-26 15:22:37 +0900 | [diff] [blame] | 95 | if (++(*oidlen) > vlen) |
| 96 | goto fail; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 97 | |
Namjae Jeon | cdd1039 | 2021-05-26 15:22:37 +0900 | [diff] [blame] | 98 | if (!asn1_subid_decode(&iptr, end, optr++)) |
| 99 | goto fail; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 100 | } |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 101 | return true; |
Namjae Jeon | cdd1039 | 2021-05-26 15:22:37 +0900 | [diff] [blame] | 102 | |
| 103 | fail: |
| 104 | kfree(*oid); |
Colin Ian King | 5fb6886 | 2021-06-18 09:54:53 +0900 | [diff] [blame] | 105 | fail_nullify: |
Namjae Jeon | cdd1039 | 2021-05-26 15:22:37 +0900 | [diff] [blame] | 106 | *oid = NULL; |
| 107 | return false; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 108 | } |
| 109 | |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 110 | static bool oid_eq(unsigned long *oid1, unsigned int oid1len, |
| 111 | unsigned long *oid2, unsigned int oid2len) |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 112 | { |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 113 | if (oid1len != oid2len) |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 114 | return false; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 115 | |
Namjae Jeon | 3566a2b | 2021-05-26 15:23:55 +0900 | [diff] [blame] | 116 | return memcmp(oid1, oid2, oid1len) == 0; |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 117 | } |
| 118 | |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 119 | int |
| 120 | ksmbd_decode_negTokenInit(unsigned char *security_blob, int length, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 121 | struct ksmbd_conn *conn) |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 122 | { |
Hyunchul Lee | 99f4525 | 2021-06-09 10:06:57 +0900 | [diff] [blame] | 123 | return asn1_ber_decoder(&ksmbd_spnego_negtokeninit_decoder, conn, |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 124 | security_blob, length); |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | int |
| 128 | ksmbd_decode_negTokenTarg(unsigned char *security_blob, int length, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 129 | struct ksmbd_conn *conn) |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 130 | { |
Hyunchul Lee | 99f4525 | 2021-06-09 10:06:57 +0900 | [diff] [blame] | 131 | return asn1_ber_decoder(&ksmbd_spnego_negtokentarg_decoder, conn, |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 132 | security_blob, length); |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | static int compute_asn_hdr_len_bytes(int len) |
| 136 | { |
| 137 | if (len > 0xFFFFFF) |
| 138 | return 4; |
| 139 | else if (len > 0xFFFF) |
| 140 | return 3; |
| 141 | else if (len > 0xFF) |
| 142 | return 2; |
| 143 | else if (len > 0x7F) |
| 144 | return 1; |
| 145 | else |
| 146 | return 0; |
| 147 | } |
| 148 | |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 149 | static void encode_asn_tag(char *buf, unsigned int *ofs, char tag, char seq, |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 150 | int length) |
| 151 | { |
| 152 | int i; |
| 153 | int index = *ofs; |
| 154 | char hdr_len = compute_asn_hdr_len_bytes(length); |
| 155 | int len = length + 2 + hdr_len; |
| 156 | |
| 157 | /* insert tag */ |
| 158 | buf[index++] = tag; |
| 159 | |
Namjae Jeon | a2d6321 | 2021-05-26 16:40:39 +0900 | [diff] [blame] | 160 | if (!hdr_len) { |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 161 | buf[index++] = len; |
Namjae Jeon | a2d6321 | 2021-05-26 16:40:39 +0900 | [diff] [blame] | 162 | } else { |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 163 | buf[index++] = 0x80 | hdr_len; |
| 164 | for (i = hdr_len - 1; i >= 0; i--) |
| 165 | buf[index++] = (len >> (i * 8)) & 0xFF; |
| 166 | } |
| 167 | |
| 168 | /* insert seq */ |
| 169 | len = len - (index - *ofs); |
| 170 | buf[index++] = seq; |
| 171 | |
Namjae Jeon | a2d6321 | 2021-05-26 16:40:39 +0900 | [diff] [blame] | 172 | if (!hdr_len) { |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 173 | buf[index++] = len; |
Namjae Jeon | a2d6321 | 2021-05-26 16:40:39 +0900 | [diff] [blame] | 174 | } else { |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 175 | buf[index++] = 0x80 | hdr_len; |
| 176 | for (i = hdr_len - 1; i >= 0; i--) |
| 177 | buf[index++] = (len >> (i * 8)) & 0xFF; |
| 178 | } |
| 179 | |
| 180 | *ofs += (index - *ofs); |
| 181 | } |
| 182 | |
| 183 | int build_spnego_ntlmssp_neg_blob(unsigned char **pbuffer, u16 *buflen, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 184 | char *ntlm_blob, int ntlm_blob_len) |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 185 | { |
| 186 | char *buf; |
| 187 | unsigned int ofs = 0; |
| 188 | int neg_result_len = 4 + compute_asn_hdr_len_bytes(1) * 2 + 1; |
| 189 | int oid_len = 4 + compute_asn_hdr_len_bytes(NTLMSSP_OID_LEN) * 2 + |
| 190 | NTLMSSP_OID_LEN; |
| 191 | int ntlmssp_len = 4 + compute_asn_hdr_len_bytes(ntlm_blob_len) * 2 + |
| 192 | ntlm_blob_len; |
| 193 | int total_len = 4 + compute_asn_hdr_len_bytes(neg_result_len + |
| 194 | oid_len + ntlmssp_len) * 2 + |
| 195 | neg_result_len + oid_len + ntlmssp_len; |
| 196 | |
| 197 | buf = kmalloc(total_len, GFP_KERNEL); |
| 198 | if (!buf) |
| 199 | return -ENOMEM; |
| 200 | |
| 201 | /* insert main gss header */ |
| 202 | encode_asn_tag(buf, &ofs, 0xa1, 0x30, neg_result_len + oid_len + |
| 203 | ntlmssp_len); |
| 204 | |
| 205 | /* insert neg result */ |
| 206 | encode_asn_tag(buf, &ofs, 0xa0, 0x0a, 1); |
| 207 | buf[ofs++] = 1; |
| 208 | |
| 209 | /* insert oid */ |
| 210 | encode_asn_tag(buf, &ofs, 0xa1, 0x06, NTLMSSP_OID_LEN); |
| 211 | memcpy(buf + ofs, NTLMSSP_OID_STR, NTLMSSP_OID_LEN); |
| 212 | ofs += NTLMSSP_OID_LEN; |
| 213 | |
| 214 | /* insert response token - ntlmssp blob */ |
| 215 | encode_asn_tag(buf, &ofs, 0xa2, 0x04, ntlm_blob_len); |
| 216 | memcpy(buf + ofs, ntlm_blob, ntlm_blob_len); |
| 217 | ofs += ntlm_blob_len; |
| 218 | |
| 219 | *pbuffer = buf; |
| 220 | *buflen = total_len; |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | int build_spnego_ntlmssp_auth_blob(unsigned char **pbuffer, u16 *buflen, |
Namjae Jeon | 070fb21 | 2021-05-26 17:57:12 +0900 | [diff] [blame] | 225 | int neg_result) |
Namjae Jeon | e2f3448 | 2021-03-16 10:49:09 +0900 | [diff] [blame] | 226 | { |
| 227 | char *buf; |
| 228 | unsigned int ofs = 0; |
| 229 | int neg_result_len = 4 + compute_asn_hdr_len_bytes(1) * 2 + 1; |
| 230 | int total_len = 4 + compute_asn_hdr_len_bytes(neg_result_len) * 2 + |
| 231 | neg_result_len; |
| 232 | |
| 233 | buf = kmalloc(total_len, GFP_KERNEL); |
| 234 | if (!buf) |
| 235 | return -ENOMEM; |
| 236 | |
| 237 | /* insert main gss header */ |
| 238 | encode_asn_tag(buf, &ofs, 0xa1, 0x30, neg_result_len); |
| 239 | |
| 240 | /* insert neg result */ |
| 241 | encode_asn_tag(buf, &ofs, 0xa0, 0x0a, 1); |
| 242 | if (neg_result) |
| 243 | buf[ofs++] = 2; |
| 244 | else |
| 245 | buf[ofs++] = 0; |
| 246 | |
| 247 | *pbuffer = buf; |
| 248 | *buflen = total_len; |
| 249 | return 0; |
| 250 | } |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 251 | |
Hyunchul Lee | 99f4525 | 2021-06-09 10:06:57 +0900 | [diff] [blame] | 252 | int ksmbd_gssapi_this_mech(void *context, size_t hdrlen, unsigned char tag, |
| 253 | const void *value, size_t vlen) |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 254 | { |
| 255 | unsigned long *oid; |
| 256 | size_t oidlen; |
| 257 | int err = 0; |
| 258 | |
| 259 | if (!asn1_oid_decode(value, vlen, &oid, &oidlen)) { |
| 260 | err = -EBADMSG; |
| 261 | goto out; |
| 262 | } |
| 263 | |
| 264 | if (!oid_eq(oid, oidlen, SPNEGO_OID, SPNEGO_OID_LEN)) |
| 265 | err = -EBADMSG; |
| 266 | kfree(oid); |
| 267 | out: |
| 268 | if (err) { |
| 269 | char buf[50]; |
| 270 | |
| 271 | sprint_oid(value, vlen, buf, sizeof(buf)); |
| 272 | ksmbd_debug(AUTH, "Unexpected OID: %s\n", buf); |
| 273 | } |
| 274 | return err; |
| 275 | } |
| 276 | |
Hyunchul Lee | 99f4525 | 2021-06-09 10:06:57 +0900 | [diff] [blame] | 277 | int ksmbd_neg_token_init_mech_type(void *context, size_t hdrlen, |
| 278 | unsigned char tag, const void *value, |
| 279 | size_t vlen) |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 280 | { |
| 281 | struct ksmbd_conn *conn = context; |
| 282 | unsigned long *oid; |
| 283 | size_t oidlen; |
| 284 | int mech_type; |
Namjae Jeon | 8bae441 | 2021-05-26 15:24:39 +0900 | [diff] [blame] | 285 | char buf[50]; |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 286 | |
Namjae Jeon | 8bae441 | 2021-05-26 15:24:39 +0900 | [diff] [blame] | 287 | if (!asn1_oid_decode(value, vlen, &oid, &oidlen)) |
| 288 | goto fail; |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 289 | |
| 290 | if (oid_eq(oid, oidlen, NTLMSSP_OID, NTLMSSP_OID_LEN)) |
| 291 | mech_type = KSMBD_AUTH_NTLMSSP; |
| 292 | else if (oid_eq(oid, oidlen, MSKRB5_OID, MSKRB5_OID_LEN)) |
| 293 | mech_type = KSMBD_AUTH_MSKRB5; |
| 294 | else if (oid_eq(oid, oidlen, KRB5_OID, KRB5_OID_LEN)) |
| 295 | mech_type = KSMBD_AUTH_KRB5; |
| 296 | else if (oid_eq(oid, oidlen, KRB5U2U_OID, KRB5U2U_OID_LEN)) |
| 297 | mech_type = KSMBD_AUTH_KRB5U2U; |
| 298 | else |
Namjae Jeon | 8bae441 | 2021-05-26 15:24:39 +0900 | [diff] [blame] | 299 | goto fail; |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 300 | |
| 301 | conn->auth_mechs |= mech_type; |
| 302 | if (conn->preferred_auth_mech == 0) |
| 303 | conn->preferred_auth_mech = mech_type; |
| 304 | |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 305 | kfree(oid); |
| 306 | return 0; |
Namjae Jeon | 8bae441 | 2021-05-26 15:24:39 +0900 | [diff] [blame] | 307 | |
| 308 | fail: |
| 309 | kfree(oid); |
| 310 | sprint_oid(value, vlen, buf, sizeof(buf)); |
| 311 | ksmbd_debug(AUTH, "Unexpected OID: %s\n", buf); |
| 312 | return -EBADMSG; |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 313 | } |
| 314 | |
Hyunchul Lee | 99f4525 | 2021-06-09 10:06:57 +0900 | [diff] [blame] | 315 | int ksmbd_neg_token_init_mech_token(void *context, size_t hdrlen, |
| 316 | unsigned char tag, const void *value, |
| 317 | size_t vlen) |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 318 | { |
| 319 | struct ksmbd_conn *conn = context; |
| 320 | |
| 321 | conn->mechToken = kmalloc(vlen + 1, GFP_KERNEL); |
| 322 | if (!conn->mechToken) |
| 323 | return -ENOMEM; |
| 324 | |
| 325 | memcpy(conn->mechToken, value, vlen); |
| 326 | conn->mechToken[vlen] = '\0'; |
| 327 | return 0; |
| 328 | } |
| 329 | |
Hyunchul Lee | 99f4525 | 2021-06-09 10:06:57 +0900 | [diff] [blame] | 330 | int ksmbd_neg_token_targ_resp_token(void *context, size_t hdrlen, |
| 331 | unsigned char tag, const void *value, |
| 332 | size_t vlen) |
Hyunchul Lee | fad4161 | 2021-04-19 17:26:15 +0900 | [diff] [blame] | 333 | { |
| 334 | struct ksmbd_conn *conn = context; |
| 335 | |
| 336 | conn->mechToken = kmalloc(vlen + 1, GFP_KERNEL); |
| 337 | if (!conn->mechToken) |
| 338 | return -ENOMEM; |
| 339 | |
| 340 | memcpy(conn->mechToken, value, vlen); |
| 341 | conn->mechToken[vlen] = '\0'; |
| 342 | return 0; |
| 343 | } |