hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/sched/cls_route.c
....@@ -1,10 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * net/sched/cls_route.c ROUTE4 classifier.
3
- *
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License
6
- * as published by the Free Software Foundation; either version
7
- * 2 of the License, or (at your option) any later version.
84 *
95 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
106 */
....@@ -276,7 +272,8 @@
276272 tcf_queue_work(&f->rwork, route4_delete_filter_work);
277273 }
278274
279
-static void route4_destroy(struct tcf_proto *tp, struct netlink_ext_ack *extack)
275
+static void route4_destroy(struct tcf_proto *tp, bool rtnl_held,
276
+ struct netlink_ext_ack *extack)
280277 {
281278 struct route4_head *head = rtnl_dereference(tp->root);
282279 int h1, h2;
....@@ -312,7 +309,7 @@
312309 }
313310
314311 static int route4_delete(struct tcf_proto *tp, void *arg, bool *last,
315
- struct netlink_ext_ack *extack)
312
+ bool rtnl_held, struct netlink_ext_ack *extack)
316313 {
317314 struct route4_head *head = rtnl_dereference(tp->root);
318315 struct route4_filter *f = arg;
....@@ -393,7 +390,7 @@
393390 struct route4_bucket *b;
394391 int err;
395392
396
- err = tcf_exts_validate(net, tp, tb, est, &f->exts, ovr, extack);
393
+ err = tcf_exts_validate(net, tp, tb, est, &f->exts, ovr, true, extack);
397394 if (err < 0)
398395 return err;
399396
....@@ -425,6 +422,11 @@
425422 nhandle |= handle & 0x7F00;
426423 if (nhandle != handle)
427424 return -EINVAL;
425
+ }
426
+
427
+ if (!nhandle) {
428
+ NL_SET_ERR_MSG(extack, "Replacing with handle of 0 is invalid");
429
+ return -EINVAL;
428430 }
429431
430432 h1 = to_hash(nhandle);
....@@ -468,7 +470,7 @@
468470 static int route4_change(struct net *net, struct sk_buff *in_skb,
469471 struct tcf_proto *tp, unsigned long base, u32 handle,
470472 struct nlattr **tca, void **arg, bool ovr,
471
- struct netlink_ext_ack *extack)
473
+ bool rtnl_held, struct netlink_ext_ack *extack)
472474 {
473475 struct route4_head *head = rtnl_dereference(tp->root);
474476 struct route4_filter __rcu **fp;
....@@ -480,10 +482,16 @@
480482 int err;
481483 bool new = true;
482484
485
+ if (!handle) {
486
+ NL_SET_ERR_MSG(extack, "Creating with handle of 0 is invalid");
487
+ return -EINVAL;
488
+ }
489
+
483490 if (opt == NULL)
484491 return handle ? -EINVAL : 0;
485492
486
- err = nla_parse_nested(tb, TCA_ROUTE4_MAX, opt, route4_policy, NULL);
493
+ err = nla_parse_nested_deprecated(tb, TCA_ROUTE4_MAX, opt,
494
+ route4_policy, NULL);
487495 if (err < 0)
488496 return err;
489497
....@@ -496,14 +504,13 @@
496504 if (!f)
497505 goto errout;
498506
499
- err = tcf_exts_init(&f->exts, TCA_ROUTE4_ACT, TCA_ROUTE4_POLICE);
507
+ err = tcf_exts_init(&f->exts, net, TCA_ROUTE4_ACT, TCA_ROUTE4_POLICE);
500508 if (err < 0)
501509 goto errout;
502510
503511 if (fold) {
504512 f->id = fold->id;
505513 f->iif = fold->iif;
506
- f->res = fold->res;
507514 f->handle = fold->handle;
508515
509516 f->tp = fold->tp;
....@@ -528,7 +535,7 @@
528535 rcu_assign_pointer(f->next, f1);
529536 rcu_assign_pointer(*fp, f);
530537
531
- if (fold && fold->handle && f->handle != fold->handle) {
538
+ if (fold) {
532539 th = to_hash(fold->handle);
533540 h = from_hash(fold->handle >> 16);
534541 b = rtnl_dereference(head->table[th]);
....@@ -560,15 +567,13 @@
560567 return err;
561568 }
562569
563
-static void route4_walk(struct tcf_proto *tp, struct tcf_walker *arg)
570
+static void route4_walk(struct tcf_proto *tp, struct tcf_walker *arg,
571
+ bool rtnl_held)
564572 {
565573 struct route4_head *head = rtnl_dereference(tp->root);
566574 unsigned int h, h1;
567575
568
- if (head == NULL)
569
- arg->stop = 1;
570
-
571
- if (arg->stop)
576
+ if (head == NULL || arg->stop)
572577 return;
573578
574579 for (h = 0; h <= 256; h++) {
....@@ -597,7 +602,7 @@
597602 }
598603
599604 static int route4_dump(struct net *net, struct tcf_proto *tp, void *fh,
600
- struct sk_buff *skb, struct tcmsg *t)
605
+ struct sk_buff *skb, struct tcmsg *t, bool rtnl_held)
601606 {
602607 struct route4_filter *f = fh;
603608 struct nlattr *nest;
....@@ -608,7 +613,7 @@
608613
609614 t->tcm_handle = f->handle;
610615
611
- nest = nla_nest_start(skb, TCA_OPTIONS);
616
+ nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
612617 if (nest == NULL)
613618 goto nla_put_failure;
614619