Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp698809ybh; Tue, 10 Mar 2020 06:41:25 -0700 (PDT) X-Google-Smtp-Source: ADFU+vut3pbd8hnh6n2uubfPaTrvE6g81GECbmEBCm7TRoOYk0pwYSH60s9a1JQXwvckiK0RodgD X-Received: by 2002:aca:dc56:: with SMTP id t83mr1242848oig.105.1583847685405; Tue, 10 Mar 2020 06:41:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583847685; cv=none; d=google.com; s=arc-20160816; b=YoaZjbscGMLWLXFbJPSqTvH+csyxcZSyJq+k7lF1Wbk4Na+cqYnGOZBU95IfCWvmpr 9BFfDm8/aypnF8WR14cwMRZ4LWkpuB3BnemHlwkovewC9TF4r0e16L8KIDmtgqTcQrhQ On/XLdaMCT0tV64AaGKjxbey2LXDf3sPputAF/2BsZcAvsgWGdgH/HpBKoYDCuVoP++8 90GZ60jkKoGNi8Jk/ucGxVGqHWufvsvpxO9xg/Bf5jpLZuiduuz3nJ9n7Y1pqbdXz0F+ iAGl9w38lMyN4wyESaYp1pQs1YJQyyFqRBbiETD15JCyVPxpKexX+iEntB/OAl5pWp+X gn/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tdCakLmGGdbV6/mSnxMAz5CTuCLgEuPNdLSh0lJ7no8=; b=FDHu+VmmZejI3yhufTwIy7NTHRMFI49fifVVwf9ApzFMUBX94mjHdcXLs6BjnlZydk Rqv6LL8HD9zfh596KRffaY7SLGnO6bFqIXeeNOEa4rc871mUSj0oxEwGXFRlGD0ZDEqZ 9PApdqAR8KcfvvD2Hbj6batHuD7ESyJOdq049InSSsc+vIdGHJQCYIkbHbDzG53UdhQq t7aljETeyuBWDaIpL7Ln8voVhsJm4Kbmrn1K6VTtvWJoSCRKF5/BUlooPPOxngVXrubo w9v97dOc7eVY3aAMPZRajhyF8t/TuA+SQ74TRBFB8kQZExyYZkfZVxk67awixqBMKD8J dboQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RVfgnAaF; 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 k98si8019270otk.61.2020.03.10.06.41.13; Tue, 10 Mar 2020 06:41:25 -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; dkim=pass header.i=@kernel.org header.s=default header.b=RVfgnAaF; 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 S1726858AbgCJMmq (ORCPT + 99 others); Tue, 10 Mar 2020 08:42:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:42840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726705AbgCJMmm (ORCPT ); Tue, 10 Mar 2020 08:42:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 7833724691; Tue, 10 Mar 2020 12:42:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583844161; bh=0yC6sXkVWtqG7e+QMEiQvk1PLyTDCmV8uQD29gvoQ4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RVfgnAaFN39llhNOYKqXtEFE9kyoSsxd29tuCfBdqMj7+xWaQ1YcRvmnP7+rFpVBb 2lZl+jENani0Cv+4Dcqva9esDbpuaXrduM81zTAEMRMHz/qBXaRmpRKuLABKadppLA yAtC19ZqOt/HyIMmrUOesM7ryiiY8CNC+TwYOChg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hangbin Liu , Marcelo Ricardo Leitner , Xin Long , "David S. Miller" Subject: [PATCH 4.4 16/72] sctp: move the format error check out of __sctp_sf_do_9_1_abort Date: Tue, 10 Mar 2020 13:38:29 +0100 Message-Id: <20200310123605.668187910@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200310123601.053680753@linuxfoundation.org> References: <20200310123601.053680753@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xin Long [ Upstream commit 245709ec8be89af46ea7ef0444c9c80913999d99 ] When T2 timer is to be stopped, the asoc should also be deleted, otherwise, there will be no chance to call sctp_association_free and the asoc could last in memory forever. However, in sctp_sf_shutdown_sent_abort(), after adding the cmd SCTP_CMD_TIMER_STOP for T2 timer, it may return error due to the format error from __sctp_sf_do_9_1_abort() and miss adding SCTP_CMD_ASSOC_FAILED where the asoc will be deleted. This patch is to fix it by moving the format error check out of __sctp_sf_do_9_1_abort(), and do it before adding the cmd SCTP_CMD_TIMER_STOP for T2 timer. Thanks Hangbin for reporting this issue by the fuzz testing. v1->v2: - improve the comment in the code as Marcelo's suggestion. Fixes: 96ca468b86b0 ("sctp: check invalid value of length parameter in error cause") Reported-by: Hangbin Liu Acked-by: Marcelo Ricardo Leitner Signed-off-by: Xin Long Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sctp/sm_statefuns.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c @@ -177,6 +177,16 @@ sctp_chunk_length_valid(struct sctp_chun return 1; } +/* Check for format error in an ABORT chunk */ +static inline bool sctp_err_chunk_valid(struct sctp_chunk *chunk) +{ + struct sctp_errhdr *err; + + sctp_walk_errors(err, chunk->chunk_hdr); + + return (void *)err == (void *)chunk->chunk_end; +} + /********************************************************** * These are the state functions for handling chunk events. **********************************************************/ @@ -2159,6 +2169,9 @@ sctp_disposition_t sctp_sf_shutdown_pend sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest)) return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands); + if (!sctp_err_chunk_valid(chunk)) + return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); + return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands); } @@ -2201,6 +2214,9 @@ sctp_disposition_t sctp_sf_shutdown_sent sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest)) return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands); + if (!sctp_err_chunk_valid(chunk)) + return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); + /* Stop the T2-shutdown timer. */ sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP, SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN)); @@ -2466,6 +2482,9 @@ sctp_disposition_t sctp_sf_do_9_1_abort( sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest)) return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands); + if (!sctp_err_chunk_valid(chunk)) + return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); + return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands); } @@ -2482,15 +2501,9 @@ static sctp_disposition_t __sctp_sf_do_9 /* See if we have an error cause code in the chunk. */ len = ntohs(chunk->chunk_hdr->length); - if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr)) { - - sctp_errhdr_t *err; - sctp_walk_errors(err, chunk->chunk_hdr); - if ((void *)err != (void *)chunk->chunk_end) - return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); + if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr)) error = ((sctp_errhdr_t *)chunk->skb->data)->cause; - } sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET)); /* ASSOC_FAILED will DELETE_TCB. */