Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1625935
| From | David Laight <David.Laight@ACULAB.COM> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | RE: [PATCH v2 1/5] kprobes: convert kprobe_lookup_name() to a function |
| Date | 2017-04-19 10:50 +0200 |
| Message-ID | <txTtf-1cG-3@gated-at.bofh.it> (permalink) |
| References | <tvoad-3rc-5@gated-at.bofh.it> <tvojT-3JH-15@gated-at.bofh.it> <txATE-6he-13@gated-at.bofh.it> <txSQx-YG-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Naveen N. Rao
> Sent: 19 April 2017 09:09
> To: David Laight; Michael Ellerman
> Cc: linux-kernel@vger.kernel.org; linuxppc-dev@lists.ozlabs.org; Masami Hiramatsu; Ingo Molnar
> Subject: RE: [PATCH v2 1/5] kprobes: convert kprobe_lookup_name() to a function
>
> Excerpts from David Laight's message of April 18, 2017 18:22:
> > From: Naveen N. Rao
> >> Sent: 12 April 2017 11:58
> > ...
> >> +kprobe_opcode_t *kprobe_lookup_name(const char *name)
> >> +{
> > ...
> >> + char dot_name[MODULE_NAME_LEN + 1 + KSYM_NAME_LEN];
> >> + const char *modsym;
> >> + bool dot_appended = false;
> >> + if ((modsym = strchr(name, ':')) != NULL) {
> >> + modsym++;
> >> + if (*modsym != '\0' && *modsym != '.') {
> >> + /* Convert to <module:.symbol> */
> >> + strncpy(dot_name, name, modsym - name);
> >> + dot_name[modsym - name] = '.';
> >> + dot_name[modsym - name + 1] = '\0';
> >> + strncat(dot_name, modsym,
> >> + sizeof(dot_name) - (modsym - name) - 2);
> >> + dot_appended = true;
> >
> > If the ':' is 'a way down' name[] then although the strncpy() won't
> > overrun dot_name[] the rest of the code can.
>
> Nice catch, thanks David!
> We need to be validating the length of 'name'. I'll put out a patch for
> that.
Silent truncation is almost certainly wrong here.
> As an aside, I'm not sure I follow what you mean when you say that the
> strncpy() won't overrun dot_name[]. If we have a name[] longer than
> sizeof(dot_name) with the ':' after that, the strncpy() can also overrun
> dot_name[].
Yes, that should just be a memcpy(), as should the strncat().
Using strncpy() where the length is other than the size of the target buffer
should be banned. Not that it ever does what people expect.
strncat() is even worse.
David
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v2 0/5] powerpc: a few kprobe fixes and refactoring "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-04-12 13:00 +0200
[PATCH v2 2/5] powerpc: kprobes: fix handling of function offsets on ABIv2 "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-04-12 13:10 +0200
Re: [PATCH v2 2/5] powerpc: kprobes: fix handling of function offsets on ABIv2 Masami Hiramatsu <mhiramat@kernel.org> - 2017-04-13 06:30 +0200
[PATCH v2 3/5] powerpc: introduce a new helper to obtain function entry points "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-04-12 13:10 +0200
Re: [PATCH v2 3/5] powerpc: introduce a new helper to obtain function entry points Masami Hiramatsu <mhiramat@kernel.org> - 2017-04-13 06:40 +0200
Re: [PATCH v2 3/5] powerpc: introduce a new helper to obtain function entry points "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-04-13 08:00 +0200
[PATCH v2 1/5] kprobes: convert kprobe_lookup_name() to a function "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-04-12 13:10 +0200
Re: [PATCH v2 1/5] kprobes: convert kprobe_lookup_name() to a function Masami Hiramatsu <mhiramat@kernel.org> - 2017-04-13 05:10 +0200
RE: [PATCH v2 1/5] kprobes: convert kprobe_lookup_name() to a function David Laight <David.Laight@ACULAB.COM> - 2017-04-18 15:00 +0200
RE: [PATCH v2 1/5] kprobes: convert kprobe_lookup_name() to a function "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-04-19 10:10 +0200
RE: [PATCH v2 1/5] kprobes: convert kprobe_lookup_name() to a function David Laight <David.Laight@ACULAB.COM> - 2017-04-19 10:50 +0200
Re: [PATCH v2 1/5] kprobes: convert kprobe_lookup_name() to a function "'Naveen N. Rao'" <naveen.n.rao@linux.vnet.ibm.com> - 2017-04-19 13:10 +0200
[PATCH v2 4/5] powerpc: kprobes: factor out code to emulate instruction into a helper "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-04-12 13:10 +0200
Re: [PATCH v2 4/5] powerpc: kprobes: factor out code to emulate instruction into a helper Masami Hiramatsu <mhiramat@kernel.org> - 2017-04-13 06:40 +0200
Re: [PATCH v2 4/5] powerpc: kprobes: factor out code to emulate instruction into a helper "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-04-13 08:00 +0200
Re: [PATCH v2 4/5] powerpc: kprobes: factor out code to emulate instruction into a helper "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-04-13 11:00 +0200
[PATCH v2 5/5] powerpc: kprobes: emulate instructions on kprobe handler re-entry "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-04-12 13:10 +0200
Re: [PATCH v2 5/5] powerpc: kprobes: emulate instructions on kprobe handler re-entry Masami Hiramatsu <mhiramat@kernel.org> - 2017-04-13 06:40 +0200
Re: [PATCH v2 5/5] powerpc: kprobes: emulate instructions on kprobe handler re-entry "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-04-13 08:00 +0200
Re: [PATCH v2 0/5] powerpc: a few kprobe fixes and refactoring Masami Hiramatsu <mhiramat@kernel.org> - 2017-04-13 05:10 +0200
Re: [PATCH v2 0/5] powerpc: a few kprobe fixes and refactoring "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com> - 2017-04-13 08:00 +0200
csiph-web