patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Honnappa Nagarahalli <Honnappa.Nagarahalli@arm.com>
To: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>,
	"wangyunjian@huawei.com" <wangyunjian@huawei.com>
Cc: "dev@dpdk.org" <dev@dpdk.org>,
	"luyicai@huawei.com" <luyicai@huawei.com>,
	 "stable@dpdk.org" <stable@dpdk.org>, nd <nd@arm.com>,
	nd <nd@arm.com>
Subject: RE: [dpdk-dev] [PATCH v2] ring: fix use after free in ring release
Date: Wed, 3 May 2023 05:44:54 +0000	[thread overview]
Message-ID: <DBAPR08MB5814145B3280C58569F1035E986C9@DBAPR08MB5814.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <6215f9c3-db40-a0c1-edc6-d859f2920609@yandex.ru>

<snip>

> >>
> >>
> >>
> >>> After the memzone is freed, it is not removed from the 'rte_ring_tailq'.
> >>> If rte_ring_lookup is called at this time, it will cause a
> >>> use-after-free problem. This change prevents that from happening.
> >>>
> >>> Fixes: 4e32101f9b01 ("ring: support freeing")
> >>> Cc: stable@dpdk.org
> >>>
> >>> Suggested-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
> >>> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> >>> ---
> >>> v2: update code suggested by Honnappa Nagarahalli
> >>> ---
> >>>   lib/ring/rte_ring.c | 8 +++-----
> >>>   1 file changed, 3 insertions(+), 5 deletions(-)
> >>>
> >>> diff --git a/lib/ring/rte_ring.c b/lib/ring/rte_ring.c index
> >>> 8ed455043d..2755323b8a 100644
> >>> --- a/lib/ring/rte_ring.c
> >>> +++ b/lib/ring/rte_ring.c
> >>> @@ -333,11 +333,6 @@ rte_ring_free(struct rte_ring *r)
> >>>   		return;
> >>>   	}
> >>>
> >>> -	if (rte_memzone_free(r->memzone) != 0) {
> >>> -		RTE_LOG(ERR, RING, "Cannot free memory\n");
> >>> -		return;
> >>> -	}
> >>> -
> >>>   	ring_list = RTE_TAILQ_CAST(rte_ring_tailq.head, rte_ring_list);
> >>>   	rte_mcfg_tailq_write_lock();
> >>>
> >>> @@ -354,6 +349,9 @@ rte_ring_free(struct rte_ring *r)
> >>>
> >>>   	TAILQ_REMOVE(ring_list, te, next);
> >>>
> >>> +	if (rte_memzone_free(r->memzone) != 0)
> >>> +		RTE_LOG(ERR, RING, "Cannot free memory\n");
> >>> +
> >>
> >> I nit: I think it is a bit better to first release the lock and then
> >> free the memzone.
> > I think both of our suggestions are contradictory. Any reason why you want
> to free outside the locked region?
> 
> 
> Don't know what you mean by 'both suggestions' here.
I wrote 'both of our suggestions'. Essentially, in v1, freeing the memzone was outside of the lock. I suggested to move it inside and you are suggesting to move it inside.

> I think I gave only one - move memzone_free() after tailq_write_unlock().
> To be more precise:
> 1) rte_mcfg_tailq_write_lock();
> ...
> 2) TAILQ_REMOVE(...);
> 3) rte_mcfg_tailq_write_unlock();
> 4) rte_memzone_free(r->memzone);
> 
> As I remember, memzones are protected by their own lock (mlock), so we
> don't need to hold qlock to free a memzone, after ring was already removed
> from the ring_list.
> 
> >
> > I thought, since it belongs to the ring being freed, it makes sense to free it
> while holding the lock to avoid any race conditions (though, I have not
> checked what those are).
> 
> 
> As I understand, it is ok with current design to grab mlock while holding qlock.
> So, there is nothing wrong with current patch, I just think that in that case it is
> excessive, and can be safely avoided.
> 
> >
> >> Apart from that, LGTM.
> >> Acked-by: Konstantin Ananyev <konstantin.v.ananyev@yandex.ru>
> >>
> >>>   	rte_mcfg_tailq_write_unlock();
> >>>
> >>>   	rte_free(te);
> >>> --
> >>> 2.33.0
> >>
> >


  reply	other threads:[~2023-05-03  5:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-17 13:11 [dpdk-dev] [PATCH] " Yunjian Wang
2023-04-18 23:53 ` Honnappa Nagarahalli
2023-04-19  7:08   ` wangyunjian
2023-04-19 21:44     ` Honnappa Nagarahalli
2023-04-20  6:48       ` wangyunjian
2023-04-20  6:43 ` [dpdk-dev] [PATCH v2] " Yunjian Wang
2023-04-20 16:56   ` Honnappa Nagarahalli
2023-05-01 12:32   ` Konstantin Ananyev
2023-05-01 19:06     ` Honnappa Nagarahalli
2023-05-02 23:06       ` Konstantin Ananyev
2023-05-03  5:44         ` Honnappa Nagarahalli [this message]
2023-05-03 22:32           ` Konstantin Ananyev
2023-05-03 23:45             ` Honnappa Nagarahalli
2023-05-05  1:26               ` wangyunjian
2023-05-05  6:48   ` [dpdk-dev] [PATCH v3] " Yunjian Wang
2023-05-23 10:16     ` Thomas Monjalon

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=DBAPR08MB5814145B3280C58569F1035E986C9@DBAPR08MB5814.eurprd08.prod.outlook.com \
    --to=honnappa.nagarahalli@arm.com \
    --cc=dev@dpdk.org \
    --cc=konstantin.v.ananyev@yandex.ru \
    --cc=luyicai@huawei.com \
    --cc=nd@arm.com \
    --cc=stable@dpdk.org \
    --cc=wangyunjian@huawei.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;
as well as URLs for NNTP newsgroup(s).