Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2312448imm; Mon, 28 May 2018 05:54:42 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrcpY+0KKQIYhBREL7uz7fKthgLGof7aMiFuIEheVVchC2OLTb7xwz4gNJJqjdsWAdxxVju X-Received: by 2002:a17:902:6181:: with SMTP id u1-v6mr13382180plj.369.1527512082324; Mon, 28 May 2018 05:54:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527512082; cv=none; d=google.com; s=arc-20160816; b=IpAY5nSO+MTki4HfEtzy1eHoZnJqhmAWJpx1gJSsoKbmt9Iy1RPtw3ibUxeY1U+wQC mhYquZV+A2aerk0XzUaG++V2Aiy7ot0FiR7bDJrQomKZ1OkNGQ2jOhPzy0xv5p41vEFT BKkMX39siSfZC5TfITrOW1I+kezL6ad9exz5UQOl50lxEYyppYjrEdLvpzQpxVJdQji5 nOg6xh4bBSidPI9Xh6tU2lnXK2fsYYcAGYOzNXlFDl87olv+kp9Pivw/t47i9vpaqZ4Q 4CFaMPtTV5/seOPw29EUVmtYEdQvuWRKx/y8u0hgpeTDDqYNhhzJw6w85EhK9qe025u6 GCWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=PgKdcBU7L6sWFUN+Zo/+5LyuyL1ltnJQ3Do7d6LxJac=; b=baOFlkk1UZ4t0amrmXJxN8SYLtothEb8dkJkTTzAhWNUSgRHouV560Z0CqB3E0fcFi fNk+VdKXCpiVec1YLxagZZBpcxeiWu1q7fKSeTrSIGJufGIg3bGIs389EAfdGsJWiYrw EsoQ/CPp8ztMBu7LcN8MO9hL5dhM+cBsU719emekYCkxNH98eIQOCM7c1Srfdf0lbK+R 1896unVe+j24PdNqNgjKsSwfX12u/SC1wHq+g85hTJMwXCRHr8cQbyzPS8e5y/ExtfNZ p/qIvxJMb0cyFxF65eF39LCl3ya5dRCuWaz4v2/dOeUabYPwrwf964txpqqOoXcLey03 yPQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GZWIpYGb; 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 f9-v6si28403453plo.568.2018.05.28.05.54.27; Mon, 28 May 2018 05:54:42 -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=GZWIpYGb; 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 S1424964AbeE1Mx3 (ORCPT + 99 others); Mon, 28 May 2018 08:53:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:44134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164222AbeE1Kzf (ORCPT ); Mon, 28 May 2018 06:55:35 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 9E94820845; Mon, 28 May 2018 10:55:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527504935; bh=KQS8IAs/JravFK5DuoP3CuXYUSnDusSp/5J6dLUPcPw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GZWIpYGbZfFoE8TIHdzECZpbx/DLcgGSFsemF9kceBAOGWYXHF3uznWvpI+uSkGVP SMJD3N9ATdWJyEJy99O2Yr56H8dfkX7wSoOY1i+qDpe4XESxhazMp2SXcBO+gFMF3b 1zALT/+ieOncbKr5gbHhMlpPb1dvqUu/+2bOHwYk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jamal Hadi Salim , Davide Caratti , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 283/496] net/sched: fix idr leak in the error path of __tcf_ipt_init() Date: Mon, 28 May 2018 12:01:08 +0200 Message-Id: <20180528100331.764653302@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100319.498712256@linuxfoundation.org> References: <20180528100319.498712256@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Davide Caratti [ Upstream commit 1e46ef1762bb2e52f0f996131a4d16ed4e9fd065 ] __tcf_ipt_init() can fail after the idr has been successfully reserved. When this happens, subsequent attempts to configure xt/ipt rules using the same idr value systematically fail with -ENOSPC: # tc action add action xt -j LOG --log-prefix test1 index 100 tablename: mangle hook: NF_IP_POST_ROUTING target: LOG level warning prefix "test1" index 100 RTNETLINK answers: Cannot allocate memory We have an error talking to the kernel Command "(null)" is unknown, try "tc actions help". # tc action add action xt -j LOG --log-prefix test1 index 100 tablename: mangle hook: NF_IP_POST_ROUTING target: LOG level warning prefix "test1" index 100 RTNETLINK answers: No space left on device We have an error talking to the kernel Command "(null)" is unknown, try "tc actions help". # tc action add action xt -j LOG --log-prefix test1 index 100 tablename: mangle hook: NF_IP_POST_ROUTING target: LOG level warning prefix "test1" index 100 RTNETLINK answers: No space left on device We have an error talking to the kernel ... Fix this in the error path of __tcf_ipt_init(), calling tcf_idr_release() in place of tcf_idr_cleanup(). Since tcf_ipt_release() can now be called when tcfi_t is NULL, we also need to protect calls to ipt_destroy_target() to avoid NULL pointer dereference. Fixes: 65a206c01e8e ("net/sched: Change act_api and act_xxx modules to use IDR") Acked-by: Jamal Hadi Salim Signed-off-by: Davide Caratti Signed-off-by: David S. Miller Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/sched/act_ipt.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/net/sched/act_ipt.c +++ b/net/sched/act_ipt.c @@ -80,9 +80,12 @@ static void ipt_destroy_target(struct xt static void tcf_ipt_release(struct tc_action *a, int bind) { struct tcf_ipt *ipt = to_ipt(a); - ipt_destroy_target(ipt->tcfi_t); + + if (ipt->tcfi_t) { + ipt_destroy_target(ipt->tcfi_t); + kfree(ipt->tcfi_t); + } kfree(ipt->tcfi_tname); - kfree(ipt->tcfi_t); } static const struct nla_policy ipt_policy[TCA_IPT_MAX + 1] = { @@ -187,7 +190,7 @@ err2: kfree(tname); err1: if (ret == ACT_P_CREATED) - tcf_idr_cleanup(*a, est); + tcf_idr_release(*a, bind); return err; }