mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xiaotian Feng <xtfeng@gmail.com>
To: wzt.wzt@gmail.com
Cc: linux-kernel@vger.kernel.org, axboe@kernel.dk
Subject: Re: [PATCH] Block: Fix block/elevator.c elevator_get() off-by-one  error
Date: Fri, 2 Apr 2010 15:14:42 +0800	[thread overview]
Message-ID: <x2o7b6bb4a51004020014xb9ce0784ifdb255c28c6aa02d@mail.gmail.com> (raw)
In-Reply-To: <20100330092132.GB2713@localhost.localdomain>

On Tue, Mar 30, 2010 at 5:21 PM,  <wzt.wzt@gmail.com> wrote:
> elevator_get() not check the name length, if the name length > sizeof(elv),
> elv will miss the '\0'. And elv buffer will be replace "-iosched" as something
> like aaaaaaaaa, then call request_module() can load an not trust module.
>
> Signed-off-by: Zhitong Wang <zhitong.wangzt@alibaba-inc.com>
>
> ---
>  block/elevator.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/block/elevator.c b/block/elevator.c
> index df75676..76e3702 100644
> --- a/block/elevator.c
> +++ b/block/elevator.c
> @@ -154,7 +154,7 @@ static struct elevator_type *elevator_get(const char *name)
>
>                spin_unlock(&elv_list_lock);
>
> -               sprintf(elv, "%s-iosched", name);
> +               snprintf(elv, sizeof(elv), "%s-iosched", name);
>

elv is defined as char elv[ELV_NAME_MAX + strlen("-iosched")];
so if name length > sizeof(elv), the name length must already bigger
than ELV_NAME_MAX

elevator_get is used in elevator_init, so if elevator_init is passing
a super long name, why not just return -EINVAL?
In this patch, if we pass a super long name, we're still trying to cut
it and request_module an invalid name, right?
Although '\0' is kept, but name is still invalid, right?


>                request_module("%s", elv);
>                spin_lock(&elv_list_lock);
> --
> 1.6.5.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>

      parent reply	other threads:[~2010-04-02  7:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-30  9:21 wzt.wzt
2010-04-02  6:40 ` Jens Axboe
2010-04-02  7:14 ` Xiaotian Feng [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=x2o7b6bb4a51004020014xb9ce0784ifdb255c28c6aa02d@mail.gmail.com \
    --to=xtfeng@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wzt.wzt@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

all inboxes | Powered by JetHome®