Skip to contentSkip to conversation

NFS: fix potential NULL deref in nfs_closedir()

PATCH In review Taesoo Kim 3 participants 3 messages Mar 21, 2015

Subsystems (2)
lore
Share & tools
lore

Taesoo Kim

author
#0 lore raw

PATCH 1/1 NFS: fix potential NULL deref in nfs_closedir()

From: Byoungyoung Lee <[email protected]>

When filp->private_data is NULL, put_nfs_open_dir_context() deferences its pointer (fi->list, fi->cred), similar to what other file systems handle '.release' api (9p, cifs, btrfs, ext4, ocfs2).

---
 fs/nfs/dir.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/nfs/dir.c +2 -1
index c19e16f..434ecf1 100644
@@ -133,7 +133,8 @@ out:
 static int
 nfs_closedir(struct inode *inode, struct file *filp)
 {
-	put_nfs_open_dir_context(file_inode(filp), filp->private_data);
+	if (filp->private_data)
+		put_nfs_open_dir_context(file_inode(filp), filp->private_data);
 	return 0;
 }
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 6 lines · Taesoo Kim

From: Byoungyoung Lee <[email protected]>

When filp->private_data is NULL, put_nfs_open_dir_context() deferences its pointer (fi->list, fi->cred), similar to what other file systems handle '.release' api (9p, cifs, btrfs, ext4, ocfs2).

Why woud filp->private_data ever be NULL here?

#2 lore raw

Ops. After reading nfs code, we also find out that nfs_opendir() always allocates ctx obj (for private_data), unlike other fs allocate private_data right before seeking dentries.

Sorry for the false alarm.

Taesoo

Quoted 9 lines · Christoph Hellwig
Quoted 6 lines · Taesoo Kim

From: Byoungyoung Lee <[email protected]>

When filp->private_data is NULL, put_nfs_open_dir_context() deferences its pointer (fi->list, fi->cred), similar to what other file systems handle '.release' api (9p, cifs, btrfs, ext4, ocfs2).

Why woud filp->private_data ever be NULL here?