public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chen Gang <gang.chen@asianux.com>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
	"linux-kernel@vger.kernel.org >> linux-kernel@vger.kernel.org" 
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] kernel: module: strncpy issue, using strlcpy instead of strncpy
Date: Mon, 08 Apr 2013 10:48:15 +0800	[thread overview]
Message-ID: <51622FEF.2070801@asianux.com> (raw)
In-Reply-To: <CAMuHMdU+K9Kqe1JS+PCcuyf_3V1yMDe_M1r63SyEyp4ppfkpfg@mail.gmail.com>

On 2013年04月07日 22:28, Geert Uytterhoeven wrote:
> On Sun, Apr 7, 2013 at 1:38 PM, Chen Gang <gang.chen@asianux.com> wrote:
>> >   ownername and namebuf are all NUL terminated string.
>> >
>> >   need always let them ended by '\0'.
>> >
>> > Signed-off-by: Chen Gang <gang.chen@asianux.com>
>> > ---
>> >  kernel/module.c |    4 ++--
>> >  1 files changed, 2 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/kernel/module.c b/kernel/module.c
>> > index 3c2c72d..597efd8 100644
>> > --- a/kernel/module.c
>> > +++ b/kernel/module.c
>> > @@ -3464,7 +3464,7 @@ const char *module_address_lookup(unsigned long addr,
>> >         }
>> >         /* Make a copy in here where it's safe */
>> >         if (ret) {
>> > -               strncpy(namebuf, ret, KSYM_NAME_LEN - 1);
>> > +               strlcpy(namebuf, ret, KSYM_NAME_LEN);
>> >                 ret = namebuf;
>> >         }
>> >         preempt_enable();
> Is this buffer ever copied to userspace?


at lease now:
  I think, it is not, the reason is:
    it is only a tool function for kallsyms using.
    it has no duty to let namebuf initialized.

  please reference the related comments in include/linux/module.h

493 /* For kallsyms to ask for address resolution.  namebuf should be at
494  * least KSYM_NAME_LEN long: a pointer to namebuf is returned if
495  * found, otherwise NULL. */
496 const char *module_address_lookup(unsigned long addr,
497                             unsigned long *symbolsize,
498                             unsigned long *offset,
499                             char **modname,
500                             char *namebuf);


originally:
  it will not cause issue (the upper caller has noticed it).
  but we really need let it '\0' ended within module_address_lookup.
    (so, maybe for subject: "strncpy issue" need be deleted)


in the future:
  since it is an extern function, it can be used by others.
  since it is a tool function, it can not be used directly by user mode.
  according to the api definition:
    if it is necessary to initialize (such as return to user mode)
      the caller should perform it.
    if it is not necessary to initialize (not return to user mode)
      still prefer the caller to initialize it.
      but should understand if the caller will not initialize it.
        (if caller does not initialize it, it should not cause issue)


  thanks.

  :-)


-- 
Chen Gang

Asianux Corporation

  reply	other threads:[~2013-04-08  2:48 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-07 11:38 [PATCH] kernel: module: strncpy issue, using strlcpy instead of strncpy Chen Gang
2013-04-07 14:28 ` Geert Uytterhoeven
2013-04-08  2:48   ` Chen Gang [this message]
2013-04-08  3:02     ` Chen Gang
2013-04-08  5:30 ` Rusty Russell
2013-04-08 10:16   ` Chen Gang
2013-04-08 13:45     ` Rusty Russell
2013-04-09  1:52       ` Chen Gang
2013-04-09  9:36         ` Chen Gang
2013-04-09  9:55           ` Chen Gang
2013-04-10  6:00           ` Chen Gang
2013-04-09  2:47     ` [PATCH v2] kernel: module: using strlcpy and strcpy " Chen Gang
2013-04-10  1:22       ` Rusty Russell
2013-04-10  4:13         ` [PATCH v3] " Chen Gang
2013-04-10  6:52           ` Rusty Russell

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=51622FEF.2070801@asianux.com \
    --to=gang.chen@asianux.com \
    --cc=geert@linux-m68k.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    /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