From patchwork Wed Oct 11 23:38:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ronnie Sahlberg X-Patchwork-Id: 824610 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yC9RG645cz9sPr for ; Thu, 12 Oct 2017 10:38:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751433AbdJKXit (ORCPT ); Wed, 11 Oct 2017 19:38:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48788 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751285AbdJKXit (ORCPT ); Wed, 11 Oct 2017 19:38:49 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 174B64ACCA; Wed, 11 Oct 2017 23:38:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 174B64ACCA Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lsahlber@redhat.com Received: from test1190.test.redhat.com (vpn2-54-18.bne.redhat.com [10.64.54.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6AA7617C5A; Wed, 11 Oct 2017 23:38:48 +0000 (UTC) From: Ronnie Sahlberg To: linux-cifs Cc: Steve French Subject: [PATCH] cifs: initialize rsp_iov and check for NULL in SMB2_read Date: Thu, 12 Oct 2017 10:38:40 +1100 Message-Id: <20171011233840.10365-1-lsahlber@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 11 Oct 2017 23:38:49 +0000 (UTC) Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Signed-off-by: Ronnie Sahlberg --- fs/cifs/smb2pdu.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 6ff4c275ca9a..e6b62771a48e 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -2639,10 +2639,10 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms, { int resp_buftype, rc = -EACCES; struct smb2_read_plain_req *req = NULL; - struct smb2_read_rsp *rsp = NULL; + struct smb2_read_rsp *rsp; struct smb2_sync_hdr *shdr; struct kvec iov[2]; - struct kvec rsp_iov; + struct kvec rsp_iov = {NULL, 0}; unsigned int total_len; __be32 req_len; struct smb_rqst rqst = { .rq_iov = iov, @@ -2669,11 +2669,9 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms, cifs_small_buf_release(req); rsp = (struct smb2_read_rsp *)rsp_iov.iov_base; - shdr = get_sync_hdr(rsp); - - if (shdr->Status == STATUS_END_OF_FILE) { - free_rsp_buf(resp_buftype, rsp_iov.iov_base); - return 0; + if (rsp == NULL) { + cifs_dbg(VFS, "rsp is NULL in read\n"); + return -EIO; } if (rc) { @@ -2690,6 +2688,13 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms, } } + shdr = get_sync_hdr(rsp); + + if (shdr->Status == STATUS_END_OF_FILE) { + free_rsp_buf(resp_buftype, rsp_iov.iov_base); + return 0; + } + if (*buf) { memcpy(*buf, (char *)shdr + rsp->DataOffset, *nbytes); free_rsp_buf(resp_buftype, rsp_iov.iov_base);