Skip to contentSkip to conversation

cifs: do not search for channel if server is terminating

bug report Dan Carpenter 3 participants 4 messages Feb 5, 2024 – Feb 6, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hello Shyam Prasad N,

This is a semi-automatic email about new static checker warnings.

fs/smb/client/sess.c:88 cifs_ses_get_chan_index()
warn: variable dereferenced before check 'server' (see line 79)

fs/smb/client/sess.c

    78		/* if the channel is waiting for termination */
    79		if (server->terminate)
                    ^^^^^^^^^^^^^^^^^

The patch adds an unchecked dereference

    80			return CIFS_INVAL_CHAN_INDEX;
    81	
    82		for (i = 0; i < ses->chan_count; i++) {
    83			if (ses->chans[i].server == server)
    84				return i;
    85		}
    86	
    87		/* If we didn't find the channel, it is likely a bug */
    88		if (server)
                    ^^^^^^

But the existing code assumed that server could be NULL

    89			cifs_dbg(VFS, "unable to get chan index for server: 0x%llx",
    90				 server->conn_id);

regards,
dan carpenter

#1 lore raw

Shyam,
Let me know if any objections to this fix, similar to what was pointed out by Dan.

See attached.

Quoted 32 lines · Dan Carpenter

Hello Shyam Prasad N,

This is a semi-automatic email about new static checker warnings.

fs/smb/client/sess.c:88 cifs_ses_get_chan_index()
warn: variable dereferenced before check 'server' (see line 79)

fs/smb/client/sess.c

    78          /* if the channel is waiting for termination */
    79          if (server->terminate)
                    ^^^^^^^^^^^^^^^^^

The patch adds an unchecked dereference

    80                  return CIFS_INVAL_CHAN_INDEX;
    81
    82          for (i = 0; i < ses->chan_count; i++) {
    83                  if (ses->chans[i].server == server)
    84                          return i;
    85          }
    86
    87          /* If we didn't find the channel, it is likely a bug */
    88          if (server)
                    ^^^^^^

But the existing code assumed that server could be NULL

    89                  cifs_dbg(VFS, "unable to get chan index for server: 0x%llx",
    90                           server->conn_id);

regards,
dan carpenter

Signature · 3 lines
Thanks,

Steve

From afb511be9dfb27ff57b9213ef56c264eaff6db34 Mon Sep 17 00:00:00 2001
From: Steve French <[email protected]>
Date: Mon, 5 Feb 2024 14:43:17 -0600
Subject: [PATCH] smb3: add missing null server pointer check

Address static checker warning in cifs_ses_get_chan_index():
warn: variable dereferenced before check 'server'
To be consistent, and reduce risk, we should add another check for null server pointer.

Fixes 88675b22d34e ("cifs: do not search for channel if server is terminating")
Cc Shyam Prasad N <[email protected]>
---
 fs/smb/client/sess.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/sess.c +1 -1
index ed4bd88dd528..476d54fceb50 100644
@@ -76,7 +76,7 @@ cifs_ses_get_chan_index(struct cifs_ses *ses,
 	unsigned int i;
 
 	/* if the channel is waiting for termination */
-	if (server->terminate)
+	if (server && server->terminate)
 		return CIFS_INVAL_CHAN_INDEX;
 
 	for (i = 0; i < ses->chan_count; i++) {
Signature · 1 line
2.40.1
#2 lore raw
Quoted 42 lines · Steve French

Shyam,
Let me know if any objections to this fix, similar to what was pointed out by Dan.

See attached.

Quoted 32 lines · Dan Carpenter

Hello Shyam Prasad N,

This is a semi-automatic email about new static checker warnings.

fs/smb/client/sess.c:88 cifs_ses_get_chan_index()
warn: variable dereferenced before check 'server' (see line 79)

fs/smb/client/sess.c

    78          /* if the channel is waiting for termination */
    79          if (server->terminate)
                    ^^^^^^^^^^^^^^^^^

The patch adds an unchecked dereference

    80                  return CIFS_INVAL_CHAN_INDEX;
    81
    82          for (i = 0; i < ses->chan_count; i++) {
    83                  if (ses->chans[i].server == server)
    84                          return i;
    85          }
    86
    87          /* If we didn't find the channel, it is likely a bug */
    88          if (server)
                    ^^^^^^

But the existing code assumed that server could be NULL

    89                  cifs_dbg(VFS, "unable to get chan index for server: 0x%llx",
    90                           server->conn_id);

regards,
dan carpenter

Hi Dan,
Thanks for running your analysis on the changes.

Quoted 5 lines

--
Thanks,

Steve

Hi Steve,
With the current code, there should ideally be no case where a NULL server would be passed to this function. But it is always good to check explicitly.
Changes look good to me.

Signature · 2 lines
Regards,
Shyam
#3 lore raw
Quoted 59 lines · Shyam Prasad N
Quoted 42 lines · Steve French

Shyam,
Let me know if any objections to this fix, similar to what was pointed out by Dan.

See attached.

Quoted 32 lines · Dan Carpenter

Hello Shyam Prasad N,

This is a semi-automatic email about new static checker warnings.

fs/smb/client/sess.c:88 cifs_ses_get_chan_index()
warn: variable dereferenced before check 'server' (see line 79)

fs/smb/client/sess.c

    78          /* if the channel is waiting for termination */
    79          if (server->terminate)
                    ^^^^^^^^^^^^^^^^^

The patch adds an unchecked dereference

    80                  return CIFS_INVAL_CHAN_INDEX;
    81
    82          for (i = 0; i < ses->chan_count; i++) {
    83                  if (ses->chans[i].server == server)
    84                          return i;
    85          }
    86
    87          /* If we didn't find the channel, it is likely a bug */
    88          if (server)
                    ^^^^^^

But the existing code assumed that server could be NULL

    89                  cifs_dbg(VFS, "unable to get chan index for server: 0x%llx",
    90                           server->conn_id);

regards,
dan carpenter

Hi Dan,
Thanks for running your analysis on the changes.

Quoted 5 lines

--
Thanks,

Steve

Hi Steve,
With the current code, there should ideally be no case where a NULL server would be passed to this function. But it is always good to check explicitly.
Changes look good to me.

Quoted 3 lines

--
Regards,
Shyam

Added the Reviewed-by and added to cifs-2.6.git for-next

Signature · 3 lines
Thanks,

Steve