From: Marc Dionne <marc.dionne@auristor.com>
To: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/mm: Fix slabinfo crash when MAX_SLABS is exceeded
Date: Tue, 29 Oct 2024 13:12:59 -0300 [thread overview]
Message-ID: <CAB9dFduUf_3N-9=t3O6ePxanjwPiqdQmgKR6O8VoF5BmPG_b4Q@mail.gmail.com> (raw)
In-Reply-To: <20241029160609.13725-1-marc.c.dionne@gmail.com>
On Tue, Oct 29, 2024 at 1:06 PM 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.
>
> Signed-off-by: Marc Dionne <marc.dionne@auristor.com>
> ---
> tools/mm/slabinfo.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/tools/mm/slabinfo.c b/tools/mm/slabinfo.c
> index cfaeaea71042..2c9c86d677ed 100644
> --- a/tools/mm/slabinfo.c
> +++ b/tools/mm/slabinfo.c
> @@ -21,7 +21,7 @@
> #include <regex.h>
> #include <errno.h>
>
> -#define MAX_SLABS 500
> +#define MAX_SLABS 1000
> #define MAX_ALIASES 500
> #define MAX_NODES 1024
>
> @@ -1240,6 +1240,8 @@ static void read_slab_dir(void)
> p--;
> alias->ref = strdup(p);
> alias++;
> + if (aliases > MAX_ALIASES)
This is not quite right, needs to be alias - aliasinfo. Will send a V2.
> + fatal("Too many aliases\n");
> break;
> case DT_DIR:
> if (chdir(de->d_name))
> @@ -1301,6 +1303,8 @@ static void read_slab_dir(void)
> if (slab->name[0] == ':')
> alias_targets++;
> slab++;
> + if (slab - slabinfo > MAX_SLABS)
> + fatal("Too many slabs\n");
> break;
> default :
> fatal("Unknown file type %lx\n", de->d_type);
> @@ -1310,10 +1314,6 @@ static void read_slab_dir(void)
> slabs = slab - slabinfo;
> actual_slabs = slabs;
> aliases = alias - aliasinfo;
> - if (slabs > MAX_SLABS)
> - fatal("Too many slabs\n");
> - if (aliases > MAX_ALIASES)
> - fatal("Too many aliases\n");
> }
>
> static void output_slabs(void)
> --
> 2.47.0
>
prev parent reply other threads:[~2024-12-05 15:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-29 16:06 Marc Dionne
2024-10-29 16:12 ` Marc Dionne [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='CAB9dFduUf_3N-9=t3O6ePxanjwPiqdQmgKR6O8VoF5BmPG_b4Q@mail.gmail.com' \
--to=marc.dionne@auristor.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/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