Received: by 10.192.165.148 with SMTP id m20csp821076imm; Fri, 27 Apr 2018 08:03:18 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrqg9kqaBw5n8NfsZIFRVOgO/27rf8fglqQWIUTOfpXXTPWyY2EUXqHtvFsDLNmz78KnmV/ X-Received: by 2002:a63:3688:: with SMTP id d130-v6mr2457120pga.228.1524841398623; Fri, 27 Apr 2018 08:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524841398; cv=none; d=google.com; s=arc-20160816; b=O7hWMMoQzxHWr6dNFbdLC8cUKK+RcLZbniBIUl38teFcAhre8dRxzXlokdeuTvrcKd +ByaQxxYVhfz6mlfIAskse6Utji0eDPymW2Ei4pYieNm+v2CYk036shrhL/4HkkdqsuL 1Kmcbq9bD3nizwKEGLMtIo+94YneaNLnD4odeCQopAT0n1PjKKPeV5fHvbZkE8AVQyuu 4IQkDS31980e/qWUVh5Xd2U1x8DOjNHalpQJcm63Jp8qUlBviTF7tLnctC6HaBN+Mgp5 KoT8vEBidgGPdFLueAOYE1tkUdIBqsx8f0lirjJEolf5rzN8Z3UiFq86vbAqKA/3plor L7EQ== 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=3j7pWtyReiAMCDMQd00YQpMNyFa/aXzixj0t8E0fLG8=; b=rij/JlDTOU63fBSmLCPK7/J0Z6i1ff0fdj5ATOgA2yJxPBt5cMT/o7gKQzKGQKGVVW 0z4N8gKdi/2IspKjXqcs599YQdL5lWv863IxiEx782oR0rnnt/PkrkuCMrIvZZpP4jgV ikniGwvyBhKCkSF5trQOHTLFH28MLiszL2sKrGloLS6LC+30iZOHS4IG2wYayTqy/47C cmaW8/RdPsH4Wzbq7c9PkW5R4yMBt6JRYY2RBvLgg9g7CVlIf41OrRx9iLeWjJrp/cN3 fUscGLPGyrf2yvnPlYNYbskkb8II56hZvmknT4i9oczLxzu61R2OuC/x5ImcthvsRD50 FMgg== 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 q66si1457596pfk.190.2018.04.27.08.03.04; Fri, 27 Apr 2018 08:03:18 -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 S933928AbeD0OF3 (ORCPT + 99 others); Fri, 27 Apr 2018 10:05:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:51564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933900AbeD0OFU (ORCPT ); Fri, 27 Apr 2018 10:05:20 -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 AA3DD21890; Fri, 27 Apr 2018 14:05:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AA3DD21890 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.9 68/74] strparser: Fix incorrect strp->need_bytes value. Date: Fri, 27 Apr 2018 15:58:58 +0200 Message-Id: <20180427135712.758259744@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180427135709.899303463@linuxfoundation.org> References: <20180427135709.899303463@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.9-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 @@ -285,9 +285,9 @@ static int strp_recv(read_descriptor_t * strp_start_rx_timer(strp); } + rxm->accum_len += cand_len; strp->rx_need_bytes = rxm->strp.full_len - rxm->accum_len; - rxm->accum_len += cand_len; rxm->early_eaten = cand_len; STRP_STATS_ADD(strp->stats.rx_bytes, cand_len); desc->count = 0; /* Stop reading socket */ @@ -310,6 +310,7 @@ static int strp_recv(read_descriptor_t * /* Hurray, we have a new message! */ del_timer(&strp->rx_msg_timer); strp->rx_skb_head = NULL; + strp->rx_need_bytes = 0; STRP_STATS_INCR(strp->stats.rx_msgs); /* Give skb to upper layer */ @@ -374,9 +375,7 @@ void strp_data_ready(struct strparser *s return; if (strp->rx_need_bytes) { - if (strp_peek_len(strp) >= strp->rx_need_bytes) - strp->rx_need_bytes = 0; - else + if (strp_peek_len(strp) < strp->rx_need_bytes) return; }