linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Marc Dionne <marc.c.dionne@gmail.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Vlastimil Babka <vbabka@suse.cz>,
	Marc Dionne <marc.dionne@auristor.com>
Subject: Re: [PATCH v3] tools/mm: Fix slabinfo crash when MAX_SLABS is exceeded
Date: Wed, 30 Oct 2024 15:40:09 -0700	[thread overview]
Message-ID: <20241030154009.16b693b53b3c00d2439fd854@linux-foundation.org> (raw)
In-Reply-To: <20241030133208.41061-1-marc.c.dionne@gmail.com>

On Wed, 30 Oct 2024 10:32:08 -0300 Marc Dionne <marc.c.dionne@gmail.com> wrote:

> From: Marc Dionne <marc.dionne@auristor.com>
> 
> The number of slabs can easily exceed the hard coded MAX_SLABS in the
> slabinfo tool, causing it to overwrite memory and crash.
> 
> Increase the value of MAX_SLABS, and check if that has been exceeded for
> each new slab, instead of at the end when it's already too late.  Also
> move the check for MAX_ALIASES into the loop body.
> 
> @@ -1240,6 +1240,8 @@ static void read_slab_dir(void)
>  				p--;
>  			alias->ref = strdup(p);
>  			alias++;
> +			if (alias - aliasinfo == MAX_ALIASES)
> +				fatal("Too many aliases\n");

Again, this is not correct.  It has a potential off-by-one error.

If at this point, (alias - aliasinfo == MAX_ALIASES), we *do not know*
whether there are "Too many aliases".  Because the parsing might have
reached the end of input, in which case we're fine.

A fix for this is to check for an invalid `alias' immediately before we
use it, as I described in the previous email.



      reply	other threads:[~2024-10-30 22:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-30 13:32 Marc Dionne
2024-10-30 22:40 ` Andrew Morton [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=20241030154009.16b693b53b3c00d2439fd854@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=marc.c.dionne@gmail.com \
    --cc=marc.dionne@auristor.com \
    --cc=vbabka@suse.cz \
    /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