Distributed Replicated Block Device (DRBD) development
 help / color / mirror / Atom feed
From: "Christoph Böhmwalder" <christoph.boehmwalder@linbit.com>
To: John Sanpe <sanpeqf@gmail.com>
Cc: lars.ellenberg@linbit.com, philipp.reisner@linbit.com,
	linux-kernel@vger.kernel.org, drbd-dev@lists.linbit.com
Subject: Re: [Drbd-dev] [PATCH] lib/lru_cache: Fixed array overflow caused by incorrect boundary handling.
Date: Mon, 1 Aug 2022 17:40:52 +0200	[thread overview]
Message-ID: <4d88538d-c401-ebaf-8f63-8e8b7ad9e632@linbit.com> (raw)
In-Reply-To: <20220723075931.163245-1-sanpeqf@gmail.com>

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@gmail.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@linbit.com>

-- 
Christoph Böhmwalder
LINBIT | Keeping the Digital World Running
DRBD HA —  Disaster Recovery — Software defined Storage

      reply	other threads:[~2022-08-01 15:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-23  7:59 [Drbd-dev] [PATCH] lib/lru_cache: Fixed array overflow caused by incorrect boundary handling John Sanpe
2022-08-01 15:40 ` Christoph Böhmwalder [this message]

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=4d88538d-c401-ebaf-8f63-8e8b7ad9e632@linbit.com \
    --to=christoph.boehmwalder@linbit.com \
    --cc=drbd-dev@lists.linbit.com \
    --cc=lars.ellenberg@linbit.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=philipp.reisner@linbit.com \
    --cc=sanpeqf@gmail.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