Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp829726rwd; Thu, 1 Jun 2023 07:08:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ50VolwQfHAvuxHdgOnlEfDDmTrd9fZjZW1U/B8wDnCcdwFnngAztynw6bXiWLGasQJMqAK X-Received: by 2002:a17:90b:1d85:b0:255:3f6f:2c6 with SMTP id pf5-20020a17090b1d8500b002553f6f02c6mr7980994pjb.22.1685628493969; Thu, 01 Jun 2023 07:08:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685628493; cv=none; d=google.com; s=arc-20160816; b=CQUZLpAvm0HEuvyipNAXcjNKQwd0G+FjV70GAYJtF2zWnrOW9lqDWOgmy/SsoA+swg 4lLZivTQemdZ3kVJuZbXRUv0XICH21AwE+J+tvg9jEEQraGw7bD+c294iZ6/K16tGgPq GLLzTxfIhcD4s8pkHiXSGjrXQH1hAOFj+11bOUQVNsZf2NYHvsTES6bx+R3DJt6kIHHR 4f8+fKrNW+64qubihwDNEISpa4EVYBOYj+r7MO/MGEjOh/Eg2z6ERNMh10jzaTSXMtzQ Ik337KrSfOZkFAR9uSGiqjKMG2Rtu6N8FA4YDrPBjgVdvST5AB7GqV8s3rz1Q9Kb19LG YZ3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=skGIOiovoAINBES9Lx9Yv142DT49P+CdnCRlglmWkYg=; b=YI/Jnn/wqOm3MGzbpCB/sH13ji8VMELClF8u5FWbPttUZpjjMHAZ8Q9tDm9FbhvgnD 2aXzO0rLiqm8DvACQSnvnf+Obd0k7IQc8j5isoUqFmttSITMULntxAi4Rq/agCtk+5bD tXbRh2Vp6LDunJm1rm0kb4HaiSq/7S/WGGu2dqEBxLNV8pp05/0F4QT42ogHTELAxdyN qhDaZAL9WntGaxG95IbTA+hdWZrPMCB6QksgDvzqYiPOo3C1u9qF+z0X9GW0NoNaViLb prqeX4Tc5F3U2QoCSWivfs7YZL5uAUS+oaV2cLYYPXIaC1lOWeJprqimaGUwRtmWA7Sl K5eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=l7jX3PMg; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i13-20020a17090a64cd00b002472cd8ded6si1174431pjm.103.2023.06.01.07.08.00; Thu, 01 Jun 2023 07:08:13 -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=l7jX3PMg; 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 S233606AbjFAOGx (ORCPT + 99 others); Thu, 1 Jun 2023 10:06:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233607AbjFAOGt (ORCPT ); Thu, 1 Jun 2023 10:06:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E3A0189 for ; Thu, 1 Jun 2023 07:06:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0AA3164571 for ; Thu, 1 Jun 2023 14:06:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DA87C4339B; Thu, 1 Jun 2023 14:06:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685628406; bh=jo+kQRmaMsGk8ilFDIPDe218c8Tetx9OvbItrHEqoYE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=l7jX3PMgpRa2WwIfC0tf5h8YCO3IO9p9e/4e8d8da94t0pAlDlQzhZbrmZvAS4OVt jKJGsiItamIF78bDAdpNSxVF/uFzsxc23LkOb1Nkzq/7Hgnkuo0LJT7SYxUSE93L0Y vuRpWEFlFBxrRwQcDBb8Mtu5N8FpvHJFbPt5CZZw0YATtIzFB8+X48XLITlt19lFuU PHDnKzvz38VWHDHPYWKtkv4zy4dppE5MgVVnw0Sn0tGaF8rT3wRHluNTEwmaVPQ1tC 0YicaiD+JNkUSIm3X5rmcaw5Tnp16fWZw8Tdtiy6KkBbsGW6eoW3jZcVq3kd3Pvvqn xY5yRd6zi5Ylg== Date: Thu, 1 Jun 2023 15:06:40 +0100 From: Lee Jones To: Jamal Hadi Salim , Eric Dumazet Cc: Eric Dumazet , xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, stable@kernel.org Subject: Re: [PATCH 1/1] net/sched: cls_u32: Fix reference counter leak leading to overflow Message-ID: <20230601140640.GG449117@google.com> References: <20230531141556.1637341-1-lee@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 On Wed, 31 May 2023, Jamal Hadi Salim wrote: > On Wed, May 31, 2023 at 11:03 AM Eric Dumazet wrote: > > > > On Wed, May 31, 2023 at 4:16 PM Lee Jones wrote: > > > > > > In the event of a failure in tcf_change_indev(), u32_set_parms() will > > > immediately return without decrementing the recently incremented > > > reference counter. If this happens enough times, the counter will > > > rollover and the reference freed, leading to a double free which can be > > > used to do 'bad things'. > > > > > > Cc: stable@kernel.org # v4.14+ > > > > Please add a Fixes: tag. Why? From memory, I couldn't identify a specific commit to fix, which is why I used a Cc tag as per the Stable documentation: Option 1 ******** To have the patch automatically included in the stable tree, add the tag .. code-block:: none Cc: stable@vger.kernel.org in the sign-off area. Once the patch is merged it will be applied to the stable tree without anything else needing to be done by the author or subsystem maintainer. > > > Signed-off-by: Lee Jones > > > --- > > > net/sched/cls_u32.c | 5 ++++- > > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > > > diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c > > > index 4e2e269f121f8..fad61ca5e90bf 100644 > > > --- a/net/sched/cls_u32.c > > > +++ b/net/sched/cls_u32.c > > > @@ -762,8 +762,11 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp, > > > if (tb[TCA_U32_INDEV]) { > > > int ret; > > > ret = tcf_change_indev(net, tb[TCA_U32_INDEV], extack); > > > > This call should probably be done earlier in the function, next to > > tcf_exts_validate_ex() > > > > Otherwise we might ask why the tcf_bind_filter() does not need to be undone. > > > > Something like: > > > > diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c > > index 4e2e269f121f8a301368b9783753e055f5af6a4e..ac957ff2216ae18bcabdd3af3b0e127447ef8f91 > > 100644 > > --- a/net/sched/cls_u32.c > > +++ b/net/sched/cls_u32.c > > @@ -718,13 +718,18 @@ static int u32_set_parms(struct net *net, struct > > tcf_proto *tp, > > struct nlattr *est, u32 flags, u32 fl_flags, > > struct netlink_ext_ack *extack) > > { > > - int err; > > + int err, ifindex = -1; > > > > err = tcf_exts_validate_ex(net, tp, tb, est, &n->exts, flags, > > fl_flags, extack); > > if (err < 0) > > return err; > > > > + if (tb[TCA_U32_INDEV]) { > > + ifindex = tcf_change_indev(net, tb[TCA_U32_INDEV], extack); > > + if (ifindex < 0) > > + return -EINVAL; > > + } Thanks for the advice. Leave it with me. > > if (tb[TCA_U32_LINK]) { > > u32 handle = nla_get_u32(tb[TCA_U32_LINK]); > > struct tc_u_hnode *ht_down = NULL, *ht_old; > > @@ -759,13 +764,9 @@ static int u32_set_parms(struct net *net, struct > > tcf_proto *tp, > > tcf_bind_filter(tp, &n->res, base); > > } > > > > - if (tb[TCA_U32_INDEV]) { > > - int ret; > > - ret = tcf_change_indev(net, tb[TCA_U32_INDEV], extack); > > - if (ret < 0) > > - return -EINVAL; > > - n->ifindex = ret; > > - } > > + if (ifindex >= 0) > > + n->ifindex = ifindex; > > + > > I guess we crossed paths ;-> > Please, add a tdc test as well - it doesnt have to be in this patch, > can be a followup. I don't know how to do that, or even what a 'tdc' is. Is it trivial? Can you point me towards the documentation please? -- Lee Jones [李琼斯]