Message ID | 1470041061-8059-1-git-send-email-sagi@grimberg.me (mailing list archive) |
---|---|
State | Superseded, archived |
Headers |
Return-Path: <dev-bounces@dpdk.org> X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 54C332C0F; Mon, 1 Aug 2016 10:44:27 +0200 (CEST) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by dpdk.org (Postfix) with ESMTP id 99B3F2C0C for <dev@dpdk.org>; Mon, 1 Aug 2016 10:44:25 +0200 (CEST) Received: from bzq-82-81-101-184.red.bezeqint.net ([82.81.101.184] helo=bombadil.infradead.org) by merlin.infradead.org with esmtpsa (Exim 4.85_2 #1 (Red Hat Linux)) id 1bU8pk-00089b-B4 for dev@dpdk.org; Mon, 01 Aug 2016 08:44:24 +0000 From: Sagi Grimberg <sagi@grimberg.me> To: dev@dpdk.org Date: Mon, 1 Aug 2016 11:44:21 +0300 Message-Id: <1470041061-8059-1-git-send-email-sagi@grimberg.me> X-Mailer: git-send-email 1.9.1 Subject: [dpdk-dev] [PATCH] net/mlx5: Fix possible NULL deref in RX path X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK <dev.dpdk.org> List-Unsubscribe: <http://dpdk.org/ml/options/dev>, <mailto:dev-request@dpdk.org?subject=unsubscribe> List-Archive: <http://dpdk.org/ml/archives/dev/> List-Post: <mailto:dev@dpdk.org> List-Help: <mailto:dev-request@dpdk.org?subject=help> List-Subscribe: <http://dpdk.org/ml/listinfo/dev>, <mailto:dev-request@dpdk.org?subject=subscribe> Errors-To: dev-bounces@dpdk.org Sender: "dev" <dev-bounces@dpdk.org> |
Commit Message
Sagi Grimberg
Aug. 1, 2016, 8:44 a.m. UTC
The user is allowed to call ->rx_pkt_burst() even without free
mbufs in the pool. In this scenario we'll fail allocating a rep mbuf
on the first iteration (where pkt is still NULL). This would cause us
to deref a NULL pkt (reset refcount and free).
Fix this by checking the pkt before freeing it.
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
---
drivers/net/mlx5/mlx5_rxtx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Hi Sagi, On Mon, Aug 01, 2016 at 11:44:21AM +0300, Sagi Grimberg wrote: > The user is allowed to call ->rx_pkt_burst() even without free > mbufs in the pool. In this scenario we'll fail allocating a rep mbuf > on the first iteration (where pkt is still NULL). This would cause us > to deref a NULL pkt (reset refcount and free). > > Fix this by checking the pkt before freeing it. Just to be sure, did you get an actual NULL deref crash here or is that an assumed possibility? I'm asking because this problem was supposed to be addressed by: a1bdb71a32da ("net/mlx5: fix crash in Rx") > Signed-off-by: Sagi Grimberg <sagi@grimberg.me> > --- > drivers/net/mlx5/mlx5_rxtx.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/mlx5/mlx5_rxtx.c b/drivers/net/mlx5/mlx5_rxtx.c > index fce3381ae87a..a07cc4794023 100644 > --- a/drivers/net/mlx5/mlx5_rxtx.c > +++ b/drivers/net/mlx5/mlx5_rxtx.c > @@ -1572,7 +1572,7 @@ mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n) > rte_prefetch0(wqe); > rep = rte_mbuf_raw_alloc(rxq->mp); > if (unlikely(rep == NULL)) { > - while (pkt != seg) { > + while (pkt && pkt != seg) { > assert(pkt != (*rxq->elts)[idx]); > seg = NEXT(pkt); > rte_mbuf_refcnt_set(pkt, 0); > -- > 1.9.1 I've reviewed your patch and it indeed seems to address an issue, please confirm my analysis below. When rep cannot be allocated and is thus NULL, either pkt is still NULL because the first packet segment has not been seen yet or points to the first segment. Either way at this point, seg points to current segment to process in the queue and is never NULL. Thus when pkt is still NULL (first segment) and rep cannot be allocated, the comparison (pkt != seg) between a valid pointer (seg) and NULL (pkt) succeeds. This case is not handled by the assert() statement and a crash occurs. We really want to avoid useless code in the data path, particularly inside loops. The extra check you added is performed for each iteration, so what about modifying your patch by adding the following if statement instead? if (!pkt) pkt = seg; while (pkt != seg) { ... } I guess you could add "Fixes: a1bdb71a32da ("net/mlx5: fix crash in Rx")" line to your commit log as well because the original patch only solved half of the issue. Thanks.
On 01/08/16 19:43, Adrien Mazarguil wrote: > Hi Sagi, > > On Mon, Aug 01, 2016 at 11:44:21AM +0300, Sagi Grimberg wrote: >> The user is allowed to call ->rx_pkt_burst() even without free >> mbufs in the pool. In this scenario we'll fail allocating a rep mbuf >> on the first iteration (where pkt is still NULL). This would cause us >> to deref a NULL pkt (reset refcount and free). >> >> Fix this by checking the pkt before freeing it. > > Just to be sure, did you get an actual NULL deref crash here or is that an > assumed possibility? > > I'm asking because this problem was supposed to be addressed by: > > a1bdb71a32da ("net/mlx5: fix crash in Rx") I actually got the NULL deref. This happens when the application doesn't restore mbufs to the pool correctly. In the case rte_mbuf_raw_alloc will fail on the first iteration (pkt wasn't assigned) unlike the condition handled in a1bdb71a32da. With this applied, I didn't see the crash.
On Tue, Aug 02, 2016 at 12:31:35PM +0300, Sagi Grimberg wrote: > > > On 01/08/16 19:43, Adrien Mazarguil wrote: > >Hi Sagi, > > > >On Mon, Aug 01, 2016 at 11:44:21AM +0300, Sagi Grimberg wrote: > >>The user is allowed to call ->rx_pkt_burst() even without free > >>mbufs in the pool. In this scenario we'll fail allocating a rep mbuf > >>on the first iteration (where pkt is still NULL). This would cause us > >>to deref a NULL pkt (reset refcount and free). > >> > >>Fix this by checking the pkt before freeing it. > > > >Just to be sure, did you get an actual NULL deref crash here or is that an > >assumed possibility? > > > >I'm asking because this problem was supposed to be addressed by: > > > > a1bdb71a32da ("net/mlx5: fix crash in Rx") > > I actually got the NULL deref. This happens when the application doesn't > restore mbufs to the pool correctly. In the case rte_mbuf_raw_alloc > will fail on the first iteration (pkt wasn't assigned) unlike the > condition handled in a1bdb71a32da. > > With this applied, I didn't see the crash. Thanks for confirming this, now what about the different approach I suggested in my previous message to avoid the extra check in the inner loop: if (!pkt) pkt = seg; while (pkt != seg) { ... } Also the fixes line in your commit message?
diff --git a/drivers/net/mlx5/mlx5_rxtx.c b/drivers/net/mlx5/mlx5_rxtx.c index fce3381ae87a..a07cc4794023 100644 --- a/drivers/net/mlx5/mlx5_rxtx.c +++ b/drivers/net/mlx5/mlx5_rxtx.c @@ -1572,7 +1572,7 @@ mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n) rte_prefetch0(wqe); rep = rte_mbuf_raw_alloc(rxq->mp); if (unlikely(rep == NULL)) { - while (pkt != seg) { + while (pkt && pkt != seg) { assert(pkt != (*rxq->elts)[idx]); seg = NEXT(pkt); rte_mbuf_refcnt_set(pkt, 0);