cifs: make cifs_ioctl handle NULL filp->private_data correctly
Subsystems (2)
PATCH 1/1 cifs: make cifs_ioctl handle NULL filp->private_data correctly
Commit 13cfb7334e made cifs_ioctl use the tlink attached to the cifsFileInfo for a filp. This ignores the case of an open directory however, which in CIFS can have a NULL private_data until a readdir is done on it.
This patch re-adds the NULL pointer checks that were removed in commit 50ae28f01 and moves the setting of tcon and "caps" variables lower.
Long term, a better fix would be to establish a f_op->open routine for directories that populates that field at open time, but that requires some other changes to how readdir calls are handled.
--- fs/cifs/ioctl.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
fs/cifs/ioctl.c +10 -2
@@ -38,10 +38,10 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)struct cifs_sb_info *cifs_sb;#ifdef CONFIG_CIFS_POSIX struct cifsFileInfo *pSMBFile = filep->private_data; -struct cifsTconInfo *tcon =tlink_tcon (pSMBFile->tlink); +struct cifsTconInfo *tcon;__u64 ExtAttrBits =0 ;__u64 ExtAttrMask =0 ; -__u64 caps =le64_to_cpu (tcon->fsUnixInfo.Capability); +__u64 caps;#endif /* CONFIG_CIFS_POSIX */ xid =GetXid ();
@@ -62,6 +62,10 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)break ;#ifdef CONFIG_CIFS_POSIX case FS_IOC_GETFLAGS : +if (pSMBFile ==NULL ) +break ; + tcon =tlink_tcon (pSMBFile->tlink); + caps =le64_to_cpu (tcon->fsUnixInfo.Capability);if (CIFS_UNIX_EXTATTR_CAP & caps) { rc =CIFSGetExtAttr (xid, tcon, pSMBFile->netfid, &ExtAttrBits, &ExtAttrMask);
@@ -73,6 +77,10 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)break ;case FS_IOC_SETFLAGS : +if (pSMBFile ==NULL ) +break ; + tcon =tlink_tcon (pSMBFile->tlink); + caps =le64_to_cpu (tcon->fsUnixInfo.Capability);if (CIFS_UNIX_EXTATTR_CAP & caps) {if (get_user (ExtAttrBits, (int __user *)arg)) { rc = -EFAULT ;
Signature · 1 line
1.7.2.3
A message that is not in the archive (sent off-list or not yet received): 1289219312-21396-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Quoted 12 lines · Jeff Layton
Commit
13cfb7334emadecifs_ioctluse the tlink attached to the cifsFileInfo for a filp. This ignores the case of an open directory however, which in CIFS can have a NULLprivate_datauntil a readdir is done on it.This patch re-adds the NULL pointer checks that were removed in commit
50ae28f01and moves the setting of tcon and "caps" variables lower.Long term, a better fix would be to establish a
f_op->openroutine for directories that populates that field at open time, but that requires some other changes to how readdir calls are handled.
Quoted 6 lines
Reported-by Kjell Rune Skaaraas <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/cifs/ioctl.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
Looks correct to me and fixes the bug caused by my reproducer. (BTW, the file should be open with O_RDONLY in the reproducer to trigger the Oops)
Makes sense - will do some tests today and merge
Quoted 61 lines · Jeff Layton
Commit
13cfb7334emadecifs_ioctluse the tlink attached to the cifsFileInfo for a filp. This ignores the case of an open directory however, which in CIFS can have a NULLprivate_datauntil a readdir is done on it.This patch re-adds the NULL pointer checks that were removed in commit
50ae28f01and moves the setting of tcon and "caps" variables lower.Long term, a better fix would be to establish a
f_op->openroutine for directories that populates that field at open time, but that requires some other changes to how readdir calls are handled.Reported-by Kjell Rune Skaaraas <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
fs/cifs/ioctl.c | 12 ++++++++++--1 files changed, 10 insertions(+), 2 deletions(-)fs/cifs/ioctl.c +2
-2@@ -38,10 +38,10 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) struct cifs_sb_info *cifs_sb; #ifdef CONFIG_CIFS_POSIX struct cifsFileInfo *pSMBFile = filep->private_data; - struct cifsTconInfo *tcon = tlink_tcon(pSMBFile->tlink); + struct cifsTconInfo *tcon; __u64 ExtAttrBits = 0; __u64 ExtAttrMask = 0; - __u64 caps = le64_to_cpu(tcon->fsUnixInfo.Capability); + __u64 caps; #endif /* CONFIG_CIFS_POSIX */ xid = GetXid();@@ -62,6 +62,10 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) break; #ifdef CONFIG_CIFS_POSIXcase
FS_IOC_GETFLAGS:
+ if (pSMBFile == NULL)
+ break;
+ tcon =tlink_tcon(pSMBFile->tlink);
+ caps =le64_to_cpu(tcon->fsUnixInfo.Capability); if (CIFS_UNIX_EXTATTR_CAP& caps) {
rc =CIFSGetExtAttr(xid, tcon, pSMBFile->netfid, &ExtAttrBits, &ExtAttrMask);fs/cifs/ioctl.c +0
-0@@ -73,6 +77,10 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg) break;case
FS_IOC_SETFLAGS:
+ if (pSMBFile == NULL)
+ break;
+ tcon =tlink_tcon(pSMBFile->tlink);
+ caps =le64_to_cpu(tcon->fsUnixInfo.Capability); if (CIFS_UNIX_EXTATTR_CAP& caps) {
if (get_user(ExtAttrBits, (int __user *)arg)) { rc =-EFAULT;
--
1.7.2.3
Signature · 3 lines
Thanks, Steve