From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_MUTT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24DE3C28CC0 for ; Thu, 30 May 2019 11:24:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 08F0225836 for ; Thu, 30 May 2019 11:24:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726902AbfE3LY6 (ORCPT ); Thu, 30 May 2019 07:24:58 -0400 Received: from charlotte.tuxdriver.com ([70.61.120.58]:36507 "EHLO smtp.tuxdriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725440AbfE3LY6 (ORCPT ); Thu, 30 May 2019 07:24:58 -0400 Received: from cpe-2606-a000-111b-405a-0-0-0-162e.dyn6.twc.com ([2606:a000:111b:405a::162e] helo=localhost) by smtp.tuxdriver.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1hWJAr-0006YK-LB; Thu, 30 May 2019 07:24:52 -0400 Date: Thu, 30 May 2019 07:24:18 -0400 From: Neil Horman To: Marcelo Ricardo Leitner Cc: syzbot , davem@davemloft.net, linux-kernel@vger.kernel.org, linux-sctp@vger.kernel.org, netdev@vger.kernel.org, syzkaller-bugs@googlegroups.com, vyasevich@gmail.com Subject: Re: memory leak in sctp_process_init Message-ID: <20190530112418.GB1966@hmswarspite.think-freely.org> References: <00000000000097abb90589e804fd@google.com> <20190528013600.GM5506@localhost.localdomain> <20190528111550.GA4658@hmswarspite.think-freely.org> <20190529190709.GE31099@hmswarspite.think-freely.org> <20190529233757.GC3713@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190529233757.GC3713@localhost.localdomain> User-Agent: Mutt/1.11.3 (2019-02-01) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Wed, May 29, 2019 at 08:37:57PM -0300, Marcelo Ricardo Leitner wrote: > On Wed, May 29, 2019 at 03:07:09PM -0400, Neil Horman wrote: > > --- a/net/sctp/sm_make_chunk.c > > +++ b/net/sctp/sm_make_chunk.c > > @@ -2419,9 +2419,12 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk, > > /* Copy cookie in case we need to resend COOKIE-ECHO. */ > > cookie = asoc->peer.cookie; > > if (cookie) { > > + if (asoc->peer.cookie_allocated) > > + kfree(cookie); > > asoc->peer.cookie = kmemdup(cookie, asoc->peer.cookie_len, gfp); > > if (!asoc->peer.cookie) > > goto clean_up; > > + asoc->peer.cookie_allocated=1; > > } > > > > /* RFC 2960 7.2.1 The initial value of ssthresh MAY be arbitrarily > > What if we kmemdup directly at sctp_process_param(), as it's done for > others already? Like SCTP_PARAM_RANDOM and SCTP_PARAM_HMAC_ALGO. I > don't see a reason for SCTP_PARAM_STATE_COOKIE to be different > here. This way it would be always allocated, and ready to be kfreed. > > We still need to free it after the handshake, btw. > Yeah, that makes sense, I'll give that a shot. Neil > Marcelo >