From patchwork Mon Oct 14 05:52:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 3034491 Return-Path: X-Original-To: patchwork-cifs-client@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E0108BF924 for ; Mon, 14 Oct 2013 05:52:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2773420255 for ; Mon, 14 Oct 2013 05:52:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D9C6B20254 for ; Mon, 14 Oct 2013 05:52:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750731Ab3JNFwP (ORCPT ); Mon, 14 Oct 2013 01:52:15 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:61410 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750796Ab3JNFwO (ORCPT ); Mon, 14 Oct 2013 01:52:14 -0400 Received: by mail-pa0-f47.google.com with SMTP id kp14so7031010pab.6 for ; Sun, 13 Oct 2013 22:52:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=bsHWvmrAP9N2WeMoy+IHWBIgSn8fSxrRzNkd3i9wAv4=; b=dmSV66jJDLNasuEGHzRbFHemIZmu/fwjt71AxKWTTvP5jBRCqs2oVJGOXyCDN5xtho KooEOm0xDvStU7bOPqj8cDKV7m3vuMUDbh4CzFPR7JeNtbhfDUQh5VV2OAsS1TZlb4uV X2ErcL5+ipZjSrGQuIhYOvuvz/g0pqwdgWE4A4j0cHHq6QyH+KHtJ5YZvsYdr6kgCwmX PAcAifMPl66fPGWH4OUoM8BkDWdzK0m/iDxfcB5g33XhEEF0rPUxSi0aby5S6SaFRV3e CmaICHIhd3wPmNB2muf42J1H3i7OJUnFbV1dqby0PzvGhoKrMMoQN2ReoAyz3b9dcCWe 4ePQ== MIME-Version: 1.0 X-Received: by 10.69.4.100 with SMTP id cd4mr33684888pbd.120.1381729934493; Sun, 13 Oct 2013 22:52:14 -0700 (PDT) Received: by 10.68.143.10 with HTTP; Sun, 13 Oct 2013 22:52:14 -0700 (PDT) Date: Mon, 14 Oct 2013 00:52:14 -0500 Message-ID: Subject: [PATCH] [CIFS] Fix corrupt SMB2 ioctl requests From: Steve French To: "linux-cifs@vger.kernel.org" Cc: "Stefan (metze) Metzmacher" Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Now that I have been able to test a wider variety of SMB2/SMB3 ioctls, some with input payloads and some without, I have this updated version of the patch (which hopefully is cleaner ) We were off by one calculating the length of ioctls in some cases because the protocol specification for SMB2 ioctl includes a mininum one byte payload but not all SMB2 ioctl requests actually have a data buffer to send. We were also not zeroing out the return buffer (in case of error this is helpful). Signed-off-by: Steve French --- fs/cifs/smb2pdu.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) *plen = 0; @@ -1182,11 +1183,23 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, req->Flags = 0; iov[0].iov_base = (char *)req; - /* 4 for rfc1002 length field */ - iov[0].iov_len = get_rfc1002_length(req) + 4; - if (indatalen) - inc_rfc1001_len(req, indatalen); + /* + * If no input data, the size of ioctl struct in + * protocol spec still includes a 1 byte data buffer, + * but if input data passed to ioctl, we do not + * want to double count this, so we do not send + * the dummy one byte of data in iovec[0] if sending + * input data (in iovec[1]). We also must add 4 bytes + * in first iovec to allow for rfc1002 length field. + */ + + if (indatalen) { + inc_rfc1001_len(req, indatalen - 1); + iov[0].iov_len = get_rfc1002_length(req) + 4 - 1; + } else + iov[0].iov_len = get_rfc1002_length(req) + 4; + rc = SendReceive2(xid, ses, iov, num_iovecs, &resp_buftype, 0); rsp = (struct smb2_ioctl_rsp *)iov[0].iov_base; diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index edccb52..afa3829 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -1137,6 +1137,7 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid, cifs_dbg(FYI, "SMB2 IOCTL\n"); + *out_data = NULL; /* zero out returned data len, in case of error */ if (plen)