Skip to contentSkip to conversation

cifs: avoid possible NULL dereference

PATCH Superseded Su Hui 2 participants 3 messages Sep 25, 2023 – Sep 26, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Su Hui

author
#0 lore raw

PATCH 1/1 cifs: avoid possible NULL dereference

smatch warn:
fs/smb/client/file.c:4910 cifs_oplock_break() warn:
variable dereferenced before check 'inode' (see line 4881)

If 'inode' is NULL, print some warning and return.

---
 fs/smb/client/file.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/smb/client/file.c +7 -1
index 2108b3b40ce9..37eed057ded0 100644
@@ -4878,6 +4878,12 @@ void cifs_oplock_break(struct work_struct *work)
 	struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo,
 						  oplock_break);
 	struct inode *inode = d_inode(cfile->dentry);
+
+	if (!inode) {
+		cifs_dbg(FYI, "%s : failed to find inode\n", __func__);
+		return;
+	}
+
 	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
 	struct cifsInodeInfo *cinode = CIFS_I(inode);
 	struct cifs_tcon *tcon;
@@ -4907,7 +4913,7 @@ void cifs_oplock_break(struct work_struct *work)
 		cinode->oplock = 0;
 	}
 
-	if (inode && S_ISREG(inode->i_mode)) {
+	if (S_ISREG(inode->i_mode)) {
 		if (CIFS_CACHE_READ(cinode))
 			break_lease(inode, O_RDONLY);
 		else
Signature · 1 line
2.30.2
#1 lore raw
Quoted 5 lines · Su Hui
fs/smb/client/file.c +0 -0
index 2108b3b40ce9..37eed057ded0 100644

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4886

Quoted 9 lines
fs/smb/client/file.c +6 -0
@@ -4878,6 +4878,12 @@ void cifs_oplock_break(struct work_struct *work)
 	struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo,
 						  oplock_break);
 	struct inode *inode = d_inode(cfile->dentry);
+
+	if (!inode) {
+		cifs_dbg(FYI, "%s : failed to find inode\n", __func__);
+		return;
+	}
+

Are we allowing this in the middle of the declaration block these days?

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4889

Quoted 3 lines
fs/smb/client/file.c +0 -0
 	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
 	struct cifsInodeInfo *cinode = CIFS_I(inode);
 	struct cifs_tcon *tcon;

regards,
dan carpenter

author
#2 lore raw
Quoted 16 lines · Dan Carpenter
Quoted 5 lines · Su Hui
fs/smb/client/file.c +0 -0
index 2108b3b40ce9..37eed057ded0 100644

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4886

Quoted 9 lines
fs/smb/client/file.c +6 -0
@@ -4878,6 +4878,12 @@ void cifs_oplock_break(struct work_struct *work)
  	struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo,
  						  oplock_break);
  	struct inode *inode = d_inode(cfile->dentry);
+
+	if (!inode) {
+		cifs_dbg(FYI, "%s : failed to find inode\n", __func__);
+		return;
+	}
+

Are we allowing this in the middle of the declaration block these days?

Really sorry for this, I will modify it right now. Thanks for your reminder!

Su Hui

Quoted 7 lines

fs/smb/client/file.c void cifs_oplock_break(struct work_struct *work) · line 4889

Quoted 4 lines
fs/smb/client/file.c +0 -0
  	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
  	struct cifsInodeInfo *cinode = CIFS_I(inode);
  	struct cifs_tcon *tcon;

regards,
dan carpenter