~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/smb/server/asn1.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/smb/server/asn1.c (Version linux-6.12-rc7) and /fs/smb/server/asn1.c (Version linux-4.15.18)


  1 // SPDX-License-Identifier: GPL-2.0-or-later        1 
  2 /*                                                
  3  * The ASB.1/BER parsing code is derived from     
  4  * turn derived from the gxsnmp package by Gre    
  5  *                                                
  6  * Copyright (c) 2000 RP Internet (www.rpi.net    
  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>                           
 14 #include <linux/oid_registry.h>                   
 15                                                   
 16 #include "glob.h"                                 
 17                                                   
 18 #include "asn1.h"                                 
 19 #include "connection.h"                           
 20 #include "auth.h"                                 
 21 #include "ksmbd_spnego_negtokeninit.asn1.h"       
 22 #include "ksmbd_spnego_negtokentarg.asn1.h"       
 23                                                   
 24 #define NTLMSSP_OID_LEN  10                       
 25                                                   
 26 static char NTLMSSP_OID_STR[NTLMSSP_OID_LEN] =    
 27         0x82, 0x37, 0x02, 0x02, 0x0a };           
 28                                                   
 29 int                                               
 30 ksmbd_decode_negTokenInit(unsigned char *secur    
 31                           struct ksmbd_conn *c    
 32 {                                                 
 33         return asn1_ber_decoder(&ksmbd_spnego_    
 34                                 security_blob,    
 35 }                                                 
 36                                                   
 37 int                                               
 38 ksmbd_decode_negTokenTarg(unsigned char *secur    
 39                           struct ksmbd_conn *c    
 40 {                                                 
 41         return asn1_ber_decoder(&ksmbd_spnego_    
 42                                 security_blob,    
 43 }                                                 
 44                                                   
 45 static int compute_asn_hdr_len_bytes(int len)     
 46 {                                                 
 47         if (len > 0xFFFFFF)                       
 48                 return 4;                         
 49         else if (len > 0xFFFF)                    
 50                 return 3;                         
 51         else if (len > 0xFF)                      
 52                 return 2;                         
 53         else if (len > 0x7F)                      
 54                 return 1;                         
 55         else                                      
 56                 return 0;                         
 57 }                                                 
 58                                                   
 59 static void encode_asn_tag(char *buf, unsigned    
 60                            int length)            
 61 {                                                 
 62         int i;                                    
 63         int index = *ofs;                         
 64         char hdr_len = compute_asn_hdr_len_byt    
 65         int len = length + 2 + hdr_len;           
 66                                                   
 67         /* insert tag */                          
 68         buf[index++] = tag;                       
 69                                                   
 70         if (!hdr_len) {                           
 71                 buf[index++] = len;               
 72         } else {                                  
 73                 buf[index++] = 0x80 | hdr_len;    
 74                 for (i = hdr_len - 1; i >= 0;     
 75                         buf[index++] = (len >>    
 76         }                                         
 77                                                   
 78         /* insert seq */                          
 79         len = len - (index - *ofs);               
 80         buf[index++] = seq;                       
 81                                                   
 82         if (!hdr_len) {                           
 83                 buf[index++] = len;               
 84         } else {                                  
 85                 buf[index++] = 0x80 | hdr_len;    
 86                 for (i = hdr_len - 1; i >= 0;     
 87                         buf[index++] = (len >>    
 88         }                                         
 89                                                   
 90         *ofs += (index - *ofs);                   
 91 }                                                 
 92                                                   
 93 int build_spnego_ntlmssp_neg_blob(unsigned cha    
 94                                   char *ntlm_b    
 95 {                                                 
 96         char *buf;                                
 97         unsigned int ofs = 0;                     
 98         int neg_result_len = 4 + compute_asn_h    
 99         int oid_len = 4 + compute_asn_hdr_len_    
100                 NTLMSSP_OID_LEN;                  
101         int ntlmssp_len = 4 + compute_asn_hdr_    
102                 ntlm_blob_len;                    
103         int total_len = 4 + compute_asn_hdr_le    
104                         oid_len + ntlmssp_len)    
105                         neg_result_len + oid_l    
106                                                   
107         buf = kmalloc(total_len, GFP_KERNEL);     
108         if (!buf)                                 
109                 return -ENOMEM;                   
110                                                   
111         /* insert main gss header */              
112         encode_asn_tag(buf, &ofs, 0xa1, 0x30,     
113                         ntlmssp_len);             
114                                                   
115         /* insert neg result */                   
116         encode_asn_tag(buf, &ofs, 0xa0, 0x0a,     
117         buf[ofs++] = 1;                           
118                                                   
119         /* insert oid */                          
120         encode_asn_tag(buf, &ofs, 0xa1, 0x06,     
121         memcpy(buf + ofs, NTLMSSP_OID_STR, NTL    
122         ofs += NTLMSSP_OID_LEN;                   
123                                                   
124         /* insert response token - ntlmssp blo    
125         encode_asn_tag(buf, &ofs, 0xa2, 0x04,     
126         memcpy(buf + ofs, ntlm_blob, ntlm_blob    
127         ofs += ntlm_blob_len;                     
128                                                   
129         *pbuffer = buf;                           
130         *buflen = total_len;                      
131         return 0;                                 
132 }                                                 
133                                                   
134 int build_spnego_ntlmssp_auth_blob(unsigned ch    
135                                    int neg_res    
136 {                                                 
137         char *buf;                                
138         unsigned int ofs = 0;                     
139         int neg_result_len = 4 + compute_asn_h    
140         int total_len = 4 + compute_asn_hdr_le    
141                 neg_result_len;                   
142                                                   
143         buf = kmalloc(total_len, GFP_KERNEL);     
144         if (!buf)                                 
145                 return -ENOMEM;                   
146                                                   
147         /* insert main gss header */              
148         encode_asn_tag(buf, &ofs, 0xa1, 0x30,     
149                                                   
150         /* insert neg result */                   
151         encode_asn_tag(buf, &ofs, 0xa0, 0x0a,     
152         if (neg_result)                           
153                 buf[ofs++] = 2;                   
154         else                                      
155                 buf[ofs++] = 0;                   
156                                                   
157         *pbuffer = buf;                           
158         *buflen = total_len;                      
159         return 0;                                 
160 }                                                 
161                                                   
162 int ksmbd_gssapi_this_mech(void *context, size    
163                            const void *value,     
164 {                                                 
165         enum OID oid;                             
166                                                   
167         oid = look_up_OID(value, vlen);           
168         if (oid != OID_spnego) {                  
169                 char buf[50];                     
170                                                   
171                 sprint_oid(value, vlen, buf, s    
172                 ksmbd_debug(AUTH, "Unexpected     
173                 return -EBADMSG;                  
174         }                                         
175                                                   
176         return 0;                                 
177 }                                                 
178                                                   
179 int ksmbd_neg_token_init_mech_type(void *conte    
180                                    unsigned ch    
181                                    size_t vlen    
182 {                                                 
183         struct ksmbd_conn *conn = context;        
184         enum OID oid;                             
185         int mech_type;                            
186                                                   
187         oid = look_up_OID(value, vlen);           
188         if (oid == OID_ntlmssp) {                 
189                 mech_type = KSMBD_AUTH_NTLMSSP    
190         } else if (oid == OID_mskrb5) {           
191                 mech_type = KSMBD_AUTH_MSKRB5;    
192         } else if (oid == OID_krb5) {             
193                 mech_type = KSMBD_AUTH_KRB5;      
194         } else if (oid == OID_krb5u2u) {          
195                 mech_type = KSMBD_AUTH_KRB5U2U    
196         } else {                                  
197                 char buf[50];                     
198                                                   
199                 sprint_oid(value, vlen, buf, s    
200                 ksmbd_debug(AUTH, "Unexpected     
201                 return -EBADMSG;                  
202         }                                         
203                                                   
204         conn->auth_mechs |= mech_type;            
205         if (conn->preferred_auth_mech == 0)       
206                 conn->preferred_auth_mech = me    
207                                                   
208         return 0;                                 
209 }                                                 
210                                                   
211 static int ksmbd_neg_token_alloc(void *context    
212                                  unsigned char    
213                                  size_t vlen)     
214 {                                                 
215         struct ksmbd_conn *conn = context;        
216                                                   
217         if (!vlen)                                
218                 return -EINVAL;                   
219                                                   
220         conn->mechToken = kmemdup_nul(value, v    
221         if (!conn->mechToken)                     
222                 return -ENOMEM;                   
223                                                   
224         conn->mechTokenLen = (unsigned int)vle    
225                                                   
226         return 0;                                 
227 }                                                 
228                                                   
229 int ksmbd_neg_token_init_mech_token(void *cont    
230                                     unsigned c    
231                                     size_t vle    
232 {                                                 
233         return ksmbd_neg_token_alloc(context,     
234 }                                                 
235                                                   
236 int ksmbd_neg_token_targ_resp_token(void *cont    
237                                     unsigned c    
238                                     size_t vle    
239 {                                                 
240         return ksmbd_neg_token_alloc(context,     
241 }                                                 
242                                                   

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php