hash: fix use after free in thash

Message ID 1635519300-458498-1-git-send-email-vladimir.medvedkin@intel.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series hash: fix use after free in thash |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS

Commit Message

Vladimir Medvedkin Oct. 29, 2021, 2:54 p.m. UTC
  This patch fixes use after free in thash library, reported by ASAN.

Bugzilla ID: 868
Fixes: 28ebff11c2dc ("hash: add predictable RSS")

Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
---
 lib/hash/rte_thash.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

David Marchand Nov. 3, 2021, 3:41 p.m. UTC | #1
On Fri, Oct 29, 2021 at 4:55 PM Vladimir Medvedkin
<vladimir.medvedkin@intel.com> wrote:
>
> This patch fixes use after free in thash library, reported by ASAN.
>
> Bugzilla ID: 868
> Fixes: 28ebff11c2dc ("hash: add predictable RSS")
>
> Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>

Reviewed-by: David Marchand <david.marchand@redhat.com>
  
Thomas Monjalon Nov. 4, 2021, 10:38 a.m. UTC | #2
03/11/2021 16:41, David Marchand:
> On Fri, Oct 29, 2021 at 4:55 PM Vladimir Medvedkin
> <vladimir.medvedkin@intel.com> wrote:
> >
> > This patch fixes use after free in thash library, reported by ASAN.
> >
> > Bugzilla ID: 868
> > Fixes: 28ebff11c2dc ("hash: add predictable RSS")
> >
> > Signed-off-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
> 
> Reviewed-by: David Marchand <david.marchand@redhat.com>

Applied, thanks.
  

Patch

diff --git a/lib/hash/rte_thash.c b/lib/hash/rte_thash.c
index 696a112..7a284a7 100644
--- a/lib/hash/rte_thash.c
+++ b/lib/hash/rte_thash.c
@@ -416,10 +416,10 @@  insert_before(struct rte_thash_ctx *ctx,
 			return ret;
 		}
 	} else if ((next_ent != NULL) && (end > next_ent->offset)) {
-		rte_free(ent);
 		RTE_LOG(ERR, HASH,
 			"Can't add helper %s due to conflict with existing"
 			" helper %s\n", ent->name, next_ent->name);
+		rte_free(ent);
 		return -ENOSPC;
 	}
 	attach_lfsr(ent, cur_ent->lfsr);
@@ -465,10 +465,10 @@  insert_after(struct rte_thash_ctx *ctx,
 	int ret;
 
 	if ((next_ent != NULL) && (end > next_ent->offset)) {
-		rte_free(ent);
 		RTE_LOG(ERR, HASH,
 			"Can't add helper %s due to conflict with existing"
 			" helper %s\n", ent->name, next_ent->name);
+		rte_free(ent);
 		return -EEXIST;
 	}