Skip to content

Commit 504a73d

Browse files
committed
Merge tag '6.2-rc-ksmbd-server-fixes' of git://git.samba.org/ksmbd
Pull ksmbd updates from Steve French: "Six ksmbd server fixes" * tag '6.2-rc-ksmbd-server-fixes' of git://git.samba.org/ksmbd: ksmbd: Convert to use sysfs_emit()/sysfs_emit_at() APIs ksmbd: Fix resource leak in smb2_lock() ksmbd: Fix resource leak in ksmbd_session_rpc_open() ksmbd: replace one-element arrays with flexible-array members ksmbd: use F_SETLK when unlocking a file ksmbd: set SMB2_SESSION_FLAG_ENCRYPT_DATA when enforcing data encryption for this share
2 parents 041fae9 + 72ee45f commit 504a73d

File tree

5 files changed

+31
-24
lines changed

5 files changed

+31
-24
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/mgmt/user_session.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,17 @@ int ksmbd_session_rpc_open(struct ksmbd_session *sess, char *rpc_name)
108108
entry->method = method;
109109
entry->id = ksmbd_ipc_id_alloc();
110110
if (entry->id < 0)
111-
goto error;
111+
goto free_entry;
112112

113113
resp = ksmbd_rpc_open(sess, entry->id);
114114
if (!resp)
115-
goto error;
115+
goto free_id;
116116

117117
kvfree(resp);
118118
return entry->id;
119-
error:
119+
free_id:
120+
ksmbd_rpc_id_free(entry->id);
121+
free_entry:
120122
list_del(&entry->list);
121123
kfree(entry);
122124
return -EINVAL;

fs/ksmbd/server.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,9 @@ static ssize_t stats_show(struct class *class, struct class_attribute *attr,
432432
"reset",
433433
"shutdown"
434434
};
435-
436-
ssize_t sz = scnprintf(buf, PAGE_SIZE, "%d %s %d %lu\n", stats_version,
437-
state[server_conf.state], server_conf.tcp_port,
438-
server_conf.ipc_last_active / HZ);
439-
return sz;
435+
return sysfs_emit(buf, "%d %s %d %lu\n", stats_version,
436+
state[server_conf.state], server_conf.tcp_port,
437+
server_conf.ipc_last_active / HZ);
440438
}
441439

442440
static ssize_t kill_server_store(struct class *class,
@@ -468,19 +466,13 @@ static ssize_t debug_show(struct class *class, struct class_attribute *attr,
468466

469467
for (i = 0; i < ARRAY_SIZE(debug_type_strings); i++) {
470468
if ((ksmbd_debug_types >> i) & 1) {
471-
pos = scnprintf(buf + sz,
472-
PAGE_SIZE - sz,
473-
"[%s] ",
474-
debug_type_strings[i]);
469+
pos = sysfs_emit_at(buf, sz, "[%s] ", debug_type_strings[i]);
475470
} else {
476-
pos = scnprintf(buf + sz,
477-
PAGE_SIZE - sz,
478-
"%s ",
479-
debug_type_strings[i]);
471+
pos = sysfs_emit_at(buf, sz, "%s ", debug_type_strings[i]);
480472
}
481473
sz += pos;
482474
}
483-
sz += scnprintf(buf + sz, PAGE_SIZE - sz, "\n");
475+
sz += sysfs_emit_at(buf, sz, "\n");
484476
return sz;
485477
}
486478

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: 11 additions & 5 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

@@ -6751,7 +6753,7 @@ static int smb2_set_flock_flags(struct file_lock *flock, int flags)
67516753
case SMB2_LOCKFLAG_UNLOCK:
67526754
ksmbd_debug(SMB, "received unlock request\n");
67536755
flock->fl_type = F_UNLCK;
6754-
cmd = 0;
6756+
cmd = F_SETLK;
67556757
break;
67566758
}
67576759

@@ -6855,6 +6857,7 @@ int smb2_lock(struct ksmbd_work *work)
68556857
if (lock_start > U64_MAX - lock_length) {
68566858
pr_err("Invalid lock range requested\n");
68576859
rsp->hdr.Status = STATUS_INVALID_LOCK_RANGE;
6860+
locks_free_lock(flock);
68586861
goto out;
68596862
}
68606863

@@ -6874,6 +6877,7 @@ int smb2_lock(struct ksmbd_work *work)
68746877
"the end offset(%llx) is smaller than the start offset(%llx)\n",
68756878
flock->fl_end, flock->fl_start);
68766879
rsp->hdr.Status = STATUS_INVALID_LOCK_RANGE;
6880+
locks_free_lock(flock);
68776881
goto out;
68786882
}
68796883

@@ -6885,6 +6889,7 @@ int smb2_lock(struct ksmbd_work *work)
68856889
flock->fl_type != F_UNLCK) {
68866890
pr_err("conflict two locks in one request\n");
68876891
err = -EINVAL;
6892+
locks_free_lock(flock);
68886893
goto out;
68896894
}
68906895
}
@@ -6893,6 +6898,7 @@ int smb2_lock(struct ksmbd_work *work)
68936898
smb_lock = smb2_lock_init(flock, cmd, flags, &lock_list);
68946899
if (!smb_lock) {
68956900
err = -EINVAL;
6901+
locks_free_lock(flock);
68966902
goto out;
68976903
}
68986904
}
@@ -7129,7 +7135,7 @@ int smb2_lock(struct ksmbd_work *work)
71297135
rlock->fl_start = smb_lock->start;
71307136
rlock->fl_end = smb_lock->end;
71317137

7132-
rc = vfs_lock_file(filp, 0, rlock, NULL);
7138+
rc = vfs_lock_file(filp, F_SETLK, rlock, NULL);
71337139
if (rc)
71347140
pr_err("rollback unlock fail : %d\n", rc);
71357141

0 commit comments

Comments
 (0)