Skip to content

Commit c2f3b10

Browse files
committed
Merge tag '6.17-RC4-smb3-client-fixes' of git://git.samba.org/sfrench/cifs-2.6
Pull smb client fixes from Steve French: - Fix two potential NULL pointer references - Two debugging improvements (to help debug recent issues) a new tracepoint, and minor improvement to DebugData - Trivial comment cleanup * tag '6.17-RC4-smb3-client-fixes' of git://git.samba.org/sfrench/cifs-2.6: cifs: prevent NULL pointer dereference in UTF16 conversion smb: client: show negotiated cipher in DebugData smb: client: add new tracepoint to trace lease break notification smb: client: fix spellings in comments smb: client: Fix NULL pointer dereference in cifs_debug_dirs_proc_show()
2 parents 260aa8d + 70bccd9 commit c2f3b10

File tree

7 files changed

+96
-19
lines changed

7 files changed

+96
-19
lines changed

fs/smb/client/cifs_debug.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ static int cifs_debug_dirs_proc_show(struct seq_file *m, void *v)
304304
list_for_each(tmp1, &ses->tcon_list) {
305305
tcon = list_entry(tmp1, struct cifs_tcon, tcon_list);
306306
cfids = tcon->cfids;
307+
if (!cfids)
308+
continue;
307309
spin_lock(&cfids->cfid_list_lock); /* check lock ordering */
308310
seq_printf(m, "Num entries: %d\n", cfids->num_entries);
309311
list_for_each_entry(cfid, &cfids->entries, entry) {
@@ -319,8 +321,6 @@ static int cifs_debug_dirs_proc_show(struct seq_file *m, void *v)
319321
seq_printf(m, "\n");
320322
}
321323
spin_unlock(&cfids->cfid_list_lock);
322-
323-
324324
}
325325
}
326326
}
@@ -347,6 +347,22 @@ static __always_inline const char *compression_alg_str(__le16 alg)
347347
}
348348
}
349349

350+
static __always_inline const char *cipher_alg_str(__le16 cipher)
351+
{
352+
switch (cipher) {
353+
case SMB2_ENCRYPTION_AES128_CCM:
354+
return "AES128-CCM";
355+
case SMB2_ENCRYPTION_AES128_GCM:
356+
return "AES128-GCM";
357+
case SMB2_ENCRYPTION_AES256_CCM:
358+
return "AES256-CCM";
359+
case SMB2_ENCRYPTION_AES256_GCM:
360+
return "AES256-GCM";
361+
default:
362+
return "UNKNOWN";
363+
}
364+
}
365+
350366
static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
351367
{
352368
struct mid_q_entry *mid_entry;
@@ -539,6 +555,11 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
539555
else
540556
seq_puts(m, "disabled (not supported by this server)");
541557

558+
/* Show negotiated encryption cipher, even if not required */
559+
seq_puts(m, "\nEncryption: ");
560+
if (server->cipher_type)
561+
seq_printf(m, "Negotiated cipher (%s)", cipher_alg_str(server->cipher_type));
562+
542563
seq_printf(m, "\n\n\tSessions: ");
543564
i = 0;
544565
list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
@@ -576,12 +597,8 @@ static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
576597

577598
/* dump session id helpful for use with network trace */
578599
seq_printf(m, " SessionId: 0x%llx", ses->Suid);
579-
if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA) {
600+
if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
580601
seq_puts(m, " encrypted");
581-
/* can help in debugging to show encryption type */
582-
if (server->cipher_type == SMB2_ENCRYPTION_AES256_GCM)
583-
seq_puts(m, "(gcm256)");
584-
}
585602
if (ses->sign)
586603
seq_puts(m, " signed");
587604

fs/smb/client/cifs_unicode.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ cifs_strndup_to_utf16(const char *src, const int maxlen, int *utf16_len,
629629
int len;
630630
__le16 *dst;
631631

632+
if (!src)
633+
return NULL;
634+
632635
len = cifs_local_to_utf16_bytes(src, maxlen, cp);
633636
len += 2; /* NULL */
634637
dst = kmalloc(len, GFP_KERNEL);

fs/smb/client/reparse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ static int detect_directory_symlink_target(struct cifs_sb_info *cifs_sb,
278278
}
279279

280280
/*
281-
* For absolute symlinks it is not possible to determinate
281+
* For absolute symlinks it is not possible to determine
282282
* if it should point to directory or file.
283283
*/
284284
if (symname[0] == '/') {

fs/smb/client/smb1ops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ smb_set_file_info(struct inode *inode, const char *full_path,
10051005
rc = -EOPNOTSUPP;
10061006
}
10071007

1008-
/* Fallback to SMB_COM_SETATTR command when absolutelty needed. */
1008+
/* Fallback to SMB_COM_SETATTR command when absolutely needed. */
10091009
if (rc == -EOPNOTSUPP) {
10101010
cifs_dbg(FYI, "calling SetInformation since SetPathInfo for attrs/times not supported by this server\n");
10111011
rc = SMBSetInformation(xid, tcon, full_path,
@@ -1039,7 +1039,7 @@ smb_set_file_info(struct inode *inode, const char *full_path,
10391039
cifsFileInfo_put(open_file);
10401040

10411041
/*
1042-
* Setting the read-only bit is not honered on non-NT servers when done
1042+
* Setting the read-only bit is not honored on non-NT servers when done
10431043
* via open-semantics. So for setting it, use SMB_COM_SETATTR command.
10441044
* This command works only after the file is closed, so use it only when
10451045
* operation was called without the filehandle.

fs/smb/client/smb2misc.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,15 @@ smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server)
614614
struct cifs_tcon *tcon;
615615
struct cifs_pending_open *open;
616616

617+
/* Trace receipt of lease break request from server */
618+
trace_smb3_lease_break_enter(le32_to_cpu(rsp->CurrentLeaseState),
619+
le32_to_cpu(rsp->Flags),
620+
le16_to_cpu(rsp->Epoch),
621+
le32_to_cpu(rsp->hdr.Id.SyncId.TreeId),
622+
le64_to_cpu(rsp->hdr.SessionId),
623+
*((u64 *)rsp->LeaseKey),
624+
*((u64 *)&rsp->LeaseKey[8]));
625+
617626
cifs_dbg(FYI, "Checking for lease break\n");
618627

619628
/* If server is a channel, select the primary channel */
@@ -660,10 +669,12 @@ smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server)
660669
spin_unlock(&cifs_tcp_ses_lock);
661670
cifs_dbg(FYI, "Can not process lease break - no lease matched\n");
662671
trace_smb3_lease_not_found(le32_to_cpu(rsp->CurrentLeaseState),
663-
le32_to_cpu(rsp->hdr.Id.SyncId.TreeId),
664-
le64_to_cpu(rsp->hdr.SessionId),
665-
*((u64 *)rsp->LeaseKey),
666-
*((u64 *)&rsp->LeaseKey[8]));
672+
le32_to_cpu(rsp->Flags),
673+
le16_to_cpu(rsp->Epoch),
674+
le32_to_cpu(rsp->hdr.Id.SyncId.TreeId),
675+
le64_to_cpu(rsp->hdr.SessionId),
676+
*((u64 *)rsp->LeaseKey),
677+
*((u64 *)&rsp->LeaseKey[8]));
667678

668679
return false;
669680
}

fs/smb/client/smb2pdu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6192,11 +6192,11 @@ SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon,
61926192
please_key_high = (__u64 *)(lease_key+8);
61936193
if (rc) {
61946194
cifs_stats_fail_inc(tcon, SMB2_OPLOCK_BREAK_HE);
6195-
trace_smb3_lease_err(le32_to_cpu(lease_state), tcon->tid,
6195+
trace_smb3_lease_ack_err(le32_to_cpu(lease_state), tcon->tid,
61966196
ses->Suid, *please_key_low, *please_key_high, rc);
61976197
cifs_dbg(FYI, "Send error in Lease Break = %d\n", rc);
61986198
} else
6199-
trace_smb3_lease_done(le32_to_cpu(lease_state), tcon->tid,
6199+
trace_smb3_lease_ack_done(le32_to_cpu(lease_state), tcon->tid,
62006200
ses->Suid, *please_key_low, *please_key_high);
62016201

62026202
return rc;

fs/smb/client/trace.h

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,54 @@ DEFINE_EVENT(smb3_lease_done_class, smb3_##name, \
11711171
__u64 lease_key_high), \
11721172
TP_ARGS(lease_state, tid, sesid, lease_key_low, lease_key_high))
11731173

1174-
DEFINE_SMB3_LEASE_DONE_EVENT(lease_done);
1175-
DEFINE_SMB3_LEASE_DONE_EVENT(lease_not_found);
1174+
DEFINE_SMB3_LEASE_DONE_EVENT(lease_ack_done);
1175+
/* Tracepoint when a lease break request is received/entered (includes epoch and flags) */
1176+
DECLARE_EVENT_CLASS(smb3_lease_enter_class,
1177+
TP_PROTO(__u32 lease_state,
1178+
__u32 flags,
1179+
__u16 epoch,
1180+
__u32 tid,
1181+
__u64 sesid,
1182+
__u64 lease_key_low,
1183+
__u64 lease_key_high),
1184+
TP_ARGS(lease_state, flags, epoch, tid, sesid, lease_key_low, lease_key_high),
1185+
TP_STRUCT__entry(
1186+
__field(__u32, lease_state)
1187+
__field(__u32, flags)
1188+
__field(__u16, epoch)
1189+
__field(__u32, tid)
1190+
__field(__u64, sesid)
1191+
__field(__u64, lease_key_low)
1192+
__field(__u64, lease_key_high)
1193+
),
1194+
TP_fast_assign(
1195+
__entry->lease_state = lease_state;
1196+
__entry->flags = flags;
1197+
__entry->epoch = epoch;
1198+
__entry->tid = tid;
1199+
__entry->sesid = sesid;
1200+
__entry->lease_key_low = lease_key_low;
1201+
__entry->lease_key_high = lease_key_high;
1202+
),
1203+
TP_printk("sid=0x%llx tid=0x%x lease_key=0x%llx%llx lease_state=0x%x flags=0x%x epoch=%u",
1204+
__entry->sesid, __entry->tid, __entry->lease_key_high,
1205+
__entry->lease_key_low, __entry->lease_state, __entry->flags, __entry->epoch)
1206+
)
1207+
1208+
#define DEFINE_SMB3_LEASE_ENTER_EVENT(name) \
1209+
DEFINE_EVENT(smb3_lease_enter_class, smb3_##name, \
1210+
TP_PROTO(__u32 lease_state, \
1211+
__u32 flags, \
1212+
__u16 epoch, \
1213+
__u32 tid, \
1214+
__u64 sesid, \
1215+
__u64 lease_key_low, \
1216+
__u64 lease_key_high), \
1217+
TP_ARGS(lease_state, flags, epoch, tid, sesid, lease_key_low, lease_key_high))
1218+
1219+
DEFINE_SMB3_LEASE_ENTER_EVENT(lease_break_enter);
1220+
/* Lease not found: reuse lease_enter payload (includes epoch and flags) */
1221+
DEFINE_SMB3_LEASE_ENTER_EVENT(lease_not_found);
11761222

11771223
DECLARE_EVENT_CLASS(smb3_lease_err_class,
11781224
TP_PROTO(__u32 lease_state,
@@ -1213,7 +1259,7 @@ DEFINE_EVENT(smb3_lease_err_class, smb3_##name, \
12131259
int rc), \
12141260
TP_ARGS(lease_state, tid, sesid, lease_key_low, lease_key_high, rc))
12151261

1216-
DEFINE_SMB3_LEASE_ERR_EVENT(lease_err);
1262+
DEFINE_SMB3_LEASE_ERR_EVENT(lease_ack_err);
12171263

12181264
DECLARE_EVENT_CLASS(smb3_connect_class,
12191265
TP_PROTO(char *hostname,

0 commit comments

Comments
 (0)