Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2208324imm; Mon, 28 May 2018 04:00:15 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrTd9OsYn7WEZSj3V+ZXscEDiWhaNsFu7DI2pW1NNR0UxRbo9c8pGiGeEZdtJpWp0U4W5fV X-Received: by 2002:a17:902:284b:: with SMTP id e69-v6mr12833143plb.240.1527505215478; Mon, 28 May 2018 04:00:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527505215; cv=none; d=google.com; s=arc-20160816; b=gUzLqQfpehzmhXlhoY3wlplXp1gIo/cf57rOZiNef+KAZ6N2slAaYm4IyO/F5/ieom BEoAYmvLu3IA4fIiAfSUZCvJ5KvC4K6e0WLJtUxf+qiWgX/dKOiF7ReIaJTUYJbRERZU dwuM4lMgKqMz0CJVlnbW9U+iBa/Rcr5dMKEYBJ5nlLXxASRrnXywltGSSilfVpi76VP5 +rdQ0tdsMRZvyakYWNeB5NvAkg9Wo2BEVhm+P6MRR9+2CceHOuxBHEVSofGkIo+fLA+7 O7IA3W6YyKqFVZch4v7iEbXs95MQXrmVjOvb5oDXa2u020+QEcwrc/LdS7aw5cvilzJN A+Bw== 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=KLvSu1/bWdub0H55nJP2bPoyJE1Qiuj1dpqbqumV4Xw=; b=gWuS8n+8EIKFJSUpLi8ldJNRQw03Oi3VzrhLgpDVu9kBiIiu77q47SOYLspV2a59as inH21H/FmI/z/lQrSmlfP59Wkvlzp15Anok2G5nubqEHHL2jhgWLPrFb4Sp5GIY6U1Vr /YFaC/kCJ0jVKDk6XuVADyDPMaLMSFqoqoCuQ040epiQ9jQvec0VvETczlGEbBRph6KV 2j+8tJpBT31CkBjo4q40Sr7YUv1HItLU8APePmUdrPuZltmEoesG9pgur4SuADBhczma DoNbIxYkAu2jOgx9tM3WYZtVdagECYaX9WgcA9ShYCqhghNebuV/dVxcRFgv3pLhS3N8 zQXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Mo3C/jBI; 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 j15-v6si7517505pga.252.2018.05.28.03.59.30; Mon, 28 May 2018 04:00:15 -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=Mo3C/jBI; 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 S1164428AbeE1Kzo (ORCPT + 99 others); Mon, 28 May 2018 06:55:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:44182 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164416AbeE1Kzi (ORCPT ); Mon, 28 May 2018 06:55:38 -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 64F5120845; Mon, 28 May 2018 10:55:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527504938; bh=LC/iRvMLHgsZEMeTBea9atp4/ZwClC1OB8HsUVEUieg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mo3C/jBIYEH+Xp/3Y9W3bZS5tpWM8GiTpJ6mVekdWnh+ZjMq7ZHEulHYiShqqWkEp LaH3cU3e8TXoakNAv114JP3/AtkeXTLSsLYlGpKgtmBP8MoVnaxJS3tPQqVuVf4NMo ANFpDHg9WIpb3gRfxS0tTAYbqufrQnofHpHrfE98= 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 284/496] net/sched: fix idr leak in the error path of tcf_skbmod_init() Date: Mon, 28 May 2018 12:01:09 +0200 Message-Id: <20180528100331.808800023@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 f29cdfbe33d6915ba8056179b0041279a67e3647 ] tcf_skbmod_init() can fail after the idr has been successfully reserved. When this happens, every subsequent attempt to configure skbmod rules using the same idr value will systematically fail with -ENOSPC, unless the first attempt was done using the 'replace' keyword: # tc action add action skbmod swap mac index 100 RTNETLINK answers: Cannot allocate memory We have an error talking to the kernel # tc action add action skbmod swap mac index 100 RTNETLINK answers: No space left on device We have an error talking to the kernel # tc action add action skbmod swap mac index 100 RTNETLINK answers: No space left on device We have an error talking to the kernel ... Fix this in tcf_skbmod_init(), ensuring that tcf_idr_release() is called on the error path when the idr has been reserved, but not yet inserted. Also, don't test 'ovr' in the error path, to avoid a 'replace' failure implicitly become a 'delete' that leaks refcount in act_skbmod module: # rmmod act_skbmod; modprobe act_skbmod # tc action add action skbmod swap mac index 100 # tc action add action skbmod swap mac continue index 100 RTNETLINK answers: File exists We have an error talking to the kernel # tc action replace action skbmod swap mac continue index 100 RTNETLINK answers: Cannot allocate memory We have an error talking to the kernel # tc action list action skbmod # # rmmod act_skbmod rmmod: ERROR: Module act_skbmod is in use 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_skbmod.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/net/sched/act_skbmod.c +++ b/net/sched/act_skbmod.c @@ -155,7 +155,7 @@ static int tcf_skbmod_init(struct net *n ASSERT_RTNL(); p = kzalloc(sizeof(struct tcf_skbmod_params), GFP_KERNEL); if (unlikely(!p)) { - if (ovr) + if (ret == ACT_P_CREATED) tcf_idr_release(*a, bind); return -ENOMEM; }