Linux-Modules Archive on lore.kernel.org
 help / color / Atom feed
From: Lucas De Marchi <lucas.de.marchi@gmail.com>
To: linux-modules <linux-modules@vger.kernel.org>
Cc: Lucas De Marchi <lucas.demarchi@intel.com>
Subject: Re: [PATCH 3/3] depmod: fix string overflow
Date: Sat, 13 Aug 2016 17:31:50 -0300
Message-ID: <CAKi4VALH8cJEXnYsMVA99+JF13HAyX0AKd0n8qvkfX0sC5Ehig@mail.gmail.com> (raw)
In-Reply-To: <1470854233-19810-3-git-send-email-lucas.de.marchi@gmail.com>

On Wed, Aug 10, 2016 at 3:37 PM, Lucas De Marchi
<lucas.de.marchi@gmail.com> wrote:
> From: Lucas De Marchi <lucas.demarchi@intel.com>
>
> Use scratchbuf to fix issue with strcpy that may overflow the buffer we
> declared in the stack.
> ---
>  tools/depmod.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/tools/depmod.c b/tools/depmod.c
> index a2e07c1..be9e001 100644
> --- a/tools/depmod.c
> +++ b/tools/depmod.c
> @@ -35,6 +35,7 @@
>  #include <shared/hash.h>
>  #include <shared/macro.h>
>  #include <shared/util.h>
> +#include <shared/scratchbuf.h>
>
>  #include <libkmod/libkmod.h>
>
> @@ -1920,6 +1921,7 @@ static int output_symbols_bin(struct depmod *depmod, FILE *out)
>  {
>         struct index_node *idx;
>         char alias[1024];
> +       struct scratchbuf salias;
>         size_t baselen = sizeof("symbol:") - 1;
>         struct hash_iter iter;
>         const void *v;
> @@ -1932,16 +1934,21 @@ static int output_symbols_bin(struct depmod *depmod, FILE *out)
>                 return -ENOMEM;
>
>         memcpy(alias, "symbol:", baselen);
> +       scratchbuf_init(&salias, alias, sizeof(alias));
> +
>         hash_iter_init(depmod->symbols, &iter);
>
>         while (hash_iter_next(&iter, NULL, &v)) {
>                 int duplicate;
>                 const struct symbol *sym = v;
> +               size_t len;
>
>                 if (sym->owner == NULL)
>                         continue;
>
> -               strcpy(alias + baselen, sym->name);
> +               len = strlen(sym->name);
> +               scratchbuf_alloc(&salias, baselen + len + 1);

err... the whole point of scratchbuf was to be able to increase the
buffer size and check for errors. Here I forgot to check them.


Lucas De Marchi

  reply index

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-10 18:37 [PATCH 1/3] testsuite: include stdio.h Lucas De Marchi
2016-08-10 18:37 ` [PATCH 2/3] Add scratchbuf implementation Lucas De Marchi
2016-08-10 18:37 ` [PATCH 3/3] depmod: fix string overflow Lucas De Marchi
2016-08-13 20:31   ` Lucas De Marchi [this message]
2016-08-15 13:28     ` Lucas De Marchi

Reply instructions:

You may reply publically 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=CAKi4VALH8cJEXnYsMVA99+JF13HAyX0AKd0n8qvkfX0sC5Ehig@mail.gmail.com \
    --to=lucas.de.marchi@gmail.com \
    --cc=linux-modules@vger.kernel.org \
    --cc=lucas.demarchi@intel.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

Linux-Modules Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-modules/0 linux-modules/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-modules linux-modules/ https://lore.kernel.org/linux-modules \
		linux-modules@vger.kernel.org linux-modules@archiver.kernel.org
	public-inbox-index linux-modules


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-modules


AGPL code for this site: git clone https://public-inbox.org/ public-inbox