Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4408405pxu; Mon, 12 Oct 2020 19:20:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzPdND2YJQPeUTpAKPQeKYyfzIMywH0O9m2mApZ032V32yRK39bCG0JNVI6nsi1fFflMmD X-Received: by 2002:a50:ec88:: with SMTP id e8mr17101881edr.277.1602555633129; Mon, 12 Oct 2020 19:20:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602555633; cv=none; d=google.com; s=arc-20160816; b=KTvMhrEZWDy9X4UPK8IrbU1NN4Rp6I4SBNr5YGN2MVWb6GxSgrZca6SQGxgcVAHeVZ kgVr3/Ksh++tH0ZGAq/ppctdX+TKINmTS/ztl3EiBzCnKgDZDn8v2vRhgHGPFIJZKssm A9MjSw7vIn19wLEivNZ2EwfHTydNs99AVcD+Klmqj3TsdNSChORAjTih5iBhLxBiyiw1 v9A4Pm8r8JDvCtuDcFuT9/Sm82D1ffHCnqvUdNNB7GN9QmJUy89iAz41nVBsekoyzluT CEwHgSm6xWyqsyFIIK7pog0CDXBb8oyuW8F3o9g9WTv3JZJDtHzsX+2SwaA7EE41E3ah s2DQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ym7HpWWx1giY7lKu50OB1si4MVDKhZswnuGsZqvVWqM=; b=Z0OShLzl3qvweJDLJfeN9ktOzfl2mZrJefyc3zsL++MQwVsETL1nz2DrSyZShZKPAe Hj1/2CZ63X7iCpXN9asOAncGx5qW10JRsXHA71AvxhoStP6u4ht0ggMqDCXr1K7t/bJn 9B7VlKS7Sy6hoODPGRkzMIsZYhDxuZyufyB8dTHS3Ik9xYbpMkCVxuwDUE5HNpUDWOkn MZ12BmYtG8TgPtiUfh2FlpPly7r9BPQ3nFXEzkwU3kW9myW/Elm/j/gJb4piXXN1uwBQ CMEk9KrFB4e+v4MZF1bYrpApltURxu5/89QHdBrV8YAE2Zxp6PmNExm654MlDZgWhNKI ENVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bgQmgy1A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n9si11992074edv.393.2020.10.12.19.20.11; Mon, 12 Oct 2020 19:20:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bgQmgy1A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731676AbgJLOBr (ORCPT + 99 others); Mon, 12 Oct 2020 10:01:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:41466 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731094AbgJLNiH (ORCPT ); Mon, 12 Oct 2020 09:38:07 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 2F2B52074F; Mon, 12 Oct 2020 13:38:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602509886; bh=JY3QkbtFRG3ZJnkRtN1wiSMf34tBUOJ1EJgwJRKXcxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bgQmgy1AItnbdZF2vWuJgYG6DGjurxyLJnTFArAJmv3Uf0XYwSDedKJE8Gd1KD6S/ yptW8DbEix6CReSu2Ucfk/4OSCOP+GOR81Mqzn/hoszgjnj+nd5x5VxYwWPxJX5Rwj uw4NZPB+/N7KNBub5RAv7n7RRgmrssnsCpyDMP40= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+69b804437cfec30deac3@syzkaller.appspotmail.com, Anant Thazhemadam , "David S. Miller" Subject: [PATCH 4.14 51/70] net: team: fix memory leak in __team_options_register Date: Mon, 12 Oct 2020 15:27:07 +0200 Message-Id: <20201012132632.642941802@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012132630.201442517@linuxfoundation.org> References: <20201012132630.201442517@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anant Thazhemadam commit 9a9e77495958c7382b2438bc19746dd3aaaabb8e upstream. The variable "i" isn't initialized back correctly after the first loop under the label inst_rollback gets executed. The value of "i" is assigned to be option_count - 1, and the ensuing loop (under alloc_rollback) begins by initializing i--. Thus, the value of i when the loop begins execution will now become i = option_count - 2. Thus, when kfree(dst_opts[i]) is called in the second loop in this order, (i.e., inst_rollback followed by alloc_rollback), dst_optsp[option_count - 2] is the first element freed, and dst_opts[option_count - 1] does not get freed, and thus, a memory leak is caused. This memory leak can be fixed, by assigning i = option_count (instead of option_count - 1). Fixes: 80f7c6683fe0 ("team: add support for per-port options") Reported-by: syzbot+69b804437cfec30deac3@syzkaller.appspotmail.com Tested-by: syzbot+69b804437cfec30deac3@syzkaller.appspotmail.com Signed-off-by: Anant Thazhemadam Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/team/team.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/net/team/team.c +++ b/drivers/net/team/team.c @@ -299,7 +299,7 @@ inst_rollback: for (i--; i >= 0; i--) __team_option_inst_del_option(team, dst_opts[i]); - i = option_count - 1; + i = option_count; alloc_rollback: for (i--; i >= 0; i--) kfree(dst_opts[i]);