@@ -543,7 +543,7 @@ int smb2_allocate_rsp_buf(struct ksmbd_work *work)
543
543
if (le32_to_cpu (hdr -> NextCommand ) > 0 )
544
544
sz = large_sz ;
545
545
546
- work -> response_buf = kvmalloc (sz , GFP_KERNEL | __GFP_ZERO );
546
+ work -> response_buf = kvzalloc (sz , GFP_KERNEL );
547
547
if (!work -> response_buf )
548
548
return - ENOMEM ;
549
549
@@ -1322,9 +1322,8 @@ static int decode_negotiation_token(struct ksmbd_conn *conn,
1322
1322
1323
1323
static int ntlm_negotiate (struct ksmbd_work * work ,
1324
1324
struct negotiate_message * negblob ,
1325
- size_t negblob_len )
1325
+ size_t negblob_len , struct smb2_sess_setup_rsp * rsp )
1326
1326
{
1327
- struct smb2_sess_setup_rsp * rsp = smb2_get_msg (work -> response_buf );
1328
1327
struct challenge_message * chgblob ;
1329
1328
unsigned char * spnego_blob = NULL ;
1330
1329
u16 spnego_blob_len ;
@@ -1429,10 +1428,10 @@ static struct ksmbd_user *session_user(struct ksmbd_conn *conn,
1429
1428
return user ;
1430
1429
}
1431
1430
1432
- static int ntlm_authenticate (struct ksmbd_work * work )
1431
+ static int ntlm_authenticate (struct ksmbd_work * work ,
1432
+ struct smb2_sess_setup_req * req ,
1433
+ struct smb2_sess_setup_rsp * rsp )
1433
1434
{
1434
- struct smb2_sess_setup_req * req = smb2_get_msg (work -> request_buf );
1435
- struct smb2_sess_setup_rsp * rsp = smb2_get_msg (work -> response_buf );
1436
1435
struct ksmbd_conn * conn = work -> conn ;
1437
1436
struct ksmbd_session * sess = work -> sess ;
1438
1437
struct channel * chann = NULL ;
@@ -1566,10 +1565,10 @@ static int ntlm_authenticate(struct ksmbd_work *work)
1566
1565
}
1567
1566
1568
1567
#ifdef CONFIG_SMB_SERVER_KERBEROS5
1569
- static int krb5_authenticate (struct ksmbd_work * work )
1568
+ static int krb5_authenticate (struct ksmbd_work * work ,
1569
+ struct smb2_sess_setup_req * req ,
1570
+ struct smb2_sess_setup_rsp * rsp )
1570
1571
{
1571
- struct smb2_sess_setup_req * req = smb2_get_msg (work -> request_buf );
1572
- struct smb2_sess_setup_rsp * rsp = smb2_get_msg (work -> response_buf );
1573
1572
struct ksmbd_conn * conn = work -> conn ;
1574
1573
struct ksmbd_session * sess = work -> sess ;
1575
1574
char * in_blob , * out_blob ;
@@ -1647,7 +1646,9 @@ static int krb5_authenticate(struct ksmbd_work *work)
1647
1646
return 0 ;
1648
1647
}
1649
1648
#else
1650
- static int krb5_authenticate (struct ksmbd_work * work )
1649
+ static int krb5_authenticate (struct ksmbd_work * work ,
1650
+ struct smb2_sess_setup_req * req ,
1651
+ struct smb2_sess_setup_rsp * rsp )
1651
1652
{
1652
1653
return - EOPNOTSUPP ;
1653
1654
}
@@ -1656,15 +1657,17 @@ static int krb5_authenticate(struct ksmbd_work *work)
1656
1657
int smb2_sess_setup (struct ksmbd_work * work )
1657
1658
{
1658
1659
struct ksmbd_conn * conn = work -> conn ;
1659
- struct smb2_sess_setup_req * req = smb2_get_msg ( work -> request_buf ) ;
1660
- struct smb2_sess_setup_rsp * rsp = smb2_get_msg ( work -> response_buf ) ;
1660
+ struct smb2_sess_setup_req * req ;
1661
+ struct smb2_sess_setup_rsp * rsp ;
1661
1662
struct ksmbd_session * sess ;
1662
1663
struct negotiate_message * negblob ;
1663
1664
unsigned int negblob_len , negblob_off ;
1664
1665
int rc = 0 ;
1665
1666
1666
1667
ksmbd_debug (SMB , "Received request for session setup\n" );
1667
1668
1669
+ WORK_BUFFERS (work , req , rsp );
1670
+
1668
1671
rsp -> StructureSize = cpu_to_le16 (9 );
1669
1672
rsp -> SessionFlags = 0 ;
1670
1673
rsp -> SecurityBufferOffset = cpu_to_le16 (72 );
@@ -1786,7 +1789,7 @@ int smb2_sess_setup(struct ksmbd_work *work)
1786
1789
1787
1790
if (conn -> preferred_auth_mech &
1788
1791
(KSMBD_AUTH_KRB5 | KSMBD_AUTH_MSKRB5 )) {
1789
- rc = krb5_authenticate (work );
1792
+ rc = krb5_authenticate (work , req , rsp );
1790
1793
if (rc ) {
1791
1794
rc = - EINVAL ;
1792
1795
goto out_err ;
@@ -1800,7 +1803,7 @@ int smb2_sess_setup(struct ksmbd_work *work)
1800
1803
sess -> Preauth_HashValue = NULL ;
1801
1804
} else if (conn -> preferred_auth_mech == KSMBD_AUTH_NTLMSSP ) {
1802
1805
if (negblob -> MessageType == NtLmNegotiate ) {
1803
- rc = ntlm_negotiate (work , negblob , negblob_len );
1806
+ rc = ntlm_negotiate (work , negblob , negblob_len , rsp );
1804
1807
if (rc )
1805
1808
goto out_err ;
1806
1809
rsp -> hdr .Status =
@@ -1813,7 +1816,7 @@ int smb2_sess_setup(struct ksmbd_work *work)
1813
1816
le16_to_cpu (rsp -> SecurityBufferLength ) - 1 );
1814
1817
1815
1818
} else if (negblob -> MessageType == NtLmAuthenticate ) {
1816
- rc = ntlm_authenticate (work );
1819
+ rc = ntlm_authenticate (work , req , rsp );
1817
1820
if (rc )
1818
1821
goto out_err ;
1819
1822
@@ -1911,14 +1914,16 @@ int smb2_sess_setup(struct ksmbd_work *work)
1911
1914
int smb2_tree_connect (struct ksmbd_work * work )
1912
1915
{
1913
1916
struct ksmbd_conn * conn = work -> conn ;
1914
- struct smb2_tree_connect_req * req = smb2_get_msg ( work -> request_buf ) ;
1915
- struct smb2_tree_connect_rsp * rsp = smb2_get_msg ( work -> response_buf ) ;
1917
+ struct smb2_tree_connect_req * req ;
1918
+ struct smb2_tree_connect_rsp * rsp ;
1916
1919
struct ksmbd_session * sess = work -> sess ;
1917
1920
char * treename = NULL , * name = NULL ;
1918
1921
struct ksmbd_tree_conn_status status ;
1919
1922
struct ksmbd_share_config * share ;
1920
1923
int rc = - EINVAL ;
1921
1924
1925
+ WORK_BUFFERS (work , req , rsp );
1926
+
1922
1927
treename = smb_strndup_from_utf16 (req -> Buffer ,
1923
1928
le16_to_cpu (req -> PathLength ), true,
1924
1929
conn -> local_nls );
@@ -2087,19 +2092,19 @@ static int smb2_create_open_flags(bool file_present, __le32 access,
2087
2092
*/
2088
2093
int smb2_tree_disconnect (struct ksmbd_work * work )
2089
2094
{
2090
- struct smb2_tree_disconnect_rsp * rsp = smb2_get_msg (work -> response_buf );
2095
+ struct smb2_tree_disconnect_rsp * rsp ;
2096
+ struct smb2_tree_disconnect_req * req ;
2091
2097
struct ksmbd_session * sess = work -> sess ;
2092
2098
struct ksmbd_tree_connect * tcon = work -> tcon ;
2093
2099
2100
+ WORK_BUFFERS (work , req , rsp );
2101
+
2094
2102
rsp -> StructureSize = cpu_to_le16 (4 );
2095
2103
inc_rfc1001_len (work -> response_buf , 4 );
2096
2104
2097
2105
ksmbd_debug (SMB , "request\n" );
2098
2106
2099
2107
if (!tcon || test_and_set_bit (TREE_CONN_EXPIRE , & tcon -> status )) {
2100
- struct smb2_tree_disconnect_req * req =
2101
- smb2_get_msg (work -> request_buf );
2102
-
2103
2108
ksmbd_debug (SMB , "Invalid tid %d\n" , req -> hdr .Id .SyncId .TreeId );
2104
2109
2105
2110
rsp -> hdr .Status = STATUS_NETWORK_NAME_DELETED ;
@@ -2122,10 +2127,14 @@ int smb2_tree_disconnect(struct ksmbd_work *work)
2122
2127
int smb2_session_logoff (struct ksmbd_work * work )
2123
2128
{
2124
2129
struct ksmbd_conn * conn = work -> conn ;
2125
- struct smb2_logoff_rsp * rsp = smb2_get_msg (work -> response_buf );
2130
+ struct smb2_logoff_req * req ;
2131
+ struct smb2_logoff_rsp * rsp ;
2126
2132
struct ksmbd_session * sess ;
2127
- struct smb2_logoff_req * req = smb2_get_msg (work -> request_buf );
2128
- u64 sess_id = le64_to_cpu (req -> hdr .SessionId );
2133
+ u64 sess_id ;
2134
+
2135
+ WORK_BUFFERS (work , req , rsp );
2136
+
2137
+ sess_id = le64_to_cpu (req -> hdr .SessionId );
2129
2138
2130
2139
rsp -> StructureSize = cpu_to_le16 (4 );
2131
2140
inc_rfc1001_len (work -> response_buf , 4 );
@@ -2165,12 +2174,14 @@ int smb2_session_logoff(struct ksmbd_work *work)
2165
2174
*/
2166
2175
static noinline int create_smb2_pipe (struct ksmbd_work * work )
2167
2176
{
2168
- struct smb2_create_rsp * rsp = smb2_get_msg ( work -> response_buf ) ;
2169
- struct smb2_create_req * req = smb2_get_msg ( work -> request_buf ) ;
2177
+ struct smb2_create_rsp * rsp ;
2178
+ struct smb2_create_req * req ;
2170
2179
int id ;
2171
2180
int err ;
2172
2181
char * name ;
2173
2182
2183
+ WORK_BUFFERS (work , req , rsp );
2184
+
2174
2185
name = smb_strndup_from_utf16 (req -> Buffer , le16_to_cpu (req -> NameLength ),
2175
2186
1 , work -> conn -> local_nls );
2176
2187
if (IS_ERR (name )) {
@@ -2872,11 +2883,9 @@ int smb2_open(struct ksmbd_work *work)
2872
2883
if (!file_present ) {
2873
2884
daccess = cpu_to_le32 (GENERIC_ALL_FLAGS );
2874
2885
} else {
2875
- rc = ksmbd_vfs_query_maximal_access (idmap ,
2886
+ ksmbd_vfs_query_maximal_access (idmap ,
2876
2887
path .dentry ,
2877
2888
& daccess );
2878
- if (rc )
2879
- goto err_out ;
2880
2889
already_permitted = true;
2881
2890
}
2882
2891
maximal_access = daccess ;
@@ -5305,8 +5314,10 @@ int smb2_query_info(struct ksmbd_work *work)
5305
5314
static noinline int smb2_close_pipe (struct ksmbd_work * work )
5306
5315
{
5307
5316
u64 id ;
5308
- struct smb2_close_req * req = smb2_get_msg (work -> request_buf );
5309
- struct smb2_close_rsp * rsp = smb2_get_msg (work -> response_buf );
5317
+ struct smb2_close_req * req ;
5318
+ struct smb2_close_rsp * rsp ;
5319
+
5320
+ WORK_BUFFERS (work , req , rsp );
5310
5321
5311
5322
id = req -> VolatileFileId ;
5312
5323
ksmbd_session_rpc_close (work -> sess , id );
@@ -5448,6 +5459,9 @@ int smb2_echo(struct ksmbd_work *work)
5448
5459
{
5449
5460
struct smb2_echo_rsp * rsp = smb2_get_msg (work -> response_buf );
5450
5461
5462
+ if (work -> next_smb2_rcv_hdr_off )
5463
+ rsp = ksmbd_resp_buf_next (work );
5464
+
5451
5465
rsp -> StructureSize = cpu_to_le16 (4 );
5452
5466
rsp -> Reserved = 0 ;
5453
5467
inc_rfc1001_len (work -> response_buf , 4 );
@@ -6082,8 +6096,10 @@ static noinline int smb2_read_pipe(struct ksmbd_work *work)
6082
6096
int nbytes = 0 , err ;
6083
6097
u64 id ;
6084
6098
struct ksmbd_rpc_command * rpc_resp ;
6085
- struct smb2_read_req * req = smb2_get_msg (work -> request_buf );
6086
- struct smb2_read_rsp * rsp = smb2_get_msg (work -> response_buf );
6099
+ struct smb2_read_req * req ;
6100
+ struct smb2_read_rsp * rsp ;
6101
+
6102
+ WORK_BUFFERS (work , req , rsp );
6087
6103
6088
6104
id = req -> VolatileFileId ;
6089
6105
@@ -6096,7 +6112,7 @@ static noinline int smb2_read_pipe(struct ksmbd_work *work)
6096
6112
}
6097
6113
6098
6114
work -> aux_payload_buf =
6099
- kvmalloc (rpc_resp -> payload_sz , GFP_KERNEL | __GFP_ZERO );
6115
+ kvmalloc (rpc_resp -> payload_sz , GFP_KERNEL );
6100
6116
if (!work -> aux_payload_buf ) {
6101
6117
err = - ENOMEM ;
6102
6118
goto out ;
@@ -6248,7 +6264,7 @@ int smb2_read(struct ksmbd_work *work)
6248
6264
ksmbd_debug (SMB , "filename %pD, offset %lld, len %zu\n" ,
6249
6265
fp -> filp , offset , length );
6250
6266
6251
- work -> aux_payload_buf = kvmalloc (length , GFP_KERNEL | __GFP_ZERO );
6267
+ work -> aux_payload_buf = kvzalloc (length , GFP_KERNEL );
6252
6268
if (!work -> aux_payload_buf ) {
6253
6269
err = - ENOMEM ;
6254
6270
goto out ;
@@ -6331,14 +6347,16 @@ int smb2_read(struct ksmbd_work *work)
6331
6347
*/
6332
6348
static noinline int smb2_write_pipe (struct ksmbd_work * work )
6333
6349
{
6334
- struct smb2_write_req * req = smb2_get_msg ( work -> request_buf ) ;
6335
- struct smb2_write_rsp * rsp = smb2_get_msg ( work -> response_buf ) ;
6350
+ struct smb2_write_req * req ;
6351
+ struct smb2_write_rsp * rsp ;
6336
6352
struct ksmbd_rpc_command * rpc_resp ;
6337
6353
u64 id = 0 ;
6338
6354
int err = 0 , ret = 0 ;
6339
6355
char * data_buf ;
6340
6356
size_t length ;
6341
6357
6358
+ WORK_BUFFERS (work , req , rsp );
6359
+
6342
6360
length = le32_to_cpu (req -> Length );
6343
6361
id = req -> VolatileFileId ;
6344
6362
@@ -6397,7 +6415,7 @@ static ssize_t smb2_write_rdma_channel(struct ksmbd_work *work,
6397
6415
int ret ;
6398
6416
ssize_t nbytes ;
6399
6417
6400
- data_buf = kvmalloc (length , GFP_KERNEL | __GFP_ZERO );
6418
+ data_buf = kvzalloc (length , GFP_KERNEL );
6401
6419
if (!data_buf )
6402
6420
return - ENOMEM ;
6403
6421
@@ -6607,6 +6625,9 @@ int smb2_cancel(struct ksmbd_work *work)
6607
6625
struct ksmbd_work * iter ;
6608
6626
struct list_head * command_list ;
6609
6627
6628
+ if (work -> next_smb2_rcv_hdr_off )
6629
+ hdr = ksmbd_resp_buf_next (work );
6630
+
6610
6631
ksmbd_debug (SMB , "smb2 cancel called on mid %llu, async flags 0x%x\n" ,
6611
6632
hdr -> MessageId , hdr -> Flags );
6612
6633
@@ -6766,8 +6787,8 @@ static inline bool lock_defer_pending(struct file_lock *fl)
6766
6787
*/
6767
6788
int smb2_lock (struct ksmbd_work * work )
6768
6789
{
6769
- struct smb2_lock_req * req = smb2_get_msg ( work -> request_buf ) ;
6770
- struct smb2_lock_rsp * rsp = smb2_get_msg ( work -> response_buf ) ;
6790
+ struct smb2_lock_req * req ;
6791
+ struct smb2_lock_rsp * rsp ;
6771
6792
struct smb2_lock_element * lock_ele ;
6772
6793
struct ksmbd_file * fp = NULL ;
6773
6794
struct file_lock * flock = NULL ;
@@ -6784,6 +6805,8 @@ int smb2_lock(struct ksmbd_work *work)
6784
6805
LIST_HEAD (rollback_list );
6785
6806
int prior_lock = 0 ;
6786
6807
6808
+ WORK_BUFFERS (work , req , rsp );
6809
+
6787
6810
ksmbd_debug (SMB , "Received lock request\n" );
6788
6811
fp = ksmbd_lookup_fd_slow (work , req -> VolatileFileId , req -> PersistentFileId );
6789
6812
if (!fp ) {
@@ -7897,8 +7920,8 @@ int smb2_ioctl(struct ksmbd_work *work)
7897
7920
*/
7898
7921
static void smb20_oplock_break_ack (struct ksmbd_work * work )
7899
7922
{
7900
- struct smb2_oplock_break * req = smb2_get_msg ( work -> request_buf ) ;
7901
- struct smb2_oplock_break * rsp = smb2_get_msg ( work -> response_buf ) ;
7923
+ struct smb2_oplock_break * req ;
7924
+ struct smb2_oplock_break * rsp ;
7902
7925
struct ksmbd_file * fp ;
7903
7926
struct oplock_info * opinfo = NULL ;
7904
7927
__le32 err = 0 ;
@@ -7907,6 +7930,8 @@ static void smb20_oplock_break_ack(struct ksmbd_work *work)
7907
7930
char req_oplevel = 0 , rsp_oplevel = 0 ;
7908
7931
unsigned int oplock_change_type ;
7909
7932
7933
+ WORK_BUFFERS (work , req , rsp );
7934
+
7910
7935
volatile_id = req -> VolatileFid ;
7911
7936
persistent_id = req -> PersistentFid ;
7912
7937
req_oplevel = req -> OplockLevel ;
@@ -8041,15 +8066,17 @@ static int check_lease_state(struct lease *lease, __le32 req_state)
8041
8066
static void smb21_lease_break_ack (struct ksmbd_work * work )
8042
8067
{
8043
8068
struct ksmbd_conn * conn = work -> conn ;
8044
- struct smb2_lease_ack * req = smb2_get_msg ( work -> request_buf ) ;
8045
- struct smb2_lease_ack * rsp = smb2_get_msg ( work -> response_buf ) ;
8069
+ struct smb2_lease_ack * req ;
8070
+ struct smb2_lease_ack * rsp ;
8046
8071
struct oplock_info * opinfo ;
8047
8072
__le32 err = 0 ;
8048
8073
int ret = 0 ;
8049
8074
unsigned int lease_change_type ;
8050
8075
__le32 lease_state ;
8051
8076
struct lease * lease ;
8052
8077
8078
+ WORK_BUFFERS (work , req , rsp );
8079
+
8053
8080
ksmbd_debug (OPLOCK , "smb21 lease break, lease state(0x%x)\n" ,
8054
8081
le32_to_cpu (req -> LeaseState ));
8055
8082
opinfo = lookup_lease_in_table (conn , req -> LeaseKey );
@@ -8175,8 +8202,10 @@ static void smb21_lease_break_ack(struct ksmbd_work *work)
8175
8202
*/
8176
8203
int smb2_oplock_break (struct ksmbd_work * work )
8177
8204
{
8178
- struct smb2_oplock_break * req = smb2_get_msg (work -> request_buf );
8179
- struct smb2_oplock_break * rsp = smb2_get_msg (work -> response_buf );
8205
+ struct smb2_oplock_break * req ;
8206
+ struct smb2_oplock_break * rsp ;
8207
+
8208
+ WORK_BUFFERS (work , req , rsp );
8180
8209
8181
8210
switch (le16_to_cpu (req -> StructureSize )) {
8182
8211
case OP_BREAK_STRUCT_SIZE_20 :
0 commit comments