From: "Fernando Luis Vázquez Cao" <fernando@oss.ntt.co.jp>
To: vgoyal@in.ibm.com
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
akpm@osdl.org, ak@suse.de, James.Bottomley@steeleye.com,
linux-kernel@vger.kernel.org, fastboot@lists.osdl.org
Subject: [PATCH 1/3] stack overflow safe kdump (2.6.18-rc1-i386) - safe_smp_processor_id
Date: Mon, 10 Jul 2006 16:50:52 +0900 [thread overview]
Message-ID: <1152517852.2120.107.camel@localhost.localdomain> (raw)
On the event of a stack overflow critical data that usually resides at
the bottom of the stack is likely to be stomped and, consequently, its
use should be avoided.
In particular, in the i386 and IA64 architectures the macro
smp_processor_id ultimately makes use of the "cpu" member of struct
thread_info which resides at the bottom of the stack. x86_64, on the
other hand, is not affected by this problem because it benefits from
the use of the PDA infrastructure.
To circumvent this problem I suggest implementing
"safe_smp_processor_id()" (it already exists in x86_64) for i386 and
IA64 and use it as a replacement for smp_processor_id in the reboot path
to the dump capture kernel. This is a possible implementation for i386.
Signed-off-by: Fernando Vazquez <fernando@intellilink.co.jp>
---
diff -urNp linux-2.6.18-rc1/arch/i386/kernel/smp.c linux-2.6.18-rc1-sof/arch/i386/kernel/smp.c
--- linux-2.6.18-rc1/arch/i386/kernel/smp.c 2006-07-10 10:59:58.000000000 +0900
+++ linux-2.6.18-rc1-sof/arch/i386/kernel/smp.c 2006-07-10 11:07:35.000000000 +0900
@@ -634,3 +634,29 @@ fastcall void smp_call_function_interrup
}
}
+static int convert_apicid_to_cpu(int apic_id)
+{
+ int i;
+
+ for (i = 0; i < NR_CPUS; i++) {
+ if (x86_cpu_to_apicid[i] == apic_id)
+ return i;
+ }
+ return -1;
+}
+
+int safe_smp_processor_id(void)
+{
+ int apicid, cpuid;
+
+ if (!boot_cpu_has(X86_FEATURE_APIC))
+ return 0;
+
+ apicid = hard_smp_processor_id();
+ if (apicid == BAD_APICID)
+ return 0;
+
+ cpuid = convert_apicid_to_cpu(apicid);
+
+ return cpuid >= 0 ? cpuid : 0;
+}
diff -urNp linux-2.6.18-rc1/include/asm-i386/smp.h linux-2.6.18-rc1-sof/include/asm-i386/smp.h
--- linux-2.6.18-rc1/include/asm-i386/smp.h 2006-07-10 11:00:05.000000000 +0900
+++ linux-2.6.18-rc1-sof/include/asm-i386/smp.h 2006-07-10 15:34:26.000000000 +0900
@@ -89,12 +89,20 @@ static __inline int logical_smp_processo
#endif
+#ifdef CONFIG_X86_VOYAGER
+extern int hard_smp_processor_id(void);
+#define safe_smp_processor_id() hard_smp_processor_id()
+#else
+extern int safe_smp_processor_id(void);
+#endif
+
extern int __cpu_disable(void);
extern void __cpu_die(unsigned int cpu);
#endif /* !__ASSEMBLY__ */
#else /* CONFIG_SMP */
+#define safe_smp_processor_id() 0
#define cpu_physical_id(cpu) boot_cpu_physical_apicid
#define NO_PROC_ID 0xFF /* No processor magic marker */
next reply other threads:[~2006-07-10 7:50 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-10 7:50 Fernando Luis Vázquez Cao [this message]
2006-07-10 8:27 ` [Fastboot] [PATCH 1/3] stack overflow safe kdump (2.6.18-rc1-i386) - safe_smp_processor_id Keith Owens
2006-07-10 10:15 ` Fernando Luis Vázquez Cao
2006-07-10 11:37 ` Eric W. Biederman
2006-07-11 4:21 ` Fernando Luis Vázquez Cao
2006-07-11 4:44 ` Fernando Luis Vázquez Cao
2006-07-11 4:55 ` Keith Owens
2006-07-11 6:15 ` Fernando Luis Vázquez Cao
2006-07-11 6:25 ` Keith Owens
2006-07-10 12:04 ` Keith Owens
2006-07-11 6:40 ` Fernando Luis Vázquez Cao
2006-07-10 14:16 ` James Bottomley
2006-07-10 18:20 ` Eric W. Biederman
2006-07-10 20:58 ` James Bottomley
2006-07-11 3:42 ` Eric W. Biederman
2006-07-11 12:36 ` James Bottomley
2006-07-11 19:41 ` Eric W. Biederman
2006-07-11 6:21 ` [Fastboot] " Fernando Luis Vázquez Cao
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=1152517852.2120.107.camel@localhost.localdomain \
--to=fernando@oss.ntt.co.jp \
--cc=James.Bottomley@steeleye.com \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=ebiederm@xmission.com \
--cc=fastboot@lists.osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vgoyal@in.ibm.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