From patchwork Fri Mar 15 00:21:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 10853921 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3C1561669 for ; Fri, 15 Mar 2019 00:21:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CDFE2A7E7 for ; Fri, 15 Mar 2019 00:21:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E6492A7EA; Fri, 15 Mar 2019 00:21:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82A812A7E7 for ; Fri, 15 Mar 2019 00:21:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727603AbfCOAVn (ORCPT ); Thu, 14 Mar 2019 20:21:43 -0400 Received: from mail-pg1-f176.google.com ([209.85.215.176]:35637 "EHLO mail-pg1-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727332AbfCOAVn (ORCPT ); Thu, 14 Mar 2019 20:21:43 -0400 Received: by mail-pg1-f176.google.com with SMTP id e17so5130284pgd.2 for ; Thu, 14 Mar 2019 17:21:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=CPnlFNf1PIk3YiY8CRjoJoVELXWMUs/B2X/31THIKDk=; b=aVdufyIuIPuYarSsrEHCiXacuw5YjEdG2TRH/1CV8xxfHU/y1ITVlUso/i1EM+WWEq Oh3B4lXzsaEytO1mvGhdGFWSSQFx/qCZoXDuXhxPfl0Yomh7lUpYajDWReeiK20R4aEo Tx555Q44pYDYSdl+u6CXiZbnW/VM63M4uUYnWPQrwgId6sHx6m7Z8WQnoOc80BmYBVtD DN9j+NHFiF2Bh2UNSsDbzXy2qJ7/i18sQGEsrRBH2iECG68IMmSPl6KNZAuleuIXPqUq Sl3PYXFr5NVBMkDqVNmCj1gKjwMuODChb6KxbV68QsTpJw+btq+PFm6/dKkOW3elDwK8 Z2Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=CPnlFNf1PIk3YiY8CRjoJoVELXWMUs/B2X/31THIKDk=; b=MYIz1gEemHBXyOb+7bYomREp36C1qqMB9Z4wSnLTWrf3eufG9ncxp/uGfJITHmcHq+ hqdXsnnQne80vRLPjD9st8pyY7DfTZRQmS+Vrap5kTMlTOK3StOq9Vw3x1XLR1r2Q851 +Zpi30XWMZmVFHcwvLBmxBF1kN0/D2CT3MJAKqN3GSYAohIaFhf293JEv3zdRpUmYSvo W8HGE5W5IYd+VFtQKOi/VeQ9Fbm0t8CJmxwQIBx6Po/4Jc4xr70sx6NhpDnJ/cmwtAWn 0XUm+XTHMdbwAwhRLAodT6ExVm1A1hVizoUUFxNy0PgJ8s0cztUDT/XLnK/4FqAWPEam 6G4g== X-Gm-Message-State: APjAAAVMnnG3cs5/gzBu4LRAaHsg21zdz2XubHpqsvZw0u7oK8drUL4X D4VKs8qUZSMAS5Ld98NrKSUCC1SE3YbCBab9bj0KxsQd X-Google-Smtp-Source: APXvYqwoSKYJkawdjQ4V/oICO3LqmN0aSvFwfg3PhNUKiaFyYmZal82G0CzofJF80F4x7Mu4JD6qw/kmGSJcPDH1T14= X-Received: by 2002:a17:902:147:: with SMTP id 65mr1162683plb.18.1552609301382; Thu, 14 Mar 2019 17:21:41 -0700 (PDT) MIME-Version: 1.0 From: Steve French Date: Thu, 14 Mar 2019 19:21:29 -0500 Message-ID: Subject: [SMB3] [PATCH] Pass through FSCTL for tools like smbinfo To: CIFS , samba-technical , ronnie sahlberg Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Forwarding Ronnie's patch to the broader list For debugging purposes we often have to be able to query additional information only available via SMB3 FSCTL from the server from user space tools (e.g. like cifs-utils's smbinfo). See MS-FSCC and MS-SMB2 protocol specifications for more details. From 75ecfe3c91d5b31e627ded936c5331b83436ea72 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 15 Mar 2019 09:07:22 +1000 Subject: [PATCH] SMB3: Allow SMB3 FSCTL queries to be sent to server from tools For debugging purposes we often have to be able to query additional information only available via SMB3 FSCTL from the server from user space tools (e.g. like cifs-utils's smbinfo). See MS-FSCC and MS-SMB2 protocol specifications for more details. Signed-off-by: Ronnie Sahlberg Signed-off-by: Steve French --- fs/cifs/smb2ops.c | 62 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 1c8d3684bb8b..8102409d10e4 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1330,7 +1330,8 @@ smb2_ioctl_query_info(const unsigned int xid, struct smb_query_info __user *pqi; int rc = 0; int flags = 0; - struct smb2_query_info_rsp *rsp = NULL; + struct smb2_query_info_rsp *qi_rsp = NULL; + struct smb2_ioctl_rsp *io_rsp = NULL; void *buffer = NULL; struct smb_rqst rqst[3]; int resp_buftype[3]; @@ -1340,6 +1341,7 @@ smb2_ioctl_query_info(const unsigned int xid, u8 oplock = SMB2_OPLOCK_LEVEL_NONE; struct cifs_fid fid; struct kvec qi_iov[1]; + struct kvec io_iov[SMB2_IOCTL_IOV_SIZE]; struct kvec close_iov[1]; memset(rqst, 0, sizeof(rqst)); @@ -1394,8 +1396,16 @@ smb2_ioctl_query_info(const unsigned int xid, /* Can eventually relax perm check since server enforces too */ if (!capable(CAP_SYS_ADMIN)) rc = -EPERM; - else /* TBD: Add code to compound FSCTL */ - rc = -EOPNOTSUPP; + else { + memset(&io_iov, 0, sizeof(io_iov)); + rqst[1].rq_iov = io_iov; + rqst[1].rq_nvec = SMB2_IOCTL_IOV_SIZE; + + rc = SMB2_ioctl_init(tcon, &rqst[1], + COMPOUND_FID, COMPOUND_FID, + qi.info_type, true, NULL, + 0); + } } else if (qi.flags == PASSTHRU_QUERY_INFO) { memset(&qi_iov, 0, sizeof(qi_iov)); rqst[1].rq_iov = qi_iov; @@ -1430,24 +1440,44 @@ smb2_ioctl_query_info(const unsigned int xid, resp_buftype, rsp_iov); if (rc) goto iqinf_exit; - pqi = (struct smb_query_info __user *)arg; - rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base; - if (le32_to_cpu(rsp->OutputBufferLength) < qi.input_buffer_length) - qi.input_buffer_length = le32_to_cpu(rsp->OutputBufferLength); - if (copy_to_user(&pqi->input_buffer_length, &qi.input_buffer_length, - sizeof(qi.input_buffer_length))) { - rc = -EFAULT; - goto iqinf_exit; - } - if (copy_to_user(pqi + 1, rsp->Buffer, qi.input_buffer_length)) { - rc = -EFAULT; - goto iqinf_exit; + if (qi.flags & PASSTHRU_FSCTL) { + pqi = (struct smb_query_info __user *)arg; + io_rsp = (struct smb2_ioctl_rsp *)rsp_iov[1].iov_base; + if (le32_to_cpu(io_rsp->OutputCount) < qi.input_buffer_length) + qi.input_buffer_length = le32_to_cpu(io_rsp->OutputCount); + if (copy_to_user(&pqi->input_buffer_length, &qi.input_buffer_length, + sizeof(qi.input_buffer_length))) { + rc = -EFAULT; + goto iqinf_exit; + } + if (copy_to_user(pqi + 1, &io_rsp[1], qi.input_buffer_length)) { + rc = -EFAULT; + goto iqinf_exit; + } + } else { + pqi = (struct smb_query_info __user *)arg; + qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1].iov_base; + if (le32_to_cpu(qi_rsp->OutputBufferLength) < qi.input_buffer_length) + qi.input_buffer_length = le32_to_cpu(qi_rsp->OutputBufferLength); + if (copy_to_user(&pqi->input_buffer_length, &qi.input_buffer_length, + sizeof(qi.input_buffer_length))) { + rc = -EFAULT; + goto iqinf_exit; + } + if (copy_to_user(pqi + 1, qi_rsp->Buffer, qi.input_buffer_length)) { + rc = -EFAULT; + goto iqinf_exit; + } } iqinf_exit: kfree(buffer); SMB2_open_free(&rqst[0]); - SMB2_query_info_free(&rqst[1]); + if (qi.flags & PASSTHRU_FSCTL) + SMB2_ioctl_free(&rqst[1]); + else + SMB2_query_info_free(&rqst[1]); + SMB2_close_free(&rqst[2]); free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); -- 2.17.1