smb: client: fix potential OOBs in smb2_parse_contexts()
[platform/kernel/linux-starfive.git] / fs / smb / client / smb2proto.h
1 /* SPDX-License-Identifier: LGPL-2.1 */
2 /*
3  *
4  *   Copyright (c) International Business Machines  Corp., 2002, 2011
5  *                 Etersoft, 2012
6  *   Author(s): Steve French (sfrench@us.ibm.com)
7  *              Pavel Shilovsky (pshilovsky@samba.org) 2012
8  *
9  */
10 #ifndef _SMB2PROTO_H
11 #define _SMB2PROTO_H
12 #include <linux/nls.h>
13 #include <linux/key-type.h>
14
15 struct statfs;
16 struct smb_rqst;
17
18 /*
19  *****************************************************************
20  * All Prototypes
21  *****************************************************************
22  */
23 extern int map_smb2_to_linux_error(char *buf, bool log_err);
24 extern int smb2_check_message(char *buf, unsigned int length,
25                               struct TCP_Server_Info *server);
26 extern unsigned int smb2_calc_size(void *buf);
27 extern char *smb2_get_data_area_len(int *off, int *len,
28                                     struct smb2_hdr *shdr);
29 extern __le16 *cifs_convert_path_to_utf16(const char *from,
30                                           struct cifs_sb_info *cifs_sb);
31
32 extern int smb2_verify_signature(struct smb_rqst *, struct TCP_Server_Info *);
33 extern int smb2_check_receive(struct mid_q_entry *mid,
34                               struct TCP_Server_Info *server, bool log_error);
35 extern struct mid_q_entry *smb2_setup_request(struct cifs_ses *ses,
36                                               struct TCP_Server_Info *,
37                                               struct smb_rqst *rqst);
38 extern struct mid_q_entry *smb2_setup_async_request(
39                         struct TCP_Server_Info *server, struct smb_rqst *rqst);
40 extern struct cifs_ses *smb2_find_smb_ses(struct TCP_Server_Info *server,
41                                            __u64 ses_id);
42 extern struct cifs_tcon *smb2_find_smb_tcon(struct TCP_Server_Info *server,
43                                                 __u64 ses_id, __u32  tid);
44 extern int smb2_calc_signature(struct smb_rqst *rqst,
45                                 struct TCP_Server_Info *server,
46                                 bool allocate_crypto);
47 extern int smb3_calc_signature(struct smb_rqst *rqst,
48                                 struct TCP_Server_Info *server,
49                                 bool allocate_crypto);
50 extern void smb2_echo_request(struct work_struct *work);
51 extern __le32 smb2_get_lease_state(struct cifsInodeInfo *cinode);
52 extern bool smb2_is_valid_oplock_break(char *buffer,
53                                        struct TCP_Server_Info *srv);
54 extern int smb3_handle_read_data(struct TCP_Server_Info *server,
55                                  struct mid_q_entry *mid);
56 extern int smb2_query_reparse_tag(const unsigned int xid, struct cifs_tcon *tcon,
57                                 struct cifs_sb_info *cifs_sb, const char *path,
58                                 __u32 *reparse_tag);
59 int smb2_query_path_info(const unsigned int xid,
60                          struct cifs_tcon *tcon,
61                          struct cifs_sb_info *cifs_sb,
62                          const char *full_path,
63                          struct cifs_open_info_data *data);
64 extern int smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon,
65                               const char *full_path, __u64 size,
66                               struct cifs_sb_info *cifs_sb, bool set_alloc);
67 extern int smb2_set_file_info(struct inode *inode, const char *full_path,
68                               FILE_BASIC_INFO *buf, const unsigned int xid);
69 extern int smb311_posix_mkdir(const unsigned int xid, struct inode *inode,
70                                umode_t mode, struct cifs_tcon *tcon,
71                                const char *full_path,
72                                struct cifs_sb_info *cifs_sb);
73 extern int smb2_mkdir(const unsigned int xid, struct inode *inode,
74                       umode_t mode, struct cifs_tcon *tcon,
75                       const char *name, struct cifs_sb_info *cifs_sb);
76 extern void smb2_mkdir_setinfo(struct inode *inode, const char *full_path,
77                                struct cifs_sb_info *cifs_sb,
78                                struct cifs_tcon *tcon, const unsigned int xid);
79 extern int smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon,
80                       const char *name, struct cifs_sb_info *cifs_sb);
81 extern int smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon,
82                        const char *name, struct cifs_sb_info *cifs_sb);
83 extern int smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon,
84                             const char *from_name, const char *to_name,
85                             struct cifs_sb_info *cifs_sb);
86 extern int smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon,
87                                 const char *from_name, const char *to_name,
88                                 struct cifs_sb_info *cifs_sb);
89 extern int smb3_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
90                         struct cifs_sb_info *cifs_sb, const unsigned char *path,
91                         char *pbuf, unsigned int *pbytes_written);
92 extern int smb3_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon,
93                           struct cifs_sb_info *cifs_sb,
94                           const unsigned char *path, char *pbuf,
95                           unsigned int *pbytes_read);
96 int smb2_parse_symlink_response(struct cifs_sb_info *cifs_sb, const struct kvec *iov, char **path);
97 int smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, __u32 *oplock,
98                    void *buf);
99 extern int smb2_unlock_range(struct cifsFileInfo *cfile,
100                              struct file_lock *flock, const unsigned int xid);
101 extern int smb2_push_mandatory_locks(struct cifsFileInfo *cfile);
102 extern void smb2_reconnect_server(struct work_struct *work);
103 extern int smb3_crypto_aead_allocate(struct TCP_Server_Info *server);
104 extern unsigned long smb_rqst_len(struct TCP_Server_Info *server,
105                                   struct smb_rqst *rqst);
106 extern void smb2_set_next_command(struct cifs_tcon *tcon,
107                                   struct smb_rqst *rqst);
108 extern void smb2_set_related(struct smb_rqst *rqst);
109
110 /*
111  * SMB2 Worker functions - most of protocol specific implementation details
112  * are contained within these calls.
113  */
114 extern int SMB2_negotiate(const unsigned int xid,
115                           struct cifs_ses *ses,
116                           struct TCP_Server_Info *server);
117 extern int SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses,
118                            struct TCP_Server_Info *server,
119                            const struct nls_table *nls_cp);
120 extern int SMB2_logoff(const unsigned int xid, struct cifs_ses *ses);
121 extern int SMB2_tcon(const unsigned int xid, struct cifs_ses *ses,
122                      const char *tree, struct cifs_tcon *tcon,
123                      const struct nls_table *);
124 extern int SMB2_tdis(const unsigned int xid, struct cifs_tcon *tcon);
125 extern int SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms,
126                      __le16 *path, __u8 *oplock,
127                      struct smb2_file_all_info *buf,
128                      struct create_posix_rsp *posix,
129                      struct kvec *err_iov, int *resp_buftype);
130 extern int SMB2_open_init(struct cifs_tcon *tcon,
131                           struct TCP_Server_Info *server,
132                           struct smb_rqst *rqst,
133                           __u8 *oplock, struct cifs_open_parms *oparms,
134                           __le16 *path);
135 extern void SMB2_open_free(struct smb_rqst *rqst);
136 extern int SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon,
137                      u64 persistent_fid, u64 volatile_fid, u32 opcode,
138                      char *in_data, u32 indatalen, u32 maxoutlen,
139                      char **out_data, u32 *plen /* returned data len */);
140 extern int SMB2_ioctl_init(struct cifs_tcon *tcon,
141                            struct TCP_Server_Info *server,
142                            struct smb_rqst *rqst,
143                            u64 persistent_fid, u64 volatile_fid, u32 opcode,
144                            char *in_data, u32 indatalen,
145                            __u32 max_response_size);
146 extern void SMB2_ioctl_free(struct smb_rqst *rqst);
147 extern int SMB2_change_notify(const unsigned int xid, struct cifs_tcon *tcon,
148                         u64 persistent_fid, u64 volatile_fid, bool watch_tree,
149                         u32 completion_filter, u32 max_out_data_len,
150                         char **out_data, u32 *plen /* returned data len */);
151
152 extern int __SMB2_close(const unsigned int xid, struct cifs_tcon *tcon,
153                         u64 persistent_fid, u64 volatile_fid,
154                         struct smb2_file_network_open_info *pbuf);
155 extern int SMB2_close(const unsigned int xid, struct cifs_tcon *tcon,
156                       u64 persistent_file_id, u64 volatile_file_id);
157 extern int SMB2_close_init(struct cifs_tcon *tcon,
158                            struct TCP_Server_Info *server,
159                            struct smb_rqst *rqst,
160                            u64 persistent_fid, u64 volatile_fid,
161                            bool query_attrs);
162 extern void SMB2_close_free(struct smb_rqst *rqst);
163 extern int SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon,
164                       u64 persistent_file_id, u64 volatile_file_id);
165 extern int SMB2_flush_init(const unsigned int xid, struct smb_rqst *rqst,
166                            struct cifs_tcon *tcon,
167                            struct TCP_Server_Info *server,
168                            u64 persistent_file_id, u64 volatile_file_id);
169 extern void SMB2_flush_free(struct smb_rqst *rqst);
170 extern int SMB311_posix_query_info(const unsigned int xid, struct cifs_tcon *tcon,
171                 u64 persistent_fid, u64 volatile_fid, struct smb311_posix_qinfo *data, u32 *plen);
172 extern int SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon,
173                            u64 persistent_file_id, u64 volatile_file_id,
174                            struct smb2_file_all_info *data);
175 extern int SMB2_query_info_init(struct cifs_tcon *tcon,
176                                 struct TCP_Server_Info *server,
177                                 struct smb_rqst *rqst,
178                                 u64 persistent_fid, u64 volatile_fid,
179                                 u8 info_class, u8 info_type,
180                                 u32 additional_info, size_t output_len,
181                                 size_t input_len, void *input);
182 extern void SMB2_query_info_free(struct smb_rqst *rqst);
183 extern int SMB2_query_acl(const unsigned int xid, struct cifs_tcon *tcon,
184                           u64 persistent_file_id, u64 volatile_file_id,
185                           void **data, unsigned int *plen, u32 info);
186 extern int SMB2_get_srv_num(const unsigned int xid, struct cifs_tcon *tcon,
187                             u64 persistent_fid, u64 volatile_fid,
188                             __le64 *uniqueid);
189 extern int smb2_async_readv(struct cifs_readdata *rdata);
190 extern int SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
191                      unsigned int *nbytes, char **buf, int *buf_type);
192 extern int smb2_async_writev(struct cifs_writedata *wdata,
193                              void (*release)(struct kref *kref));
194 extern int SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
195                       unsigned int *nbytes, struct kvec *iov, int n_vec);
196 extern int SMB2_echo(struct TCP_Server_Info *server);
197 extern int SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
198                                 u64 persistent_fid, u64 volatile_fid, int index,
199                                 struct cifs_search_info *srch_inf);
200 extern int SMB2_query_directory_init(unsigned int xid, struct cifs_tcon *tcon,
201                                      struct TCP_Server_Info *server,
202                                      struct smb_rqst *rqst,
203                                      u64 persistent_fid, u64 volatile_fid,
204                                      int index, int info_level);
205 extern void SMB2_query_directory_free(struct smb_rqst *rqst);
206 extern int SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon,
207                         u64 persistent_fid, u64 volatile_fid, u32 pid,
208                         __le64 *eof);
209 extern int SMB2_set_info_init(struct cifs_tcon *tcon,
210                               struct TCP_Server_Info *server,
211                               struct smb_rqst *rqst,
212                               u64 persistent_fid, u64 volatile_fid, u32 pid,
213                               u8 info_class, u8 info_type, u32 additional_info,
214                               void **data, unsigned int *size);
215 extern void SMB2_set_info_free(struct smb_rqst *rqst);
216 extern int SMB2_set_acl(const unsigned int xid, struct cifs_tcon *tcon,
217                         u64 persistent_fid, u64 volatile_fid,
218                         struct cifs_ntsd *pnntsd, int pacllen, int aclflag);
219 extern int SMB2_set_ea(const unsigned int xid, struct cifs_tcon *tcon,
220                        u64 persistent_fid, u64 volatile_fid,
221                        struct smb2_file_full_ea_info *buf, int len);
222 extern int SMB2_set_compression(const unsigned int xid, struct cifs_tcon *tcon,
223                                 u64 persistent_fid, u64 volatile_fid);
224 extern int SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon,
225                              const u64 persistent_fid, const u64 volatile_fid,
226                              const __u8 oplock_level);
227 extern int smb2_handle_cancelled_close(struct cifs_tcon *tcon,
228                                        __u64 persistent_fid,
229                                        __u64 volatile_fid);
230 extern int smb2_handle_cancelled_mid(struct mid_q_entry *mid, struct TCP_Server_Info *server);
231 void smb2_cancelled_close_fid(struct work_struct *work);
232 extern int SMB2_QFS_info(const unsigned int xid, struct cifs_tcon *tcon,
233                          u64 persistent_file_id, u64 volatile_file_id,
234                          struct kstatfs *FSData);
235 extern int SMB311_posix_qfs_info(const unsigned int xid, struct cifs_tcon *tcon,
236                          u64 persistent_file_id, u64 volatile_file_id,
237                          struct kstatfs *FSData);
238 extern int SMB2_QFS_attr(const unsigned int xid, struct cifs_tcon *tcon,
239                          u64 persistent_file_id, u64 volatile_file_id, int lvl);
240 extern int SMB2_lock(const unsigned int xid, struct cifs_tcon *tcon,
241                      const __u64 persist_fid, const __u64 volatile_fid,
242                      const __u32 pid, const __u64 length, const __u64 offset,
243                      const __u32 lockFlags, const bool wait);
244 extern int smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon,
245                       const __u64 persist_fid, const __u64 volatile_fid,
246                       const __u32 pid, const __u32 num_lock,
247                       struct smb2_lock_element *buf);
248 extern int SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon,
249                             __u8 *lease_key, const __le32 lease_state);
250 extern int smb3_validate_negotiate(const unsigned int, struct cifs_tcon *);
251
252 extern enum securityEnum smb2_select_sectype(struct TCP_Server_Info *,
253                                         enum securityEnum);
254 int smb2_parse_contexts(struct TCP_Server_Info *server,
255                         struct kvec *rsp_iov,
256                         unsigned int *epoch,
257                         char *lease_key, __u8 *oplock,
258                         struct smb2_file_all_info *buf,
259                         struct create_posix_rsp *posix);
260
261 extern int smb3_encryption_required(const struct cifs_tcon *tcon);
262 extern int smb2_validate_iov(unsigned int offset, unsigned int buffer_length,
263                              struct kvec *iov, unsigned int min_buf_size);
264 extern int smb2_validate_and_copy_iov(unsigned int offset,
265                                       unsigned int buffer_length,
266                                       struct kvec *iov,
267                                       unsigned int minbufsize, char *data);
268 extern void smb2_copy_fs_info_to_kstatfs(
269          struct smb2_fs_full_size_info *pfs_inf,
270          struct kstatfs *kst);
271 extern int smb311_crypto_shash_allocate(struct TCP_Server_Info *server);
272 extern int smb311_update_preauth_hash(struct cifs_ses *ses,
273                                       struct TCP_Server_Info *server,
274                                       struct kvec *iov, int nvec);
275 extern int smb2_query_info_compound(const unsigned int xid,
276                                     struct cifs_tcon *tcon,
277                                     const char *path, u32 desired_access,
278                                     u32 class, u32 type, u32 output_len,
279                                     struct kvec *rsp, int *buftype,
280                                     struct cifs_sb_info *cifs_sb);
281 /* query path info from the server using SMB311 POSIX extensions*/
282 int smb311_posix_query_path_info(const unsigned int xid,
283                                  struct cifs_tcon *tcon,
284                                  struct cifs_sb_info *cifs_sb,
285                                  const char *full_path,
286                                  struct cifs_open_info_data *data,
287                                  struct cifs_sid *owner,
288                                  struct cifs_sid *group);
289 int posix_info_parse(const void *beg, const void *end,
290                      struct smb2_posix_info_parsed *out);
291 int posix_info_sid_size(const void *beg, const void *end);
292 #endif                  /* _SMB2PROTO_H */