Skip to contentSkip to conversation

Fix various coverity warnings in fs/cifs

PATCH In review Steve French 5 participants 19 messages Mar 27, 2015 – Apr 1, 2015

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

cover Fix various coverity warnings in fs/cifs

Four small fixes to address warnings coverity analyzer displays for fs/cifs.

Steve French (4):
[SMB3] Fix warning on uninitialized buftype
[CIFS] Don't ignore errors on encrypting password in SMBTcon [SMB3] Fix dereference before null check warning [SMB3] Fix coverity warning

 fs/cifs/connect.c  |  6 ++++++
 fs/cifs/smb2misc.c |  2 +-
 fs/cifs/smb2pdu.c  | 15 +++++++++------
 3 files changed, 16 insertions(+), 7 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/4 Fix warning on uninitialized buftype

Pointed out by coverity analyzer. resp_buftype is not initialized in one path which can rarely log a spurious warning (buf is null so there will not be a problem with freeing data, but if buf_type were randomly set to wrong value could log a warning)

Reported by Coverity (CID 1269144)

---
 fs/cifs/smb2pdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/smb2pdu.c +1 -1
index 3417340..1b906de 100644
@@ -2114,7 +2114,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
 	struct kvec iov[2];
 	int rc = 0;
 	int len;
-	int resp_buftype;
+	int resp_buftype = CIFS_NO_BUFFER;
 	unsigned char *bufptr;
 	struct TCP_Server_Info *server;
 	struct cifs_ses *ses = tcon->ses;
Signature · 1 line
1.9.1
Acked-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] [SMB3] Fix warning on uninitialized buftype

Looks correct.

Quoted 33 lines · Steve French

Pointed out by coverity analyzer. resp_buftype is not initialized in one path which can rarely log a spurious warning (buf is null so there will not be a problem with freeing data, but if buf_type were randomly set to wrong value could log a warning)

Reported by Coverity (CID 1269144)

---
 fs/cifs/smb2pdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/smb2pdu.c +1 -2
index 3417340..1b906de 100644
@@ -2114,7 +2114,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
        struct kvec iov[2];
        int rc = 0;
        int len;
-       int resp_buftype;
+       int resp_buftype = CIFS_NO_BUFFER;
        unsigned char *bufptr;
        struct TCP_Server_Info *server;
        struct cifs_ses *ses = tcon->ses;
--

1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Acked-by on v1 1/4
#3 lore raw

Re: [PATCH 1/4] [SMB3] Fix warning on uninitialized buftype

In reply to Steve French
Quoted 9 lines · Steve French

Pointed out by coverity analyzer. resp_buftype is not initialized in one path which can rarely log a spurious warning (buf is null so there will not be a problem with freeing data, but if buf_type were randomly set to wrong value could log a warning)

Reported by Coverity (CID 1269144)

Quoted 17 lines
---
 fs/cifs/smb2pdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/smb2pdu.c +1 -1
index 3417340..1b906de 100644
@@ -2114,7 +2114,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
 	struct kvec iov[2];
 	int rc = 0;
 	int len;
-	int resp_buftype;
+	int resp_buftype = CIFS_NO_BUFFER;
 	unsigned char *bufptr;
 	struct TCP_Server_Info *server;
 	struct cifs_ses *ses = tcon->ses;
Reviewed-by on v1 1/4
#4 lore raw

Re: [PATCH 1/4] [SMB3] Fix warning on uninitialized buftype

In reply to Steve French
Quoted 18 lines · On Fri, 27 Mar 2015 00:27:59 -0500 Steve French <[email protected]> wrote:

Pointed out by coverity analyzer. resp_buftype is not initialized in one path which can rarely log a spurious warning (buf is null so there will not be a problem with freeing data, but if buf_type were randomly set to wrong value could log a warning)

Reported by Coverity (CID 1269144)

---
 fs/cifs/smb2pdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/smb2pdu.c +0 -0
index 3417340..1b906de 100644

fs/cifs/smb2pdu.c SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, · line 2120

Quoted 8 lines
fs/cifs/smb2pdu.c +1 -1
@@ -2114,7 +2114,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
 	struct kvec iov[2];
 	int rc = 0;
 	int len;
-	int resp_buftype;
+	int resp_buftype = CIFS_NO_BUFFER;
 	unsigned char *bufptr;
 	struct TCP_Server_Info *server;
 	struct cifs_ses *ses = tcon->ses;
#5 lore raw

PATCH 2/4 Don't ignore errors on encrypting password in SMBTcon

In reply to Steve French

Although unlikely to fail (and tree connect does not commonly send a password since SECMODE_USER is the default for most servers) do not ignore errors on SMBNTEncrypt in SMB Tree Connect.

Reported by Coverity (CID 1226853)

---
 fs/cifs/connect.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/cifs/connect.c +6 -0
index 4cb8450..cdb1aaf 100644
@@ -3696,6 +3696,12 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses,
 #endif /* CIFS_WEAK_PW_HASH */
 		rc = SMBNTencrypt(tcon->password, ses->server->cryptkey,
 					bcc_ptr, nls_codepage);
+		if (rc) {
+			cifs_dbg(FYI, "%s Can't generate NTLM rsp. Error: %d\n",
+				 __func__, rc);
+			cifs_buf_release(smb_buffer);
+			return rc;
+		}
 
 		bcc_ptr += CIFS_AUTH_RESP_SIZE;
 		if (ses->capabilities & CAP_UNICODE) {
Signature · 1 line
1.9.1
Acked-by on v1 2/4
#6 lore raw

Re: [PATCH 2/4] [CIFS] Don't ignore errors on encrypting password in SMBTcon

Looks correct, although we could just goto a label at the end of this function which
does the same.

Quoted 35 lines · Steve French

Although unlikely to fail (and tree connect does not commonly send a password since SECMODE_USER is the default for most servers) do not ignore errors on SMBNTEncrypt in SMB Tree Connect.

Reported by Coverity (CID 1226853)

---
 fs/cifs/connect.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/cifs/connect.c +6 -1
index 4cb8450..cdb1aaf 100644
@@ -3696,6 +3696,12 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses,
 #endif /* CIFS_WEAK_PW_HASH */
                rc = SMBNTencrypt(tcon->password, ses->server->cryptkey,
                                        bcc_ptr, nls_codepage);
+               if (rc) {
+                       cifs_dbg(FYI, "%s Can't generate NTLM rsp. Error: %d\n",
+                                __func__, rc);
+                       cifs_buf_release(smb_buffer);
+                       return rc;
+               }
 
                bcc_ptr += CIFS_AUTH_RESP_SIZE;
                if (ses->capabilities & CAP_UNICODE) {
--

1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Acked-by on v1 2/4
#7 lore raw

Re: [PATCH 2/4] [CIFS] Don't ignore errors on encrypting password in SMBTcon

In reply to Steve French
Quoted 7 lines · Steve French

Although unlikely to fail (and tree connect does not commonly send a password since SECMODE_USER is the default for most servers) do not ignore errors on SMBNTEncrypt in SMB Tree Connect.

Reported by Coverity (CID 1226853)

Quoted 21 lines
---
 fs/cifs/connect.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/cifs/connect.c +6 -0
index 4cb8450..cdb1aaf 100644
@@ -3696,6 +3696,12 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses,
 #endif /* CIFS_WEAK_PW_HASH */
 		rc = SMBNTencrypt(tcon->password, ses->server->cryptkey,
 					bcc_ptr, nls_codepage);
+		if (rc) {
+			cifs_dbg(FYI, "%s Can't generate NTLM rsp. Error: %d\n",
+				 __func__, rc);
+			cifs_buf_release(smb_buffer);
+			return rc;
+		}
 
 		bcc_ptr += CIFS_AUTH_RESP_SIZE;
 		if (ses->capabilities & CAP_UNICODE) {
#8 lore raw

Re: [PATCH 2/4] [CIFS] Don't ignore errors on encrypting password in SMBTcon

In reply to Steve French
Quoted 18 lines · On Fri, 27 Mar 2015 00:28:00 -0500 Steve French…

Although unlikely to fail (and tree connect does not commonly send a password since SECMODE_USER is the default for most servers) do not ignore errors on SMBNTEncrypt in SMB Tree Connect.

Reported by Coverity (CID 1226853)

---
 fs/cifs/connect.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/cifs/connect.c +0 -0
index 4cb8450..cdb1aaf 100644
@@ -3696,6 +3696,12 @@ CIFSTCon(const unsigned int xid, struct cifs_ses *ses,
 #endif /* CIFS_WEAK_PW_HASH */
 		rc = SMBNTencrypt(tcon->password, ses->server->cryptkey,

fs/cifs/connect.c CIFSTCon(const unsigned int xid, struct cifs_ses *ses, · line 3707

Quoted 10 lines
fs/cifs/connect.c +6 -0
 					bcc_ptr, nls_codepage);
+		if (rc) {
+			cifs_dbg(FYI, "%s Can't generate NTLM rsp. Error: %d\n",
+				 __func__, rc);
+			cifs_buf_release(smb_buffer);
+			return rc;
+		}
 
 		bcc_ptr += CIFS_AUTH_RESP_SIZE;
 		if (ses->capabilities & CAP_UNICODE) {

Acked-by:

Signature · 1 line
Jeff Layton <[email protected]>
#9 lore raw

PATCH 3/4 Fix dereference before null check warning

In reply to Steve French

null tcon is not likely in these paths in current
code, but obviously it does clarify the code to
check for null (if at all) before derefrencing
rather than after.

Reported by Coverity (CID 1042666)

---
 fs/cifs/smb2pdu.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
fs/cifs/smb2pdu.c +8 -5
index 1b906de..78b329f 100644
@@ -1218,7 +1218,7 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
 	struct smb2_ioctl_req *req;
 	struct smb2_ioctl_rsp *rsp;
 	struct TCP_Server_Info *server;
-	struct cifs_ses *ses = tcon->ses;
+	struct cifs_ses *ses;
 	struct kvec iov[2];
 	int resp_buftype;
 	int num_iovecs;
@@ -1233,6 +1233,11 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
 	if (plen)
 		*plen = 0;
 
+	if (tcon)
+		ses = tcon->ses;
+	else
+		return -EIO;
+
 	if (ses && (ses->server))
 		server = ses->server;
 	else
@@ -1296,14 +1301,12 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
 	rsp = (struct smb2_ioctl_rsp *)iov[0].iov_base;
 
 	if ((rc != 0) && (rc != -EINVAL)) {
-		if (tcon)
-			cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
+		cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
 		goto ioctl_exit;
 	} else if (rc == -EINVAL) {
 		if ((opcode != FSCTL_SRV_COPYCHUNK_WRITE) &&
 		    (opcode != FSCTL_SRV_COPYCHUNK)) {
-			if (tcon)
-				cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
+			cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
 			goto ioctl_exit;
 		}
 	}
Signature · 1 line
1.9.1
Acked-by on v1 3/4
#10 lore raw

Re: [PATCH 3/4] [SMB3] Fix dereference before null check warning

Looks correct.

Quoted 61 lines · Steve French

null tcon is not likely in these paths in current
code, but obviously it does clarify the code to
check for null (if at all) before derefrencing
rather than after.

Reported by Coverity (CID 1042666)

---
 fs/cifs/smb2pdu.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
fs/cifs/smb2pdu.c +8 -6
index 1b906de..78b329f 100644
@@ -1218,7 +1218,7 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
        struct smb2_ioctl_req *req;
        struct smb2_ioctl_rsp *rsp;
        struct TCP_Server_Info *server;
-       struct cifs_ses *ses = tcon->ses;
+       struct cifs_ses *ses;
        struct kvec iov[2];
        int resp_buftype;
        int num_iovecs;
@@ -1233,6 +1233,11 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
        if (plen)
                *plen = 0;
 
+       if (tcon)
+               ses = tcon->ses;
+       else
+               return -EIO;
+
        if (ses && (ses->server))
                server = ses->server;
        else
@@ -1296,14 +1301,12 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
        rsp = (struct smb2_ioctl_rsp *)iov[0].iov_base;
 
        if ((rc != 0) && (rc != -EINVAL)) {
-               if (tcon)
-                       cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
+               cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
                goto ioctl_exit;
        } else if (rc == -EINVAL) {
                if ((opcode != FSCTL_SRV_COPYCHUNK_WRITE) &&
                    (opcode != FSCTL_SRV_COPYCHUNK)) {
-                       if (tcon)
-                               cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
+                       cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
                        goto ioctl_exit;
                }
        }
--

1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Acked-by on v1 3/4
#11 lore raw

Re: [PATCH 3/4] [SMB3] Fix dereference before null check warning

In reply to Steve French
Quoted 8 lines · Steve French

null tcon is not likely in these paths in current
code, but obviously it does clarify the code to
check for null (if at all) before derefrencing
rather than after.

Reported by Coverity (CID 1042666)

Quoted 46 lines
---
 fs/cifs/smb2pdu.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
fs/cifs/smb2pdu.c +8 -5
index 1b906de..78b329f 100644
@@ -1218,7 +1218,7 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
 	struct smb2_ioctl_req *req;
 	struct smb2_ioctl_rsp *rsp;
 	struct TCP_Server_Info *server;
-	struct cifs_ses *ses = tcon->ses;
+	struct cifs_ses *ses;
 	struct kvec iov[2];
 	int resp_buftype;
 	int num_iovecs;
@@ -1233,6 +1233,11 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
 	if (plen)
 		*plen = 0;
 
+	if (tcon)
+		ses = tcon->ses;
+	else
+		return -EIO;
+
 	if (ses && (ses->server))
 		server = ses->server;
 	else
@@ -1296,14 +1301,12 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
 	rsp = (struct smb2_ioctl_rsp *)iov[0].iov_base;
 
 	if ((rc != 0) && (rc != -EINVAL)) {
-		if (tcon)
-			cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
+		cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
 		goto ioctl_exit;
 	} else if (rc == -EINVAL) {
 		if ((opcode != FSCTL_SRV_COPYCHUNK_WRITE) &&
 		    (opcode != FSCTL_SRV_COPYCHUNK)) {
-			if (tcon)
-				cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
+			cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
 			goto ioctl_exit;
 		}
 	}
#12 lore raw

Re: [PATCH 3/4] [SMB3] Fix dereference before null check warning

In reply to Steve French
Quoted 8 lines · On Fri, 27 Mar 2015 00:28:01 -0500 Steve French <[email protected]> wrote:

null tcon is not likely in these paths in current
code, but obviously it does clarify the code to
check for null (if at all) before derefrencing
rather than after.

Reported by Coverity (CID 1042666)

I don't get it. Under what circumstances would the tcon ever be NULL here? If there aren't any then this is just confusing. It would be better to just remove the bogus checks for a NULL tcon instead.

Quoted 46 lines
---
 fs/cifs/smb2pdu.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
fs/cifs/smb2pdu.c +8 -5
index 1b906de..78b329f 100644
@@ -1218,7 +1218,7 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
 	struct smb2_ioctl_req *req;
 	struct smb2_ioctl_rsp *rsp;
 	struct TCP_Server_Info *server;
-	struct cifs_ses *ses = tcon->ses;
+	struct cifs_ses *ses;
 	struct kvec iov[2];
 	int resp_buftype;
 	int num_iovecs;
@@ -1233,6 +1233,11 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
 	if (plen)
 		*plen = 0;
 
+	if (tcon)
+		ses = tcon->ses;
+	else
+		return -EIO;
+
 	if (ses && (ses->server))
 		server = ses->server;
 	else
@@ -1296,14 +1301,12 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
 	rsp = (struct smb2_ioctl_rsp *)iov[0].iov_base;
 
 	if ((rc != 0) && (rc != -EINVAL)) {
-		if (tcon)
-			cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
+		cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
 		goto ioctl_exit;
 	} else if (rc == -EINVAL) {
 		if ((opcode != FSCTL_SRV_COPYCHUNK_WRITE) &&
 		    (opcode != FSCTL_SRV_COPYCHUNK)) {
-			if (tcon)
-				cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
+			cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
 			goto ioctl_exit;
 		}
 	}
Signature · 1 line
Jeff Layton <[email protected]>
#13 lore raw

Re: [PATCH 3/4] [SMB3] Fix dereference before null check warning

Quoted 8 lines · Jeff Layton
Quoted 5 lines · On Fri, 27 Mar 2015 00:28:01 -0500 Steve French <[email protected]> wrote:

null tcon is not likely in these paths in current
code, but obviously it does clarify the code to
check for null (if at all) before derefrencing
rather than after.

Quoted 7 lines
Quoted 3 lines

Reported by Coverity (CID 1042666)

I don't get it. Under what circumstances would the tcon ever be NULL here? If there aren't any then this is just confusing. It would be better to just remove the bogus checks for a NULL tcon instead.

I don't think it really matters much one way or another but I agree it would be a bug to pass in a null tcon to SMB2_ioctl.

On the other hand ... if there are any paths where tcon might be null (other than SessionSetup and NegProt and TCon itself) due to bug, SMB2/SMB3 ioctl/fsctl would be the one since there are various strange operations (such as security related calls such as validate negotiate for example) that either call it now or will need to call it as additional SMB2/SMB3 ioctls are added. I didn't see any harm in checking for null tcon, although clearly passing in a null tcon would be a bug - this is one code path where I don't mind checking since there are some counterintuitive things which SMB2 ioctl/fsctl protocol operations do.

Quoted 48 lines
Quoted 46 lines
---
 fs/cifs/smb2pdu.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
fs/cifs/smb2pdu.c +8 -5
index 1b906de..78b329f 100644
@@ -1218,7 +1218,7 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
      struct smb2_ioctl_req *req;
      struct smb2_ioctl_rsp *rsp;
      struct TCP_Server_Info *server;
-     struct cifs_ses *ses = tcon->ses;
+     struct cifs_ses *ses;
      struct kvec iov[2];
      int resp_buftype;
      int num_iovecs;
@@ -1233,6 +1233,11 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
      if (plen)
              *plen = 0;
 
+     if (tcon)
+             ses = tcon->ses;
+     else
+             return -EIO;
+
      if (ses && (ses->server))
              server = ses->server;
      else
@@ -1296,14 +1301,12 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
      rsp = (struct smb2_ioctl_rsp *)iov[0].iov_base;
 
      if ((rc != 0) && (rc != -EINVAL)) {
-             if (tcon)
-                     cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
+             cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
              goto ioctl_exit;
      } else if (rc == -EINVAL) {
              if ((opcode != FSCTL_SRV_COPYCHUNK_WRITE) &&
                  (opcode != FSCTL_SRV_COPYCHUNK)) {
-                     if (tcon)
-                             cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
+                     cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
                      goto ioctl_exit;
              }
      }
Signature · 3 lines
Thanks,

Steve
#14 lore raw

Re: [PATCH 3/4] [SMB3] Fix dereference before null check warning

Quoted 20 lines · On Wed, 1 Apr 2015 00:00:57 -0500 Steve French <[email protected]> wrote:
Quoted 8 lines · Jeff Layton
Quoted 5 lines · On Fri, 27 Mar 2015 00:28:01 -0500 Steve French <[email protected]> wrote:

null tcon is not likely in these paths in current
code, but obviously it does clarify the code to
check for null (if at all) before derefrencing
rather than after.

Quoted 7 lines
Quoted 3 lines

Reported by Coverity (CID 1042666)

I don't get it. Under what circumstances would the tcon ever be NULL here? If there aren't any then this is just confusing. It would be better to just remove the bogus checks for a NULL tcon instead.

I don't think it really matters much one way or another but I agree it would be a bug to pass in a null tcon to SMB2_ioctl.

Quoted 11 lines

On the other hand ... if there are any paths where tcon might be null (other than SessionSetup and NegProt and TCon itself) due to bug, SMB2/SMB3 ioctl/fsctl would be the one since there are various strange operations (such as security related calls such as validate negotiate for example) that either call it now or will need to call it as additional SMB2/SMB3 ioctls are added. I didn't see any harm in checking for null tcon, although clearly passing in a null tcon would be a bug - this is one code path where I don't mind checking since there are some counterintuitive things which SMB2 ioctl/fsctl protocol operations do.

I guess my thinking was that an ioctl syscall requires that you have an open file, and that requires a fully-established tcon with cifs.ko. So I don't quite understand how you could get into SMB2_ioctl and not have a valid tcon.

Bogus NULL pointer checks like this may seem harmless, but they tend to lead toward the papering over of real bugs. My suggestion would be to get rid of any pretense that passing in a NULL tcon is OK here.

Quoted 52 lines
Quoted 49 lines
Quoted 47 lines
---
 fs/cifs/smb2pdu.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
fs/cifs/smb2pdu.c +8 -5
index 1b906de..78b329f 100644
@@ -1218,7 +1218,7 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
      struct smb2_ioctl_req *req;
      struct smb2_ioctl_rsp *rsp;
      struct TCP_Server_Info *server;
-     struct cifs_ses *ses = tcon->ses;
+     struct cifs_ses *ses;
      struct kvec iov[2];
      int resp_buftype;
      int num_iovecs;
@@ -1233,6 +1233,11 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
      if (plen)
              *plen = 0;
 
+     if (tcon)
+             ses = tcon->ses;
+     else
+             return -EIO;
+
      if (ses && (ses->server))
              server = ses->server;
      else
@@ -1296,14 +1301,12 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
      rsp = (struct smb2_ioctl_rsp *)iov[0].iov_base;
 
      if ((rc != 0) && (rc != -EINVAL)) {
-             if (tcon)
-                     cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
+             cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
              goto ioctl_exit;
      } else if (rc == -EINVAL) {
              if ((opcode != FSCTL_SRV_COPYCHUNK_WRITE) &&
                  (opcode != FSCTL_SRV_COPYCHUNK)) {
-                     if (tcon)
-                             cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
+                     cifs_stats_fail_inc(tcon, SMB2_IOCTL_HE);
                      goto ioctl_exit;
              }
      }
Signature · 1 line
Jeff Layton <[email protected]>
#15 lore raw

PATCH 4/4 Fix coverity warning

In reply to Steve French

Coverity reports a warning for referencing the beginning of the SMB2/SMB3 frame using the ProtocolId field as an array. Although it works the same either way, this patch should quiet the warning and might be a little clearer.

Reported by Coverity (CID 741269)

---
 fs/cifs/smb2misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/smb2misc.c +1 -1
index 689f035..22dfdf1 100644
@@ -322,7 +322,7 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr)
 
 	/* return pointer to beginning of data area, ie offset from SMB start */
 	if ((*off != 0) && (*len != 0))
-		return hdr->ProtocolId + *off;
+		return (char *)(&hdr->ProtocolId[0]) + *off;
 	else
 		return NULL;
 }
Signature · 1 line
1.9.1
Acked-by on v1 4/4
#16 lore raw

Re: [PATCH 4/4] [SMB3] Fix coverity warning

Looks correct.

Quoted 32 lines · Steve French

Coverity reports a warning for referencing the beginning of the SMB2/SMB3 frame using the ProtocolId field as an array. Although it works the same either way, this patch should quiet the warning and might be a little clearer.

Reported by Coverity (CID 741269)

---
 fs/cifs/smb2misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/smb2misc.c +1 -2
index 689f035..22dfdf1 100644
@@ -322,7 +322,7 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr)
 
        /* return pointer to beginning of data area, ie offset from SMB start */
        if ((*off != 0) && (*len != 0))
-               return hdr->ProtocolId + *off;
+               return (char *)(&hdr->ProtocolId[0]) + *off;
        else
                return NULL;
 }
--

1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Acked-by on v1 4/4
#17 lore raw

Re: [PATCH 4/4] [SMB3] Fix coverity warning

In reply to Steve French
Quoted 8 lines · Steve French

Coverity reports a warning for referencing the beginning of the SMB2/SMB3 frame using the ProtocolId field as an array. Although it works the same either way, this patch should quiet the warning and might be a little clearer.

Reported by Coverity (CID 741269)

Quoted 17 lines
---
 fs/cifs/smb2misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/smb2misc.c +1 -1
index 689f035..22dfdf1 100644
@@ -322,7 +322,7 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr)
 
 	/* return pointer to beginning of data area, ie offset from SMB start */
 	if ((*off != 0) && (*len != 0))
-		return hdr->ProtocolId + *off;
+		return (char *)(&hdr->ProtocolId[0]) + *off;
 	else
 		return NULL;
 }
Acked-by on v1 4/4
#18 lore raw

Re: [PATCH 4/4] [SMB3] Fix coverity warning

In reply to Steve French
Quoted 17 lines · On Fri, 27 Mar 2015 00:28:02 -0500 Steve French…

Coverity reports a warning for referencing the beginning of the SMB2/SMB3 frame using the ProtocolId field as an array. Although it works the same either way, this patch should quiet the warning and might be a little clearer.

Reported by Coverity (CID 741269)

---
 fs/cifs/smb2misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cifs/smb2misc.c +0 -0
index 689f035..22dfdf1 100644

fs/cifs/smb2misc.c smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr) · line 328

Quoted 8 lines
fs/cifs/smb2misc.c +1 -1
@@ -322,7 +322,7 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *hdr)
 
 	/* return pointer to beginning of data area, ie offset from SMB start */
 	if ((*off != 0) && (*len != 0))
-		return hdr->ProtocolId + *off;
+		return (char *)(&hdr->ProtocolId[0]) + *off;
 	else
 		return NULL;
 }