Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1622802

Re: [PATCH linux 2/2] net sched actions: fix refcount decrement on error

From Wolfgang Bumiller <w.bumiller@proxmox.com>
Newsgroups linux.kernel
Subject Re: [PATCH linux 2/2] net sched actions: fix refcount decrement on error
Date 2017-04-13 10:10 +0200
Message-ID <tvHZf-89-11@gated-at.bofh.it> (permalink)
References <tvrB8-5Bn-13@gated-at.bofh.it> <tvrB9-5Bn-35@gated-at.bofh.it> <tvEyl-62y-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, Apr 12, 2017 at 09:27:31PM -0700, Cong Wang wrote:
> On Wed, Apr 12, 2017 at 7:21 AM, Wolfgang Bumiller
> <w.bumiller@proxmox.com> wrote:
> > If memory allocation for nla_memdup_cookie() fails
> > module_put has to be guarded by the same condition as it was
> > before the TCA_ACT_COOKIE has been added as stated in the
> > comment afterwards:
> >
> > /* module count goes up only when brand new policy is created
> >  * if it exists and is only bound to in a_o->init() then
> >  * ACT_P_CREATED is not returned (a zero is).
> >  */
> 
> Yeah, this patch makes sense for me too. Just one comment below.
> 
> >
> > Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
> > ---
> >
> > Note that I'm unsure about this patch. The hangups weren't very reliable
> > and I couldn't actually reproduce them when building from git/master (as
> > I can only test a fraction of my usual workload with it as a lot of my
> > data (VMs & containers utilizing veths and tap devices) is on ZFS...).
> > In any case it can't harm to take another look at the error handling
> > here.
> >
> >  net/sched/act_api.c | 12 ++++++++----
> >  1 file changed, 8 insertions(+), 4 deletions(-)
> >
> > diff --git a/net/sched/act_api.c b/net/sched/act_api.c
> > index 8cc883c063f0..795ac092b723 100644
> > --- a/net/sched/act_api.c
> > +++ b/net/sched/act_api.c
> > @@ -608,15 +608,19 @@ struct tc_action *tcf_action_init_1(struct net *net, struct nlattr *nla,
> >                 int cklen = nla_len(tb[TCA_ACT_COOKIE]);
> >
> >                 if (cklen > TC_COOKIE_MAX_SIZE) {
> > -                       err = -EINVAL;
> >                         tcf_hash_release(a, bind);
> > -                       goto err_mod;
> > +                       if (err != ACT_P_CREATED)
> > +                               module_put(a_o->owner);
> > +                       err = -EINVAL;
> > +                       goto err_out;
> >                 }
> >
> >                 if (nla_memdup_cookie(a, tb) < 0) {
> > -                       err = -ENOMEM;
> >                         tcf_hash_release(a, bind);
> > -                       goto err_mod;
> > +                       if (err != ACT_P_CREATED)
> > +                               module_put(a_o->owner);
> > +                       err = -ENOMEM;
> > +                       goto err_out;
> 
> Instead of duplicating code, you can add the check
> to the module_put() next to err_mod label? I mean:

I just realized that with module_put() happening in both error and
success cases if `err != ACT_P_CREATED`, we could just move that code up
to above the TCA_ACT_COOKIE handling?
Btw., the comment confused me a little at first as I thought it's about
what happens in ->init(). But reading the code I then noticed the module
count is increased in tc_lookup_action_n() (which calls try_module_get)
in this functions and it's about how this function itself is supposed
to affect the count - if I'm not mistaken.
=> so I think it makes sense to deal with this earlier.

Otherwise I'd have to save `err != ACT_P_CREATED` in an additional
variable for the err_mod case since the cookie handling modifies `err`.

What about this? (Since it's a separate issue not directly related to
patch 1 of the series I can send it as separate mail based on master if
you prefer - the diff below is based on master+patch1 for now.)

-- 8< --
Subject: [PATCH net v2] net sched actions: decrement module refcount earlier

Whether the reference count has to be decremented depends
on whether the policy was created. If TCA_ACT_COOKIE is
passed and an error occurs there, the same condition still
has to be honored.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
---
 net/sched/act_api.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/net/sched/act_api.c b/net/sched/act_api.c
index 8cc883c063f0..7d920ef83a07 100644
--- a/net/sched/act_api.c
+++ b/net/sched/act_api.c
@@ -604,28 +604,29 @@ struct tc_action *tcf_action_init_1(struct net *net, struct nlattr *nla,
 	if (err < 0)
 		goto err_mod;
 
+	/* module count goes up only when brand new policy is created
+	 * if it exists and is only bound to in a_o->init() then
+	 * ACT_P_CREATED is not returned (a zero is).
+	 */
+	if (err != ACT_P_CREATED)
+		module_put(a_o->owner);
+
 	if (name == NULL && tb[TCA_ACT_COOKIE]) {
 		int cklen = nla_len(tb[TCA_ACT_COOKIE]);
 
 		if (cklen > TC_COOKIE_MAX_SIZE) {
 			err = -EINVAL;
 			tcf_hash_release(a, bind);
-			goto err_mod;
+			goto err_out;
 		}
 
 		if (nla_memdup_cookie(a, tb) < 0) {
 			err = -ENOMEM;
 			tcf_hash_release(a, bind);
-			goto err_mod;
+			goto err_out;
 		}
 	}
 
-	/* module count goes up only when brand new policy is created
-	 * if it exists and is only bound to in a_o->init() then
-	 * ACT_P_CREATED is not returned (a zero is).
-	 */
-	if (err != ACT_P_CREATED)
-		module_put(a_o->owner);
 
 	return a;
 
-- 
2.11.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC PATCH linux 0/2] net sched actions: access to uninitialized data and error handling Wolfgang Bumiller <w.bumiller@proxmox.com> - 2017-04-12 16:40 +0200
  [PATCH linux 2/2] net sched actions: fix refcount decrement on error Wolfgang Bumiller <w.bumiller@proxmox.com> - 2017-04-12 16:40 +0200
    Re: [PATCH linux 2/2] net sched actions: fix refcount decrement on error Cong Wang <xiyou.wangcong@gmail.com> - 2017-04-13 06:30 +0200
      Re: [PATCH linux 2/2] net sched actions: fix refcount decrement on  error Wolfgang Bumiller <w.bumiller@proxmox.com> - 2017-04-13 10:10 +0200
        Re: [PATCH linux 2/2] net sched actions: fix refcount decrement on error Cong Wang <xiyou.wangcong@gmail.com> - 2017-04-13 20:10 +0200
          Re: [PATCH linux 2/2] net sched actions: fix refcount decrement on  error Wolfgang Bumiller <w.bumiller@proxmox.com> - 2017-04-14 11:10 +0200
            Re: [PATCH linux 2/2] net sched actions: fix refcount decrement on error Cong Wang <xiyou.wangcong@gmail.com> - 2017-04-15 20:30 +0200
              Re: [PATCH linux 2/2] net sched actions: fix refcount decrement on  error Wolfgang Bumiller <w.bumiller@proxmox.com> - 2017-04-15 20:50 +0200
                Re: [PATCH linux 2/2] net sched actions: fix refcount decrement on error Cong Wang <xiyou.wangcong@gmail.com> - 2017-04-17 20:20 +0200
    Re: [PATCH linux 2/2] net sched actions: fix refcount decrement on error Roman Mashak <mrv@mojatatu.com> - 2017-04-13 15:50 +0200
  Re: [RFC PATCH linux 0/2] net sched actions: access to uninitialized  data and error handling Cong Wang <xiyou.wangcong@gmail.com> - 2017-04-13 03:30 +0200
  Re: [RFC PATCH linux 0/2] net sched actions: access to  uninitialized data and error handling David Miller <davem@davemloft.net> - 2017-04-17 17:10 +0200

csiph-web