diff mbox series

ksmbd: add processed command debug log

Message ID 20231026122107.3755159-1-mmakassikis@freebox.fr
State New
Headers show
Series ksmbd: add processed command debug log | expand

Commit Message

Marios Makassikis Oct. 26, 2023, 12:21 p.m. UTC
Additional log to help identify what command is going to be
processed next.

Signed-off-by: Marios Makassikis <mmakassikis@freebox.fr>
---
 fs/smb/server/smb2pdu.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

Comments

Steve French Oct. 26, 2023, 3:52 p.m. UTC | #1
It may be helpful to define dynamic trace points (e.g.
DECLARE_EVENT_CLASS ...) for ksmbd, so can more easily do eBPF
tracing.  XFS and the cifs.ko client have multiple examples, but
fs/nfsd may have some almost exact matches on what could be defined
for fs/smb/server/trace.h and trace.c for ksmbd.ko

On Thu, Oct 26, 2023 at 7:21 AM Marios Makassikis
<mmakassikis@freebox.fr> wrote:
>
> Additional log to help identify what command is going to be
> processed next.
>
> Signed-off-by: Marios Makassikis <mmakassikis@freebox.fr>
> ---
>  fs/smb/server/smb2pdu.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
>
> diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
> index 93262ca3f58a..d2b51177f0ca 100644
> --- a/fs/smb/server/smb2pdu.c
> +++ b/fs/smb/server/smb2pdu.c
> @@ -39,6 +39,36 @@
>  #include "mgmt/ksmbd_ida.h"
>  #include "ndr.h"
>
> +static const char *const smb2_cmd_str[] = {
> +       [SMB2_NEGOTIATE_HE] = "SMB2_NEGOTIATE",
> +       [SMB2_SESSION_SETUP_HE] = "SMB2_SESSION_SETUP",
> +       [SMB2_LOGOFF_HE] = "SMB2_LOGOFF",
> +       [SMB2_TREE_CONNECT_HE] = "SMB2_TREE_CONNECT",
> +       [SMB2_TREE_DISCONNECT_HE] = "SMB2_TREE_DISCONNECT",
> +       [SMB2_CREATE_HE] = "SMB2_CREATE",
> +       [SMB2_CLOSE_HE] = "SMB2_CLOSE",
> +       [SMB2_FLUSH_HE] = "SMB2_FLUSH",
> +       [SMB2_READ_HE] = "SMB2_READ",
> +       [SMB2_WRITE_HE] = "SMB2_WRITE",
> +       [SMB2_LOCK_HE] = "SMB2_LOCK",
> +       [SMB2_IOCTL_HE] = "SMB2_IOCTL",
> +       [SMB2_CANCEL_HE] = "SMB2_CANCEL",
> +       [SMB2_ECHO_HE] = "SMB2_ECHO",
> +       [SMB2_QUERY_DIRECTORY_HE] = "SMB2_QUERY_DIRECTORY",
> +       [SMB2_CHANGE_NOTIFY_HE] = "SMB2_CHANGE_NOTIFY",
> +       [SMB2_QUERY_INFO_HE] = "SMB2_QUERY_INFO",
> +       [SMB2_SET_INFO_HE] = "SMB2_SET_INFO",
> +       [SMB2_OPLOCK_BREAK_HE] = "SMB2_OPLOCK_BREAK",
> +};
> +
> +static const char *smb2_cmd_to_str(u16 cmd)
> +{
> +       if (cmd < ARRAY_SIZE(smb2_cmd_str))
> +               return smb2_cmd_str[cmd];
> +
> +       return "unknown_cmd";
> +}
> +
>  static void __wbuf(struct ksmbd_work *work, void **req, void **rsp)
>  {
>         if (work->next_smb2_rcv_hdr_off) {
> @@ -568,6 +598,8 @@ int smb2_check_user_session(struct ksmbd_work *work)
>         unsigned int cmd = le16_to_cpu(req_hdr->Command);
>         unsigned long long sess_id;
>
> +       ksmbd_debug(SMB, "received command: %s\n",
> +                   smb2_cmd_to_str(req_hdr->Command));
>         /*
>          * SMB2_ECHO, SMB2_NEGOTIATE, SMB2_SESSION_SETUP command do not
>          * require a session id, so no need to validate user session's for
> --
> 2.34.1
>
Namjae Jeon Oct. 29, 2023, 11:41 p.m. UTC | #2
2023-10-26 21:21 GMT+09:00, Marios Makassikis <mmakassikis@freebox.fr>:
> Additional log to help identify what command is going to be
> processed next.
There are the functions that doesn't call WORK_BUFFERS(). e.g.
smb2_handle_negotiate(), smb2_cancel, smb2_ioctl(), etc... And
duplicated prints will show from smb2_sess_setup().

int smb2_sess_setup(struct ksmbd_work *work)
{
        struct ksmbd_conn *conn = work->conn;
        struct smb2_sess_setup_req *req;
        struct smb2_sess_setup_rsp *rsp;
        struct ksmbd_session *sess;
        struct negotiate_message *negblob;
        unsigned int negblob_len, negblob_off;
        int rc = 0;

        ksmbd_debug(SMB, "Received request for session setup\n");

        WORK_BUFFERS(work, req, rsp);

Thanks!
diff mbox series

Patch

diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c
index 93262ca3f58a..d2b51177f0ca 100644
--- a/fs/smb/server/smb2pdu.c
+++ b/fs/smb/server/smb2pdu.c
@@ -39,6 +39,36 @@ 
 #include "mgmt/ksmbd_ida.h"
 #include "ndr.h"
 
+static const char *const smb2_cmd_str[] = {
+	[SMB2_NEGOTIATE_HE] = "SMB2_NEGOTIATE",
+	[SMB2_SESSION_SETUP_HE] = "SMB2_SESSION_SETUP",
+	[SMB2_LOGOFF_HE] = "SMB2_LOGOFF",
+	[SMB2_TREE_CONNECT_HE] = "SMB2_TREE_CONNECT",
+	[SMB2_TREE_DISCONNECT_HE] = "SMB2_TREE_DISCONNECT",
+	[SMB2_CREATE_HE] = "SMB2_CREATE",
+	[SMB2_CLOSE_HE] = "SMB2_CLOSE",
+	[SMB2_FLUSH_HE] = "SMB2_FLUSH",
+	[SMB2_READ_HE] = "SMB2_READ",
+	[SMB2_WRITE_HE] = "SMB2_WRITE",
+	[SMB2_LOCK_HE] = "SMB2_LOCK",
+	[SMB2_IOCTL_HE] = "SMB2_IOCTL",
+	[SMB2_CANCEL_HE] = "SMB2_CANCEL",
+	[SMB2_ECHO_HE] = "SMB2_ECHO",
+	[SMB2_QUERY_DIRECTORY_HE] = "SMB2_QUERY_DIRECTORY",
+	[SMB2_CHANGE_NOTIFY_HE] = "SMB2_CHANGE_NOTIFY",
+	[SMB2_QUERY_INFO_HE] = "SMB2_QUERY_INFO",
+	[SMB2_SET_INFO_HE] = "SMB2_SET_INFO",
+	[SMB2_OPLOCK_BREAK_HE] = "SMB2_OPLOCK_BREAK",
+};
+
+static const char *smb2_cmd_to_str(u16 cmd)
+{
+	if (cmd < ARRAY_SIZE(smb2_cmd_str))
+		return smb2_cmd_str[cmd];
+
+	return "unknown_cmd";
+}
+
 static void __wbuf(struct ksmbd_work *work, void **req, void **rsp)
 {
 	if (work->next_smb2_rcv_hdr_off) {
@@ -568,6 +598,8 @@  int smb2_check_user_session(struct ksmbd_work *work)
 	unsigned int cmd = le16_to_cpu(req_hdr->Command);
 	unsigned long long sess_id;
 
+	ksmbd_debug(SMB, "received command: %s\n",
+		    smb2_cmd_to_str(req_hdr->Command));
 	/*
 	 * SMB2_ECHO, SMB2_NEGOTIATE, SMB2_SESSION_SETUP command do not
 	 * require a session id, so no need to validate user session's for