Skip to content

Commit 37ba7b0

Browse files
namjaejeonsmfrench
authored andcommitted
ksmbd: set SMB2_SESSION_FLAG_ENCRYPT_DATA when enforcing data encryption for this share
Currently, SMB2_SESSION_FLAG_ENCRYPT_DATA is always set session setup response. Since this forces data encryption from the client, there is a problem that data is always encrypted regardless of the use of the cifs seal mount option. SMB2_SESSION_FLAG_ENCRYPT_DATA should be set according to KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION flags, and in case of KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION_OFF, encryption mode is turned off for all connections. Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 76dcd73 commit 37ba7b0

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

fs/ksmbd/ksmbd_netlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct ksmbd_heartbeat {
7474
#define KSMBD_GLOBAL_FLAG_SMB2_LEASES BIT(0)
7575
#define KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION BIT(1)
7676
#define KSMBD_GLOBAL_FLAG_SMB3_MULTICHANNEL BIT(2)
77+
#define KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION_OFF BIT(3)
7778

7879
/*
7980
* IPC request for ksmbd server startup

fs/ksmbd/smb2ops.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,9 @@ void init_smb3_02_server(struct ksmbd_conn *conn)
247247
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
248248
conn->vals->capabilities |= SMB2_GLOBAL_CAP_LEASING;
249249

250-
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION &&
251-
conn->cli_cap & SMB2_GLOBAL_CAP_ENCRYPTION)
250+
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION ||
251+
(!(server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION_OFF) &&
252+
conn->cli_cap & SMB2_GLOBAL_CAP_ENCRYPTION))
252253
conn->vals->capabilities |= SMB2_GLOBAL_CAP_ENCRYPTION;
253254

254255
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB3_MULTICHANNEL)
@@ -271,6 +272,11 @@ int init_smb3_11_server(struct ksmbd_conn *conn)
271272
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_LEASES)
272273
conn->vals->capabilities |= SMB2_GLOBAL_CAP_LEASING;
273274

275+
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION ||
276+
(!(server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION_OFF) &&
277+
conn->cli_cap & SMB2_GLOBAL_CAP_ENCRYPTION))
278+
conn->vals->capabilities |= SMB2_GLOBAL_CAP_ENCRYPTION;
279+
274280
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB3_MULTICHANNEL)
275281
conn->vals->capabilities |= SMB2_GLOBAL_CAP_MULTI_CHANNEL;
276282

fs/ksmbd/smb2pdu.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ static void decode_encrypt_ctxt(struct ksmbd_conn *conn,
903903
return;
904904
}
905905

906-
if (!(server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION))
906+
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION_OFF)
907907
return;
908908

909909
for (i = 0; i < cph_cnt; i++) {
@@ -1508,7 +1508,8 @@ static int ntlm_authenticate(struct ksmbd_work *work)
15081508
return -EINVAL;
15091509
}
15101510
sess->enc = true;
1511-
rsp->SessionFlags = SMB2_SESSION_FLAG_ENCRYPT_DATA_LE;
1511+
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION)
1512+
rsp->SessionFlags = SMB2_SESSION_FLAG_ENCRYPT_DATA_LE;
15121513
/*
15131514
* signing is disable if encryption is enable
15141515
* on this session
@@ -1599,7 +1600,8 @@ static int krb5_authenticate(struct ksmbd_work *work)
15991600
return -EINVAL;
16001601
}
16011602
sess->enc = true;
1602-
rsp->SessionFlags = SMB2_SESSION_FLAG_ENCRYPT_DATA_LE;
1603+
if (server_conf.flags & KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION)
1604+
rsp->SessionFlags = SMB2_SESSION_FLAG_ENCRYPT_DATA_LE;
16031605
sess->sign = false;
16041606
}
16051607

0 commit comments

Comments
 (0)