From patchwork Sat Aug 20 01:55:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 1082122 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7K1tjDa012305 for ; Sat, 20 Aug 2011 01:55:50 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754216Ab1HTBzu (ORCPT ); Fri, 19 Aug 2011 21:55:50 -0400 Received: from mail-gw0-f46.google.com ([74.125.83.46]:33213 "EHLO mail-gw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753439Ab1HTBzt (ORCPT ); Fri, 19 Aug 2011 21:55:49 -0400 Received: by mail-gw0-f46.google.com with SMTP id a12so2026366gwa.19 for ; Fri, 19 Aug 2011 18:55:49 -0700 (PDT) Received: by 10.91.211.3 with SMTP id n3mr32720agq.67.1313805349639; Fri, 19 Aug 2011 18:55:49 -0700 (PDT) Received: from salusa.poochiereds.net (cpe-075-177-182-191.nc.res.rr.com [75.177.182.191]) by mx.google.com with ESMTPS id b5sm3122509anm.21.2011.08.19.18.55.48 (version=SSLv3 cipher=OTHER); Fri, 19 Aug 2011 18:55:49 -0700 (PDT) From: Jeff Layton To: smfrench@gmail.com Cc: piastryyy@gmail.com, linux-cifs@vger.kernel.org Subject: [PATCH 07/14] cifs: add a third receive phase to cifs_demultiplex_thread Date: Fri, 19 Aug 2011 21:55:32 -0400 Message-Id: <1313805339-1233-8-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1313805339-1233-1-git-send-email-jlayton@redhat.com> References: <1313805339-1233-1-git-send-email-jlayton@redhat.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sat, 20 Aug 2011 01:55:50 +0000 (UTC) Have the demultiplex thread receive just enough to get to the MID, and then find it before receiving the rest. Later, we'll use this to swap in a preallocated receive buffer for some calls. Signed-off-by: Jeff Layton --- fs/cifs/connect.c | 31 ++++++++++++++++++++++++------- 1 files changed, 24 insertions(+), 7 deletions(-) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index ecd8ae7..5adbeec 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -732,11 +732,25 @@ cifs_demultiplex_thread(void *p) if (!is_smb_response(server, buf[0])) continue; - /* check the length */ - if ((pdu_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) || - (pdu_length < sizeof(struct smb_hdr) - 1 - 4)) { - cERROR(1, "Invalid size SMB length %d pdu_length %d", - 4, pdu_length + 4); + /* make sure we have enough to get to the MID */ + if (pdu_length < sizeof(struct smb_hdr) - 1 - 4) { + cERROR(1, "SMB response too short (%u bytes)", + pdu_length); + cifs_reconnect(server); + wake_up(&server->response_q); + continue; + } + + /* read down to the MID */ + length = read_from_socket(server, buf + 4, + sizeof(struct smb_hdr) - 1 - 4); + if (length < 0) + continue; + total_read += length; + + if (pdu_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) { + cERROR(1, "SMB response too long (%u bytes)", + pdu_length); cifs_reconnect(server); wake_up(&server->response_q); continue; @@ -745,12 +759,15 @@ cifs_demultiplex_thread(void *p) /* else length ok */ if (pdu_length > MAX_CIFS_SMALL_BUFFER_SIZE - 4) { isLargeBuf = true; - memcpy(bigbuf, smallbuf, 4); + memcpy(bigbuf, smallbuf, total_read); smb_buffer = (struct smb_hdr *)bigbuf; buf = bigbuf; } - length = read_from_socket(server, buf + 4, pdu_length); + /* now read the rest */ + length = read_from_socket(server, + buf + sizeof(struct smb_hdr) - 1, + pdu_length - sizeof(struct smb_hdr) + 1 + 4); if (length < 0) continue; total_read += length;