Linux block layer
 help / color / mirror / Atom feed
From: lyl2019@mail.ustc.edu.cn
To: lyl2019@mail.ustc.edu.cn
Cc: "Christoph Böhmwalder" <christoph.boehmwalder@linbit.com>,
	philipp.reisner@linbit.com, lars.ellenberg@linbit.com,
	axboe@kernel.dk, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, drbd-dev@lists.linbit.com
Subject: Re: Re: Re: [Drbd-dev] [PATCH] drbd: Fix a use after free in get_initial_state
Date: Thu, 1 Apr 2021 23:17:27 +0800 (GMT+08:00)	[thread overview]
Message-ID: <17336352.26b99.1788e02bf3d.Coremail.lyl2019@mail.ustc.edu.cn> (raw)
In-Reply-To: <5b14fa53.26b7e.1788dff8d13.Coremail.lyl2019@mail.ustc.edu.cn>




> -----原始邮件-----
> 发件人: lyl2019@mail.ustc.edu.cn
> 发送时间: 2021-04-01 23:13:58 (星期四)
> 收件人: "Christoph Böhmwalder" <christoph.boehmwalder@linbit.com>
> 抄送: philipp.reisner@linbit.com, lars.ellenberg@linbit.com, axboe@kernel.dk, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, drbd-dev@lists.linbit.com
> 主题: Re: Re: [Drbd-dev] [PATCH] drbd: Fix a use after free in get_initial_state
> 
> 
> 
> 
> > -----原始邮件-----
> > 发件人: "Christoph Böhmwalder" <christoph.boehmwalder@linbit.com>
> > 发送时间: 2021-04-01 21:01:20 (星期四)
> > 收件人: "Lv Yunlong" <lyl2019@mail.ustc.edu.cn>
> > 抄送: philipp.reisner@linbit.com, lars.ellenberg@linbit.com, axboe@kernel.dk, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, drbd-dev@lists.linbit.com
> > 主题: Re: [Drbd-dev] [PATCH] drbd: Fix a use after free in get_initial_state
> > 
> > On 4/1/21 1:57 PM, Lv Yunlong wrote:
> > > In get_initial_state, it calls notify_initial_state_done(skb,..) if
> > > cb->args[5]==1. I see that if genlmsg_put() failed in
> > > notify_initial_state_done(), the skb will be freed by nlmsg_free(skb).
> > > Then get_initial_state will goto out and the freed skb will be used by
> > > return value skb->len.
> > > 
> > > My patch lets skb_len = skb->len and return the skb_len to avoid the uaf.
> > > 
> > > Fixes: a29728463b254 ("drbd: Backport the "events2" command")
> > > Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
> > > ---
> > >   drivers/block/drbd/drbd_nl.c | 3 ++-
> > >   1 file changed, 2 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
> > > index bf7de4c7b96c..474f84675d0a 100644
> > > --- a/drivers/block/drbd/drbd_nl.c
> > > +++ b/drivers/block/drbd/drbd_nl.c
> > > @@ -4905,6 +4905,7 @@ static int get_initial_state(struct sk_buff *skb, struct netlink_callback *cb)
> > >   	struct drbd_state_change *state_change = (struct drbd_state_change *)cb->args[0];
> > >   	unsigned int seq = cb->args[2];
> > >   	unsigned int n;
> > > +	unsigned int skb_len = skb->len;
> > >   	enum drbd_notification_type flags = 0;
> > >   
> > >   	/* There is no need for taking notification_mutex here: it doesn't
> > > @@ -4915,7 +4916,7 @@ static int get_initial_state(struct sk_buff *skb, struct netlink_callback *cb)
> > >   	cb->args[5]--;
> > >   	if (cb->args[5] == 1) {
> > >   		notify_initial_state_done(skb, seq);
> > > -		goto out;
> > > +		return skb_len;
> > >   	}
> > >   	n = cb->args[4]++;
> > >   	if (cb->args[4] < cb->args[3])
> > > 
> > 
> > Thanks for the patch!
> > 
> > I think the problem goes even further: skb can also be freed in the 
> > notify_*_state_change -> notify_*_state calls below.
> > 
> > Also, at the point where we save skb->len into skb_len, skb is not 
> > initialized yet. Maybe it makes more sense to not return a length in the 
> > first place here, but an error code instead.
> > 
> > -- 
> > Christoph Böhmwalder
> > LINBIT | Keeping the Digital World Running
> > DRBD HA —  Disaster Recovery — Software defined Storage
> 
> Ok, I see.
> I found that drbd_adm_get_initial_state() has called the get_initial_state(),
> and return -ENOMEM if it calls remember_old_state() failed.
> 
> So, i think that means if get_initial_state() failed on the notify_initial_state_done(),
> it should return -ENOMEM too.
> 
> I will submit the PATCH v2 to fix the first place. The fixes of the further problem is 
> hard for me.
> 
> Thanks.

I found that notify_initial_state_done() uses err = -EMSGSIZE, so the first place should
return -EMSGSIZE not -ENOMEM. Sorry.

  reply	other threads:[~2021-04-01 17:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-01 11:57 [PATCH] drbd: Fix a use after free in get_initial_state Lv Yunlong
2021-04-01 13:01 ` [Drbd-dev] " Christoph Böhmwalder
2021-04-01 15:13   ` lyl2019
2021-04-01 15:17     ` lyl2019 [this message]
2021-04-02  5:09 ` kernel test robot

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=17336352.26b99.1788e02bf3d.Coremail.lyl2019@mail.ustc.edu.cn \
    --to=lyl2019@mail.ustc.edu.cn \
    --cc=axboe@kernel.dk \
    --cc=christoph.boehmwalder@linbit.com \
    --cc=drbd-dev@lists.linbit.com \
    --cc=lars.ellenberg@linbit.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=philipp.reisner@linbit.com \
    /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