Message ID | 20230420175952.1114302-1-ivecera@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp524091vqo; Thu, 20 Apr 2023 11:11:00 -0700 (PDT) X-Google-Smtp-Source: AKy350bciqO0OoRbuXGUwxaWkcDsdnzly/AY9LpX3cuai/R2gW0/MSOkVFTEuoqk6XhvPxPmvRxk X-Received: by 2002:a05:6a20:1443:b0:f0:827f:4aff with SMTP id a3-20020a056a20144300b000f0827f4affmr3648729pzi.0.1682014260157; Thu, 20 Apr 2023 11:11:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682014260; cv=none; d=google.com; s=arc-20160816; b=a22T38C5UWIl2V8UnOsYYtU1dxtdLwxYmfeDydv1aAg2epCXqqqlgRWprHxGIVy7hE WR2yDcE0qVsPTCo09bWv7qLQhygiz15Xthik3S/UKfS+ua8cJ4koSn9dwsNC2a1359Co bKxGSyzy/ZxDgEZwOI6n9EC+BbkgBzhrjTsLo9AwPy+VgoSHoH8ykouSbuQBnIhugLPn OXO5dO9VXRSSz5Jyknn36dR3FZlC1lwDdPKFyF72LXHNfL3+Nc0nuY/C7L+yM5eUPLSW R01wzdCDdx7qtR8YobQuw1AUqRisxbi4pfujR2ttGrPl8hQZWjhbDmjtB2lWutrPL1FN qSuw== 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=sYEObKgK9ZsZ163F+qEC5kfelVhULo1SPruXGXXCNIM=; b=YiDc4CA1nlqdVNO2e2E3LtJaG9H4TELG84kinKlaB/p60WWTgRxG41Wxbsm4kA+RsD zllh4ztDyr4TLYz3QWXCyqCMxDaWvLW/ko6pxNJCmCvfPAdlZ51i5FPts6f+p6Bav/UR djcY6pzH+S+IVsHb2PfHf1zidfJIgj3VuZFv4/8SKZzeKdOFCur7yrQe8PUkIq/mY3YD ETq53IhZ2Nr7YM5Xrps5QqUczAC+yceG95+1AmLaV+ZnIDt4L8cEN8HBazwOGyvoQrj1 WPRXJ1YZs1ZeUWoodTLUvNFR+cpc4RzOc+eapl3lpSLB5q63V3gcLxybIAWZQqpxDyuT Ifqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S1UyZXQB; 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=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b13-20020aa78ecd000000b0063d27f81f05si2152506pfr.247.2023.04.20.11.10.44; Thu, 20 Apr 2023 11:11:00 -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=@redhat.com header.s=mimecast20190719 header.b=S1UyZXQB; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231572AbjDTSAv (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Thu, 20 Apr 2023 14:00:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230003AbjDTSAr (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 20 Apr 2023 14:00:47 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6736619A1 for <linux-kernel@vger.kernel.org>; Thu, 20 Apr 2023 11:00:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682013600; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=sYEObKgK9ZsZ163F+qEC5kfelVhULo1SPruXGXXCNIM=; b=S1UyZXQB275FUujSVHefBnZh2PBWZq0VMychvml5fVcj/YUr7k64RHpdBdMSpHXsZ//8Gv zD+hQeat5uRl6rROVmozo1BnFHwkJfbzBL0+Ase7AaMcT5DaTSevoo6o8PxJR34Iy2w5qT NWZcRO0oFnoQTYX+SHdmh5oNwR4ZJXI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-248-ea5QQMH0NwaenUbQ9iTEtg-1; Thu, 20 Apr 2023 13:59:56 -0400 X-MC-Unique: ea5QQMH0NwaenUbQ9iTEtg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B227296A605; Thu, 20 Apr 2023 17:59:55 +0000 (UTC) Received: from p1.luc.cera.cz (unknown [10.45.226.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A6241410F1C; Thu, 20 Apr 2023 17:59:53 +0000 (UTC) From: Ivan Vecera <ivecera@redhat.com> To: netdev@vger.kernel.org Cc: Jamal Hadi Salim <jhs@mojatatu.com>, Cong Wang <xiyou.wangcong@gmail.com>, Jiri Pirko <jiri@resnulli.us>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Paul Blakey <paulb@nvidia.com>, Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>, linux-kernel@vger.kernel.org (open list) Subject: [PATCH net] net/sched: cls_api: Initialize miss_cookie_node when action miss is not used Date: Thu, 20 Apr 2023 19:59:52 +0200 Message-Id: <20230420175952.1114302-1-ivecera@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763719784420472786?= X-GMAIL-MSGID: =?utf-8?q?1763719784420472786?= |
Series |
[net] net/sched: cls_api: Initialize miss_cookie_node when action miss is not used
|
|
Commit Message
Ivan Vecera
April 20, 2023, 5:59 p.m. UTC
Function tcf_exts_init_ex() sets exts->miss_cookie_node ptr only
when use_action_miss is true so it assumes in other case that
the field is set to NULL by the caller. If not then the field
contains garbage and subsequent tcf_exts_destroy() call results
in a crash.
Initialize .miss_cookie_node pointer to NULL when use_action_miss
parameter is false to avoid this potential scenario.
Fixes: 80cd22c35c90 ("net/sched: cls_api: Support hardware miss to tc action")
Signed-off-by: Ivan Vecera <ivecera@redhat.com>
---
net/sched/cls_api.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
Comments
On 20/04/2023 14:59, Ivan Vecera wrote: > Function tcf_exts_init_ex() sets exts->miss_cookie_node ptr only > when use_action_miss is true so it assumes in other case that > the field is set to NULL by the caller. If not then the field > contains garbage and subsequent tcf_exts_destroy() call results > in a crash. > Initialize .miss_cookie_node pointer to NULL when use_action_miss > parameter is false to avoid this potential scenario. > > Fixes: 80cd22c35c90 ("net/sched: cls_api: Support hardware miss to tc action") > Signed-off-by: Ivan Vecera <ivecera@redhat.com> > --- > net/sched/cls_api.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c > index 35785a36c80298..8bc5b9d6a2916e 100644 > --- a/net/sched/cls_api.c > +++ b/net/sched/cls_api.c > @@ -3224,8 +3224,12 @@ int tcf_exts_init_ex(struct tcf_exts *exts, struct net *net, int action, > exts->action = action; > exts->police = police; > > - if (!use_action_miss) > + if (!use_action_miss) { > +#ifdef CONFIG_NET_CLS_ACT > + exts->miss_cookie_node = NULL; > +#endif > return 0; > + } > > err = tcf_exts_miss_cookie_base_alloc(exts, tp, handle); > if (err) The problem described here also happens in the case some error happens if the action array allocation fails and before the 'miss_cookie_node' assignment inside 'tcf_exts_miss_cookie_base_alloc()'. Seems like a better way to solve this issue is to just: diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index 35785a36c802..3c3629c9e7b6 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -3211,6 +3211,7 @@ int tcf_exts_init_ex(struct tcf_exts *exts, struct net *net, int action, #ifdef CONFIG_NET_CLS_ACT exts->type = 0; exts->nr_actions = 0; + exts->miss_cookie_node = NULL; /* Note: we do not own yet a reference on net. * This reference might be taken later from tcf_exts_get_net(). */
On 20. 04. 23 20:21, Pedro Tammela wrote: > On 20/04/2023 14:59, Ivan Vecera wrote: >> Function tcf_exts_init_ex() sets exts->miss_cookie_node ptr only >> when use_action_miss is true so it assumes in other case that >> the field is set to NULL by the caller. If not then the field >> contains garbage and subsequent tcf_exts_destroy() call results >> in a crash. >> Initialize .miss_cookie_node pointer to NULL when use_action_miss >> parameter is false to avoid this potential scenario. >> >> Fixes: 80cd22c35c90 ("net/sched: cls_api: Support hardware miss to tc >> action") >> Signed-off-by: Ivan Vecera <ivecera@redhat.com> >> --- >> net/sched/cls_api.c | 6 +++++- >> 1 file changed, 5 insertions(+), 1 deletion(-) >> >> diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c >> index 35785a36c80298..8bc5b9d6a2916e 100644 >> --- a/net/sched/cls_api.c >> +++ b/net/sched/cls_api.c >> @@ -3224,8 +3224,12 @@ int tcf_exts_init_ex(struct tcf_exts *exts, >> struct net *net, int action, >> exts->action = action; >> exts->police = police; >> - if (!use_action_miss) >> + if (!use_action_miss) { >> +#ifdef CONFIG_NET_CLS_ACT >> + exts->miss_cookie_node = NULL; >> +#endif >> return 0; >> + } >> err = tcf_exts_miss_cookie_base_alloc(exts, tp, handle); >> if (err) > > The problem described here also happens in the case some error happens > if the action array allocation fails and before the 'miss_cookie_node' > assignment inside 'tcf_exts_miss_cookie_base_alloc()'. > > Seems like a better way to solve this issue is to just: > diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c > index 35785a36c802..3c3629c9e7b6 100644 > --- a/net/sched/cls_api.c > +++ b/net/sched/cls_api.c > @@ -3211,6 +3211,7 @@ int tcf_exts_init_ex(struct tcf_exts *exts, struct > net *net, int action, > #ifdef CONFIG_NET_CLS_ACT > exts->type = 0; > exts->nr_actions = 0; > + exts->miss_cookie_node = NULL; > /* Note: we do not own yet a reference on net. > * This reference might be taken later from tcf_exts_get_net(). > */ Looks better, will repost... Thanks Ivan
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index 35785a36c80298..8bc5b9d6a2916e 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -3224,8 +3224,12 @@ int tcf_exts_init_ex(struct tcf_exts *exts, struct net *net, int action, exts->action = action; exts->police = police; - if (!use_action_miss) + if (!use_action_miss) { +#ifdef CONFIG_NET_CLS_ACT + exts->miss_cookie_node = NULL; +#endif return 0; + } err = tcf_exts_miss_cookie_base_alloc(exts, tp, handle); if (err)