Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp217137ybi; Fri, 26 Jul 2019 08:37:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqzaZpSuSsAsxj29TxFRXUnSK6kU6fGEIwQEGwjKEHpAyZ7eYb8enqMBAKYmnchqB7C3IFBl X-Received: by 2002:a63:d741:: with SMTP id w1mr17174353pgi.155.1564155432044; Fri, 26 Jul 2019 08:37:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564155432; cv=none; d=google.com; s=arc-20160816; b=Guwf3T8RKhewMobEn2em++NYWvtb6BV1sVd+B8+h4q2cUKNc7J3krTOymQswNCu8vb /sAMgH9FMFJydUq7oSrYSWDMbqcN6rHgYIn1+icPqJs8wGZLzekUhx0QRNKwCUMRVPwf jgMBWBIEHo+yzN/9Uq4o4nGasAxYCRFokjBP/c3OpVGke7if+dmGa/QcEdkKiFtNj6tl 6aUZsss0LZz01vzhe3XlJXDJhlXnp24nrysZ56hl6yu5K8GoMmk9tdm4YnnnrjJFT0e7 Z6YSey0SAavz4R9mPRJ/aBBta+/mUYQB65Kk8NBDS5pFlkL6pg8WmVN9wn5wZe7XCN4s 9iZQ== 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=knhB90bdNrwHTPyNsjuNfcs9Npi6kQbSjoZVtNDg2As=; b=yjjhjGgTwa4YL+goc9ViPJ2xLoOgdBf6jlmAutvNejBszVr4GRSjcYQY6EibnCXlJg 9o/inaH3Uw68sBSWDCMJfXpsAB7ATKYNvgwdbxpD2JM9tazzLXkzQbaky+M6xqxrjnHy Zf63fqHOTN5jZrG53v0INWLF7HPQJ5cyZCR3cRXspNtKU+ruLbhYn+jH6UEt1T9TPH03 twl0XJ6ijVPHPTfx/Vttx92Q1V3+uPoTvPpMSGhiBidCx6e3qCZrv7Vb2pkIooqzmQaH QAGz0YnFQvWz5wrZRcKXL103nNglak2Teux9M0reXRGDhGYxatL4wz9wD28+GdFRJADX QOyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lL4LR6US; 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 x9si21879645pfi.211.2019.07.26.08.36.57; Fri, 26 Jul 2019 08:37:12 -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=lL4LR6US; 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 S2389435AbfGZPfk (ORCPT + 99 others); Fri, 26 Jul 2019 11:35:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:47612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389467AbfGZPc0 (ORCPT ); Fri, 26 Jul 2019 11:32:26 -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 A56B122BF5; Fri, 26 Jul 2019 15:32:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564155145; bh=sSpOQg3DGB+OdznWUnm//oWTucUswY7vQ6TMsiW/ux4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lL4LR6USvezZv+QnO4MG4+u+iVFvjYM88v2g4ZCb0M+oMssKrD895J7NnoJDD8/Ug ouXBTBO0RyLu7HNrJPM6c/0vH1UIEQ5VLuEZo59+ljQ2lWwXR+yfAWfxojJRQlzLqG DYK+JiM8PbMOclABK7mVz8HAmT7ARJtn/7p3CIPA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+c1a380d42b190ad1e559@syzkaller.appspotmail.com, Xin Long , Marcelo Ricardo Leitner , Neil Horman , "David S. Miller" Subject: [PATCH 4.19 18/50] sctp: fix error handling on stream scheduler initialization Date: Fri, 26 Jul 2019 17:24:53 +0200 Message-Id: <20190726152302.447932256@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190726152300.760439618@linuxfoundation.org> References: <20190726152300.760439618@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: Marcelo Ricardo Leitner [ Upstream commit 4d1415811e492d9a8238f8a92dd0d51612c788e9 ] It allocates the extended area for outbound streams only on sendmsg calls, if they are not yet allocated. When using the priority stream scheduler, this initialization may imply into a subsequent allocation, which may fail. In this case, it was aborting the stream scheduler initialization but leaving the ->ext pointer (allocated) in there, thus in a partially initialized state. On a subsequent call to sendmsg, it would notice the ->ext pointer in there, and trip on uninitialized stuff when trying to schedule the data chunk. The fix is undo the ->ext initialization if the stream scheduler initialization fails and avoid the partially initialized state. Although syzkaller bisected this to commit 4ff40b86262b ("sctp: set chunk transport correctly when it's a new asoc"), this bug was actually introduced on the commit I marked below. Reported-by: syzbot+c1a380d42b190ad1e559@syzkaller.appspotmail.com Fixes: 5bbbbe32a431 ("sctp: introduce stream scheduler foundations") Tested-by: Xin Long Signed-off-by: Marcelo Ricardo Leitner Acked-by: Neil Horman Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/sctp/stream.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/net/sctp/stream.c +++ b/net/sctp/stream.c @@ -253,13 +253,20 @@ out: int sctp_stream_init_ext(struct sctp_stream *stream, __u16 sid) { struct sctp_stream_out_ext *soute; + int ret; soute = kzalloc(sizeof(*soute), GFP_KERNEL); if (!soute) return -ENOMEM; SCTP_SO(stream, sid)->ext = soute; - return sctp_sched_init_sid(stream, sid, GFP_KERNEL); + ret = sctp_sched_init_sid(stream, sid, GFP_KERNEL); + if (ret) { + kfree(SCTP_SO(stream, sid)->ext); + SCTP_SO(stream, sid)->ext = NULL; + } + + return ret; } void sctp_stream_free(struct sctp_stream *stream)