cifs: do not allow creating sockets except with SMB1 posix exensions

RHBZ: 1453123

Since at least the 3.10 kernel and likely a lot earlier we have
not been able to create unix domain sockets in a cifs share
when mounted using the SFU mount option (except when mounted
with the cifs unix extensions to Samba e.g.)
Trying to create a socket, for example using the af_unix command from
xfstests will cause :
BUG: unable to handle kernel NULL pointer dereference at 00000000
00000040

Since no one uses or depends on being able to create unix domains sockets
on a cifs share the easiest fix to stop this vulnerability is to simply
not allow creation of any other special files than char or block devices
when sfu is used.

Added update to Ronnie's patch to handle a tcon link leak, and
to address a buf leak noticed by Gustavo and Colin.

Acked-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
CC: Colin Ian King <colin.king@canonical.com>
Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>
Reported-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <smfrench@gmail.com>
Cc: stable@vger.kernel.org

Changed files
+5 -4
fs
cifs
+5 -4
fs/cifs/dir.c
··· 684 684 goto mknod_out; 685 685 } 686 686 687 + if (!S_ISCHR(mode) && !S_ISBLK(mode)) 688 + goto mknod_out; 689 + 687 690 if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)) 688 691 goto mknod_out; 689 692 ··· 695 692 696 693 buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL); 697 694 if (buf == NULL) { 698 - kfree(full_path); 699 695 rc = -ENOMEM; 700 - free_xid(xid); 701 - return rc; 696 + goto mknod_out; 702 697 } 703 698 704 699 if (backup_cred(cifs_sb)) ··· 743 742 pdev->minor = cpu_to_le64(MINOR(device_number)); 744 743 rc = tcon->ses->server->ops->sync_write(xid, &fid, &io_parms, 745 744 &bytes_written, iov, 1); 746 - } /* else if (S_ISFIFO) */ 745 + } 747 746 tcon->ses->server->ops->close(xid, tcon, &fid); 748 747 d_drop(direntry); 749 748