From patchwork Thu Jul 27 17:47:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 127096 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp1274775vqo; Thu, 27 Jul 2023 11:06:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlG2TMKubDyrV+oLdFAArNgVDiRD/wATk1QZQarXbZKuyf6N2THqczI90+6hE9xHjF7EJNn0 X-Received: by 2002:a17:903:18d:b0:1b8:a389:4410 with SMTP id z13-20020a170903018d00b001b8a3894410mr118596plg.0.1690481201174; Thu, 27 Jul 2023 11:06:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690481201; cv=none; d=google.com; s=arc-20160816; b=g1pJMR+tKMiTj9GEQSig1NNucOXIB+8OhHRBlMkrqy/XwgazSdvr2sEoV8CSOyPgVo wejNOkqyzrWIf+EU9WdJYVbzyLovx4VLH6tSFkeB9fKUkr8OM9h3K2t+Zgbk9o4MrlRK OZGJ7XpKsiIXXDjVD7xQERa5y+4e1NjiNeNTqabX+9ZXTAT2Lm7ITzDe2zNw2pGM52WC tCdZ66GL+w6N2WT0Vo9HksJCSoJ3vKw8b/QGQYL3lu45zqQedzjsNRsqBOP+7HQV3An6 84fvmYbATgtSAIrJ0xoFh7OkpBVBmWV6ne0LrJGbioKX3J1PKbfP2yqQbCGeV4a4v/OU 1muA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=gox4gfYQZsQnGvVlvM/7tRFCzC5TnTXv5wfqJcH41fs=; fh=fehxmcoCOz+tCBq1OG5vCiT0wukH1TYPv9ixqO+IhE8=; b=fuJ+tE6ySFbUVrAOGC2Py71RKqqd9pxJsB1skT88XLSmI87IXNng1dyHxoOvAOIFax N6cmylcRquiYK4ndJe2rv8ClgrMOQESOVaMm+Hg5gQ1HiVcpp7sfJ8fk26ABfwrgCWtT yP/2FJhZF5ejHZuFY2Ivghj2iYo+8+Jc+j2JdJr6JhkTyn+GLAs8OmkCuFG17xr6jKml uOuu+kc0Ml8jFg/sekfYzLHSQh2kDG3PRjIaTpGLGduNsg5IPWpi7dKATN/woIj703SG LJhA8CJ6wOJOyeCLii7lZFi3u/SxB12zEqcHYi19CsYRYMEuK6c8MCnpzKgK/BbGOfo0 9gSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PSmn3vIH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e4-20020a170902e0c400b001a51368b098si1554410pla.209.2023.07.27.11.06.26; Thu, 27 Jul 2023 11:06:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PSmn3vIH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229547AbjG0Rrg (ORCPT + 99 others); Thu, 27 Jul 2023 13:47:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229481AbjG0Rrf (ORCPT ); Thu, 27 Jul 2023 13:47:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 918C23582; Thu, 27 Jul 2023 10:47:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0B49A61EEE; Thu, 27 Jul 2023 17:47:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96556C433C8; Thu, 27 Jul 2023 17:47:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690480052; bh=8hhmn8+Ux+A5/8bfiHx76Y+Keb0yncfBW6JKFFqonaI=; h=From:To:Cc:Subject:Date:From; b=PSmn3vIHdcE4YAvK30kxOfH+NwljypVDfa1Y/IjWI/dbuMd3C6YC/siSK6lnFtTpE gHws0kigPY53o+U/hFangapFoH2jflVmFyuN7YAMaoSlHYLROupPXxYWn3Gw6xc4W2 eVKg3NYE7/jIkvU6lSugbZxMBFAfo5CA2Z6DyO8w8ja8rlq06BQXPp1i9N85fiJ+9x MayhU1yyZq0bKNmu4i2XQ4n6QJvT3bGbxZLW2kgCRSfz4MkhngfHUfu7rQsxP1fzqE HN3K4s6DkL9be5qiy8Wfw5UNRCcT9zVxD/nWarpKXEfBJv+RR4mKoDilXoYGwcIbb+ FzzIKDIUrrDhg== From: SeongJae Park To: stable@vger.kernel.org Cc: M A Ramdhan , gregkh@linuxfoundation.org, sashal@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, hailmo@amazon.com, Jamal Hadi Salim , Pedro Tammela , Jakub Kicinski , SeongJae Park Subject: [PATCH 4.14] net/sched: cls_fw: Fix improper refcount update leads to use-after-free Date: Thu, 27 Jul 2023 17:47:27 +0000 Message-Id: <20230727174727.55795-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772598016133881462 X-GMAIL-MSGID: 1772598016133881462 From: M A Ramdhan [ Upstream commit 0323bce598eea038714f941ce2b22541c46d488f ] In the event of a failure in tcf_change_indev(), fw_set_parms() will immediately return an error after incrementing or decrementing reference counter in tcf_bind_filter(). If attacker can control reference counter to zero and make reference freed, leading to use after free. In order to prevent this, move the point of possible failure above the point where the TC_FW_CLASSID is handled. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: M A Ramdhan Signed-off-by: M A Ramdhan Acked-by: Jamal Hadi Salim Reviewed-by: Pedro Tammela Message-ID: <20230705161530.52003-1-ramdhan@starlabs.sg> Signed-off-by: Jakub Kicinski Signed-off-by: SeongJae Park --- net/sched/cls_fw.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/sched/cls_fw.c b/net/sched/cls_fw.c index 7f45e5ab8afcd..e63f9c2e37e50 100644 --- a/net/sched/cls_fw.c +++ b/net/sched/cls_fw.c @@ -225,11 +225,6 @@ static int fw_set_parms(struct net *net, struct tcf_proto *tp, if (err < 0) return err; - if (tb[TCA_FW_CLASSID]) { - f->res.classid = nla_get_u32(tb[TCA_FW_CLASSID]); - tcf_bind_filter(tp, &f->res, base); - } - #ifdef CONFIG_NET_CLS_IND if (tb[TCA_FW_INDEV]) { int ret; @@ -248,6 +243,11 @@ static int fw_set_parms(struct net *net, struct tcf_proto *tp, } else if (head->mask != 0xFFFFFFFF) return err; + if (tb[TCA_FW_CLASSID]) { + f->res.classid = nla_get_u32(tb[TCA_FW_CLASSID]); + tcf_bind_filter(tp, &f->res, base); + } + return 0; }