Received: by 10.192.165.148 with SMTP id m20csp811982imm; Fri, 27 Apr 2018 07:55:42 -0700 (PDT) X-Google-Smtp-Source: AB8JxZocaAEGwOs7JVijKT2A/QfNdN6L7pp0t3sXa/7YZM8jmS46tK3mM3BjOgQ0adPRkDD84z5b X-Received: by 2002:a63:7502:: with SMTP id q2-v6mr2449625pgc.248.1524840942093; Fri, 27 Apr 2018 07:55:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524840942; cv=none; d=google.com; s=arc-20160816; b=UnocVMB+EP2Wm6n/bz8CP9Vu8dPh3DSU1EQwPTG960n7vRm8vAOgFWle6fFK/qF7nR w1k01E2EW49Ez1JLo8S9omNoFXx2+cIpVG8dBCRmsIRr0OsizHm9AUzK/O+S35qbA2s+ QdUSA8JT8G9wDPGmdRUN6bpuXqajbDaBpnWX3FpgqXfbviOxnAxBlTvxNqfZAYwBa1X9 OoGbv3dL9gA2rz8yG0MUI70qTeg5UKKYv80oJ41g7p6aRlqziQYLnrfxLJkJ03lNveR5 CXPHDWvbD6tdMHn6o6CIJYkOwt95X31lt6JxIk6OWQYNql/Rsn51TYv4CiqUbhjvNsux eDnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dmarc-filter :arc-authentication-results; bh=UmNL3NsVCLNksA/Z2Q60H+1HzSQZ+ZxsCjwWaUkCb98=; b=H+y+sdyrZyMZbF88ODTpECCxf/WzTLfUgNFSghzTWOTK/cXCXQdQBU02nzZo4X60cl zj8cOUmQxTorHUsjcC9dL/NambwGfOIrkZ1UQCPDgK/RydKcVq9T3X03d6OF0jfkgCEz BAB+7DAnFjnrY5yHjag2TXju/ABBUDu7gNm4S3c7FBmr/bseS2Dt4UhnVf8rwepBvEf0 3Spe9hwhJn7FxV599NItKjeoigUWX12zJAmQ9cwB8mjXv9c2RfFw+OUfjsnTCYqmmefr L4xw0ZmEgC8du/+o98AvmXdBNyX25ntiiqCj9Z/6LdKJtPDlGamJY7ruWvrqiMrVh8Cc +Ktg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1-v6si1392891plo.128.2018.04.27.07.55.27; Fri, 27 Apr 2018 07:55:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934350AbeD0Ow7 (ORCPT + 99 others); Fri, 27 Apr 2018 10:52:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:53002 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934199AbeD0OHF (ORCPT ); Fri, 27 Apr 2018 10:07:05 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C6C8C218BC; Fri, 27 Apr 2018 14:07:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C6C8C218BC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Doron Roberts-Kedes , "David S. Miller" Subject: [PATCH 4.14 31/80] strparser: Fix incorrect strp->need_bytes value. Date: Fri, 27 Apr 2018 15:58:24 +0200 Message-Id: <20180427135734.560740670@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427135732.928644313@linuxfoundation.org> References: <20180427135732.928644313@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Doron Roberts-Kedes [ Upstream commit 9d0c75bf6e03d9bf80c55b0f677dc9b982958fd5 ] strp_data_ready resets strp->need_bytes to 0 if strp_peek_len indicates that the remainder of the message has been received. However, do_strp_work does not reset strp->need_bytes to 0. If do_strp_work completes a partial message, the value of strp->need_bytes will continue to reflect the needed bytes of the previous message, causing future invocations of strp_data_ready to return early if strp->need_bytes is less than strp_peek_len. Resetting strp->need_bytes to 0 in __strp_recv on handing a full message to the upper layer solves this problem. __strp_recv also calculates strp->need_bytes using stm->accum_len before stm->accum_len has been incremented by cand_len. This can cause strp->need_bytes to be equal to the full length of the message instead of the full length minus the accumulated length. This, in turn, causes strp_data_ready to return early, even when there is sufficient data to complete the partial message. Incrementing stm->accum_len before using it to calculate strp->need_bytes solves this problem. Found while testing net/tls_sw recv path. Fixes: 43a0c6751a322847 ("strparser: Stream parser for messages") Signed-off-by: Doron Roberts-Kedes Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/strparser/strparser.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/net/strparser/strparser.c +++ b/net/strparser/strparser.c @@ -296,9 +296,9 @@ static int __strp_recv(read_descriptor_t strp_start_timer(strp, timeo); } + stm->accum_len += cand_len; strp->need_bytes = stm->strp.full_len - stm->accum_len; - stm->accum_len += cand_len; stm->early_eaten = cand_len; STRP_STATS_ADD(strp->stats.bytes, cand_len); desc->count = 0; /* Stop reading socket */ @@ -321,6 +321,7 @@ static int __strp_recv(read_descriptor_t /* Hurray, we have a new message! */ cancel_delayed_work(&strp->msg_timer_work); strp->skb_head = NULL; + strp->need_bytes = 0; STRP_STATS_INCR(strp->stats.msgs); /* Give skb to upper layer */ @@ -410,9 +411,7 @@ void strp_data_ready(struct strparser *s return; if (strp->need_bytes) { - if (strp_peek_len(strp) >= strp->need_bytes) - strp->need_bytes = 0; - else + if (strp_peek_len(strp) < strp->need_bytes) return; }