From: Andi Kleen <ak@muc.de>
To: torvalds@transmeta.com, linux-kernel@vger.kernel.org,
rusty@rustcorp.com.au
Subject: [PATCH] Fix undefined/miscompiled construct in kernel parameters
Date: Sun, 15 Jun 2003 14:58:54 +0200 [thread overview]
Message-ID: <20030615125854.GA29458@averell> (raw)
The parse_args call in init/main.c does pointer arithmetic between two
different external symbols. This is undefined in C (only pointer arthmetic
in the same symbol is defined) and gets miscompiled on AMD64 with gcc 3.2,
resulting in a triple fault at boot when an driver with new style
parameters is compiled in. In my case it was triggered by oprofile.
This patch works around this by passing the end pointer directly
to the low level function and comparing it there. Strictly this
is still undefined, but should be ok because gcc has to handle these
pointers in another function correctly.
It is also possible to use an empty asm() with dummy input/out to work
around this, but I didn't do that for now.
The construct may appear in other cases too, but I didn't see any
miscompilation so far.
Please apply,
-Andi
diff -burpN -X ../KDIFX linux/include/linux/moduleparam.h linux-2.5.71-amd64/include/linux/moduleparam.h
--- linux/include/linux/moduleparam.h 2003-05-27 03:00:39.000000000 +0200
+++ linux-2.5.71-amd64/include/linux/moduleparam.h 2003-06-15 14:49:45.000000000 +0200
@@ -67,7 +67,7 @@ struct kparam_string {
extern int parse_args(const char *name,
char *args,
struct kernel_param *params,
- unsigned num,
+ struct kernel_param *end,
int (*unknown)(char *param, char *val));
/* All the helper functions */
diff -burpN -X ../KDIFX linux/init/main.c linux-2.5.71-amd64/init/main.c
--- linux/init/main.c 2003-06-14 23:43:06.000000000 +0200
+++ linux-2.5.71-amd64/init/main.c 2003-06-15 13:16:41.000000000 +0200
@@ -404,7 +404,7 @@ asmlinkage void __init start_kernel(void
page_alloc_init();
printk("Kernel command line: %s\n", saved_command_line);
parse_args("Booting kernel", command_line, &__start___param,
- &__stop___param - &__start___param,
+ &__stop___param,
&unknown_bootoption);
trap_init();
rcu_init();
diff -burpN -X ../KDIFX linux/kernel/module.c linux-2.5.71-amd64/kernel/module.c
--- linux/kernel/module.c 2003-06-14 23:43:06.000000000 +0200
+++ linux-2.5.71-amd64/kernel/module.c 2003-06-15 13:18:49.000000000 +0200
@@ -929,7 +929,7 @@ static int obsolete_params(const char *n
kp[i].arg = &obsparm[i];
}
- ret = parse_args(name, args, kp, num, NULL);
+ ret = parse_args(name, args, kp, &kp[num], NULL);
out:
kfree(kp);
return ret;
@@ -1622,11 +1622,11 @@ static struct module *load_module(void _
(char *)sechdrs[strindex].sh_addr);
} else {
/* Size of section 0 is 0, so this works well if no params */
- err = parse_args(mod->name, mod->args,
- (struct kernel_param *)
- sechdrs[setupindex].sh_addr,
- sechdrs[setupindex].sh_size
- / sizeof(struct kernel_param),
+ struct kernel_param *parm = (struct kernel_param *)
+ sechdrs[setupindex].sh_addr;
+ err = parse_args(mod->name, mod->args, parm,
+ &parm[sechdrs[setupindex].sh_size
+ / sizeof(struct kernel_param)],
NULL);
}
if (err < 0)
diff -burpN -X ../KDIFX linux/kernel/params.c linux-2.5.71-amd64/kernel/params.c
--- linux/kernel/params.c 2003-05-27 03:00:46.000000000 +0200
+++ linux-2.5.71-amd64/kernel/params.c 2003-06-15 13:39:16.000000000 +0200
@@ -46,13 +46,13 @@ static inline int parameq(const char *in
static int parse_one(char *param,
char *val,
struct kernel_param *params,
- unsigned num_params,
+ struct kernel_param *end,
int (*handle_unknown)(char *param, char *val))
{
unsigned int i;
/* Find parameter */
- for (i = 0; i < num_params; i++) {
+ for (i = 0; ¶ms[i] < end; i++) {
if (parameq(param, params[i].name)) {
DEBUGP("They are equal! Calling %p\n",
params[i].set);
@@ -109,7 +109,7 @@ static char *next_arg(char *args, char *
int parse_args(const char *name,
char *args,
struct kernel_param *params,
- unsigned num,
+ struct kernel_param *end,
int (*unknown)(char *param, char *val))
{
char *param, *val;
@@ -120,7 +120,7 @@ int parse_args(const char *name,
int ret;
args = next_arg(args, ¶m, &val);
- ret = parse_one(param, val, params, num, unknown);
+ ret = parse_one(param, val, params, end, unknown);
switch (ret) {
case -ENOENT:
printk(KERN_ERR "%s: Unknown parameter `%s'\n",
next reply other threads:[~2003-06-15 12:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-06-15 12:58 Andi Kleen [this message]
2003-06-15 16:52 ` [PATCH] Fix undefined/miscompiled construct in kernel parameters Linus Torvalds
2003-06-16 0:23 ` Rusty Russell
2003-06-16 0:49 ` Richard Henderson
2003-06-16 3:55 ` Rusty Russell
2003-06-16 2:44 ` Linus Torvalds
[not found] <20030615131004$6a85@gated-at.bofh.it>
[not found] ` <20030615170013$4ebc@gated-at.bofh.it>
2003-06-15 17:17 ` Andi Kleen
2003-06-15 17:24 ` Linus Torvalds
2003-06-15 17:32 ` Andi Kleen
2003-06-15 17:48 ` Roman Zippel
2003-06-15 18:28 ` Andi Kleen
2003-06-15 22:56 ` Richard Henderson
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=20030615125854.GA29458@averell \
--to=ak@muc.de \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
--cc=torvalds@transmeta.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