Skip to content

Commit

Permalink
cifs: allow dumping keys for directories too
Browse files Browse the repository at this point in the history
BugLink: https://bugs.launchpad.net/bugs/2036450

Dumping the enc/dec keys is a session wide operation.
And it should not matter if the ioctl was run on
a regular file or a directory.

Currently, we obtain the tcon pointer from the
cifs file handle. But since there's no dir open call
in cifs, this is not populated for dirs.

This change allows dumping of session keys using ioctl
even for directories. To do this, we'll now get the
tcon pointer from the superblock, and not from the file
handle.

Signed-off-by: Shyam Prasad N <sprasad@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
(cherry picked from commit b3edef6b9cd0b8893a5649ab1fa8bce71045d139)
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
  • Loading branch information
Steve French authored and smb49 committed Apr 17, 2024
1 parent 990caff commit bc2c54c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions fs/cifs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,16 +433,21 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
* Dump encryption keys. This is an old ioctl that only
* handles AES-128-{CCM,GCM}.
*/
if (pSMBFile == NULL)
break;
if (!capable(CAP_SYS_ADMIN)) {
rc = -EACCES;
break;
}

tcon = tlink_tcon(pSMBFile->tlink);
cifs_sb = CIFS_SB(inode->i_sb);
tlink = cifs_sb_tlink(cifs_sb);
if (IS_ERR(tlink)) {
rc = PTR_ERR(tlink);
break;
}
tcon = tlink_tcon(tlink);
if (!smb3_encryption_required(tcon)) {
rc = -EOPNOTSUPP;
cifs_put_tlink(tlink);
break;
}
pkey_inf.cipher_type =
Expand All @@ -459,6 +464,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
rc = -EFAULT;
else
rc = 0;
cifs_put_tlink(tlink);
break;
case CIFS_DUMP_FULL_KEY:
/*
Expand All @@ -470,8 +476,11 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
rc = -EACCES;
break;
}
tcon = tlink_tcon(pSMBFile->tlink);
cifs_sb = CIFS_SB(inode->i_sb);
tlink = cifs_sb_tlink(cifs_sb);
tcon = tlink_tcon(tlink);
rc = cifs_dump_full_key(tcon, (void __user *)arg);
cifs_put_tlink(tlink);
break;
case CIFS_IOC_NOTIFY:
if (!S_ISDIR(inode->i_mode)) {
Expand Down

0 comments on commit bc2c54c

Please sign in to comment.