netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Jamie Iles <jamie@nuviainc.com>, Eric Dumazet <eric.dumazet@gmail.com>
Cc: netdev@vger.kernel.org, Qiushi Wu <wu000273@umn.edu>,
	Jay Vosburgh <j.vosburgh@gmail.com>,
	Veaceslav Falico <vfalico@gmail.com>,
	Andy Gospodarek <andy@greyhouse.net>
Subject: Re: [RESEND PATCH] bonding: wait for sysfs kobject destruction before freeing struct slave
Date: Fri, 6 Nov 2020 17:17:12 +0100	[thread overview]
Message-ID: <d4b96330-4ee1-6393-1096-03a06abd3889@gmail.com> (raw)
In-Reply-To: <20201105181108.GA2360@poplar>



On 11/5/20 7:11 PM, Jamie Iles wrote:
> Hi Eric,
> 
> On Thu, Nov 05, 2020 at 01:49:03PM +0100, Eric Dumazet wrote:
>> On 11/5/20 9:41 AM, Jamie Iles wrote:
>>> syzkaller found that with CONFIG_DEBUG_KOBJECT_RELEASE=y, releasing a
>>> struct slave device could result in the following splat:
>>>
>>>
>>
>>> This is a potential use-after-free if the sysfs nodes are being accessed
>>> whilst removing the struct slave, so wait for the object destruction to
>>> complete before freeing the struct slave itself.
>>>
>>> Fixes: 07699f9a7c8d ("bonding: add sysfs /slave dir for bond slave devices.")
>>> Fixes: a068aab42258 ("bonding: Fix reference count leak in bond_sysfs_slave_add.")
>>> Cc: Qiushi Wu <wu000273@umn.edu>
>>> Cc: Jay Vosburgh <j.vosburgh@gmail.com>
>>> Cc: Veaceslav Falico <vfalico@gmail.com>
>>> Cc: Andy Gospodarek <andy@greyhouse.net>
>>> Signed-off-by: Jamie Iles <jamie@nuviainc.com>
>>> ---
> ...
>> This seems weird, are we going to wait for a completion while RTNL is held ?
>> I am pretty sure this could be exploited by malicious user/syzbot.
>>
>> The .release() handler could instead perform a refcounted
>> bond_free_slave() action.
> 
> Okay, so were you thinking along the lines of this moving the lifetime 
> of the slave to the kobject?
> 

This seems a bit too complex for a bug fix.

Instead of adding a completion, you could add a refcount_t, and
make bond_free_slave() a wrapper like

static inline void bond_free_slave(struct slave *slave)
{
   if (refcount_dec_and_test(&slave->refcnt))
       __bond_free_slave(slave);
}

Once the kobj is successfully activated, you would
need a refcount_inc(&slave->refcount);

Total patch would be smaller and easier to review.

The kobj .release handler would simply call bond_free_slave(slave);




  reply	other threads:[~2020-11-06 16:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-05  8:41 [RESEND PATCH] bonding: wait for sysfs kobject destruction before freeing struct slave Jamie Iles
2020-11-05 12:49 ` Eric Dumazet
2020-11-05 18:11   ` Jamie Iles
2020-11-06 16:17     ` Eric Dumazet [this message]
2020-11-13 17:12       ` [PATCHv2] " Jamie Iles
2020-11-17 20:34         ` Jakub Kicinski
2020-11-18  7:58           ` Greg Kroah-Hartman
2020-11-20 14:28         ` [PATCHv3] " Jamie Iles
2020-11-20 15:39           ` Greg Kroah-Hartman
2020-11-21 21:09             ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d4b96330-4ee1-6393-1096-03a06abd3889@gmail.com \
    --to=eric.dumazet@gmail.com \
    --cc=andy@greyhouse.net \
    --cc=j.vosburgh@gmail.com \
    --cc=jamie@nuviainc.com \
    --cc=netdev@vger.kernel.org \
    --cc=vfalico@gmail.com \
    --cc=wu000273@umn.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).