Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4342206pxu; Mon, 12 Oct 2020 16:53:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywmJ+ZwerL5yiiKKJEqvC9d7Jz0utdKgbLpPmubKyd5/S5cpwsLrNMg2IBO77Sq2AkvOKV X-Received: by 2002:a17:906:14d8:: with SMTP id y24mr30097157ejc.123.1602546686427; Mon, 12 Oct 2020 16:51:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602546686; cv=none; d=google.com; s=arc-20160816; b=sP96l2kNiZcBNpG13kJZVnNz1BPKh5ySDm4M70XGelCFyOAml+5gRmGY4AYUCE7uxN BoiNGdSzRLsuwwriBezdIoWnfPzEYPvobC7v7/kN/eRZQpGqK2ijOmrfaOs7sTYI6z5O EQHjb8bAi0Jx0CuufxvZgse1bU3cvleu9oREIe9P5wz8Yqoswt8gVRBM5po8Wv+tLDQW /h+X72afA3i1OoOtFzHa3/wQVWxQNvLhtmaLYlYVxbOc96oiXbLyk11BR8IJeOtinWTN QNYpohkRVy7wgJFrXI3ywg1uYmVjcljR1vECCUaCmIIGK4I8cRyrvjAgX9mXVJ7o+GOh WlZw== 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=RmokNmZ6sTCWZnilkuyCs1NdzDKQFYK3bNXBiasYR2U=; b=cTr4fDKMQxLOP7aUn3UHvDZDnYJihMzqW9KqVxZm+m0MHOz6fVIHKgLtUQzGPRYxv9 gNA5vPzUu6D40OH+0dOByTC6w2n+kgDA4HpPWb3Bvwy4PTmuHDrlEDOIVnMDc4SnS/fC piUamFMq3/xbhV98VCIuDe280K9Y6bi2FFBVJTTvkgt3Gpqd+KRRRUHRsTpb6QHrsO10 xvpOfWgRCmNMpCMYoghc9IG+vvscHAbJepYIJ+AIY3JEypcgpgNQ9LU8+lcU4JdgWGq2 TrQw8OtiycNsBkCmt7Fp30CDlx4Rj+fQ08gHz+ovnlsq+CM/N/Lf7Civgq4n/1Ej8hrJ Kdzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xokJNihn; 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 l91si11972251edl.566.2020.10.12.16.51.03; Mon, 12 Oct 2020 16:51:26 -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=xokJNihn; 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 S2389793AbgJLNp4 (ORCPT + 99 others); Mon, 12 Oct 2020 09:45:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:48072 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389747AbgJLNpy (ORCPT ); Mon, 12 Oct 2020 09:45:54 -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 C2E6C222D5; Mon, 12 Oct 2020 13:45:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602510308; bh=hIm/wYYl0doePaPKkN7iO5I3ZmBsb/RHHwm4JJMhybw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xokJNihni8cIONoEVQwrl8zovC19EFXPsJfuJ/V3B9l5EHoVibTVl/fNYgV832iDb UP91YtU4r0Guu6P867UVumcIq9MMSrJMFKiVloOiNxaNCp8nK518mXj00idNJ6Mz9t Qf8/xljMNDW9ZDEvQ8LOgAOphe4wOjvsT8VmM6Rc= 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 5.8 043/124] net: team: fix memory leak in __team_options_register Date: Mon, 12 Oct 2020 15:30:47 +0200 Message-Id: <20201012133148.938768556@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012133146.834528783@linuxfoundation.org> References: <20201012133146.834528783@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 @@ -287,7 +287,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]);