[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <4d88538d-c401-ebaf-8f63-8e8b7ad9e632@linbit.com>
Date: Mon, 1 Aug 2022 17:40:52 +0200
From: Christoph Böhmwalder
<christoph.boehmwalder@...bit.com>
To: John Sanpe <sanpeqf@...il.com>
Cc: drbd-dev@...ts.linbit.com, linux-kernel@...r.kernel.org,
philipp.reisner@...bit.com, lars.ellenberg@...bit.com
Subject: Re: [PATCH] lib/lru_cache: Fixed array overflow caused by incorrect
boundary handling.
Am 23.07.22 um 09:59 schrieb John Sanpe:
> This problem occurs when malloc element failed on the first time.
> At this time, the counter i is 0. When it's released, we subtract 1
> in advance without checking, which will cause i to become UINT_MAX,
> resulting in array overflow.
>
> Signed-off-by: John Sanpe <sanpeqf@...il.com>
> ---
> lib/lru_cache.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/lru_cache.c b/lib/lru_cache.c
> index 52313acbfa62..04d95de92602 100644
> --- a/lib/lru_cache.c
> +++ b/lib/lru_cache.c
> @@ -147,7 +147,7 @@ struct lru_cache *lc_create(const char *name, struct kmem_cache *cache,
> return lc;
>
> /* else: could not allocate all elements, give up */
> - for (i--; i; i--) {
> + while (i--) {
> void *p = element[i];
> kmem_cache_free(cache, p - e_off);
> }
Thanks for the fix, looks good to me.
Reviewed-by: Christoph Böhmwalder <christoph.boehmwalder@...bit.com>
--
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running
DRBD HA — Disaster Recovery — Software defined Storage
Powered by blists - more mailing lists