2007-06-06 20:48:09

by Ian McDonald

[permalink] [raw]
Subject: [BUG] Fwd: segfault : modprobe dccp_probe/tcp_probe

Hi there,

We've seen a report of a problem with dccp_probe as shown below. The
user has also verified that it occurs in tcp_probe as well. This is on
Dave Miller's tree but that currently tracks Linus' tree quite
closely. I do note that it is around 2.6.22-rc2 timeframe so there is
a possibility fixes may have gone in since.

Ian

---------- Forwarded message ----------
From: Patrick Andrieux <[email protected]>
Date: Jun 6, 2007 1:07 AM
Subject: segfault : modprobe dccp_probe
To: Ian McDonald <[email protected]>, Arnaldo Carvalho de Melo
<[email protected]>
Cc: [email protected]


Hi,

I have a segfault when inserting dccp_probe module on Dave Miller's
tree *without* Ian's patches. I got it using this cmd line :
#git-clone git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6.git davem

Please find my .config in attachement.
I'm working on Debian testing (lenny).

config :
---------------- ---------------- -----------------
| dccpClient |----------| netembox |----------| dccpServer |
---------------- ---------------- -----------------


dccpServer # uname -a
Linux dccpServer 2.6.22-rc2final-dccp #1 PREEMPT Tue May 29
18:16:08 IST 2007 i686 GNU/Linux

dccpClient # uname -a
Linux dccpClient 2.6.22-rc2final-dccp #1 PREEMPT Tue May 29
18:16:08 IST 2007 i686 GNU/Linux


script I use when testing with CCID3:
#! /bin/sh

#modprobe dccp
modprobe dccp_ccid3
sysctl -w net.dccp.default.seq_window=10000
sysctl -w net.dccp.default.send_ackvec=0
sysctl -w net.dccp.default.rx_ccid=3
sysctl -w net.dccp.default.tx_ccid=3
sysctl -w net.dccp.default.tx_qlen=5


dccpServer # modprobe dccp_probe
Segmentation fault
dccpServer # ls -l /proc/net/dccpprobe
-r-------- 1 root root 0 2007-06-05 12:31 /proc/net/dccpprobe


/etc/log/syslog :
Jun 5 12:19:55 dccpServer kernel: [ 609.085205] CCID: Registered
CCID 3 (ccid3)
Jun 5 12:26:55 dccpServer kernel: [ 1027.751606] BUG: unable to
handle kernel paging request at virtual address c0316c18
Jun 5 12:26:55 dccpServer kernel: [ 1027.751614] printing eip:
Jun 5 12:26:55 dccpServer kernel: [ 1027.751616] c0320687
Jun 5 12:26:55 dccpServer kernel: [ 1027.751618] *pde = 1fe5d163
Jun 5 12:26:55 dccpServer kernel: [ 1027.751620] *pte = 00316161
Jun 5 12:26:55 dccpServer kernel: [ 1027.751624] Oops: 0003 [#1]
Jun 5 12:26:55 dccpServer kernel: [ 1027.751625] PREEMPT
Jun 5 12:26:55 dccpServer kernel: [ 1027.751628] Modules linked in:
dccp_probe dccp_ccid3 dccp_tfrc_lib ppdev lp af_packet snd_intel8x0
snd_ac97_codec ac97_bus snd_pcm_oss snd_mixer_oss mousedev snd_pcm
snd_
timer evdev parport_pc parport snd soundcore psmouse pcspkr rtc usbhid
snd_page_alloc intel_agp agpgart floppy ehci_hcd tg3 uhci_hcd usbcore
thermal processor fan unix
Jun 5 12:26:55 dccpServer kernel: [ 1027.751657 ] CPU: 0
Jun 5 12:26:55 dccpServer kernel: [ 1027.751658] EIP:
0060:[<c0320687>] Not tainted VLI
Jun 5 12:26:55 dccpServer kernel: [ 1027.751659] EFLAGS: 00210246
(2.6.22-rc2final-dccp #1)
Jun 5 12:26:55 dccpServer kernel: [ 1027.751666] EIP is at
arch_arm_kprobe+0x6/0xb
Jun 5 12:26:55 dccpServer kernel: [ 1027.751669] eax: c0316c18 ebx:
00000000 ecx: e5f74000 edx: 00000000
Jun 5 12:26:55 dccpServer kernel: [ 1027.751672] esi: f8a25740 edi:
00000000 ebp: e5f74ea0 esp: e5f74ea0
Jun 5 12:26:55 dccpServer kernel: [ 1027.751675] ds: 007b es: 007b
fs: 0000 gs: 0033 ss: 0068
Jun 5 12:26:55 dccpServer kernel: [ 1027.751679] Process modprobe
(pid: 4889, ti=e5f74000 task=e5ae6a80 task.ti=e5f74000 )
Jun 5 12:26:55 dccpServer kernel: [ 1027.751681] Stack: e5f74eb4
c0321921 fffffff4 efa1c498 efa1c6b4 e5f74ebc c0321994 e5f74ed0
Jun 5 12:26:55 dccpServer kernel: [ 1027.751690] f8a27076
c01220c0 ffffffff efa1c684 e5f74fb0 c0137d1f 00000002 00000000
Jun 5 12:26:55 dccpServer kernel: [ 1027.751698] 00200246
00000000 0001b486 ee5379b8 f8a2580c 00000650 00200246 e65a9de4
Jun 5 12:26:55 dccpServer kernel: [ 1027.751707] Call Trace:
Jun 5 12:26:55 dccpServer kernel: [ 1027.751709] [<c0104d52>]
show_trace_log_lvl+0x1a/0x2f
Jun 5 12:26:55 dccpServer kernel: [ 1027.751714] [<c0104e04>]
show_stack_log_lvl+0x9d/0xa5
Jun 5 12:26:55 dccpServer kernel: [ 1027.751718] [<c0105006>]
show_registers+0x1fa/0x33b
Jun 5 12:26:55 dccpServer kernel: [ 1027.751722] [<c0105245>] die+0xfe/0x200
Jun 5 12:26:55 dccpServer kernel: [ 1027.751726] [<c03213ab>]
do_page_fault+0x436/0x509
Jun 5 12:26:55 dccpServer kernel: [ 1027.751730] [<c031fd4a>]
error_code+0x6a/0x70
Jun 5 12:26:55 dccpServer kernel: [ 1027.751733] [<c0321921>]
__register_kprobe+0x23a/0x294
Jun 5 12:26:55 dccpServer kernel: [ 1027.751737] [<c0321994>]
register_jprobe+0x19/0x1b
Jun 5 12:26:55 dccpServer kernel: [ 1027.751741] [<f8a27076>]
dccpprobe_init+0x76/0xb4 [dccp_probe]
Jun 5 12:26:55 dccpServer kernel: [ 1027.751747] [<c0137d1f>]
sys_init_module+0x12d5/0x1415
Jun 5 12:26:55 dccpServer kernel: [ 1027.751753] [<c0103db2>]
sysenter_past_esp+0x5f/0x99
Jun 5 12:26:55 dccpServer kernel: [ 1027.751756] =======================
Jun 5 12:26:55 dccpServer kernel: [ 1027.751758] Code: 07 83 f8 02 75
15 eb 07 bb 01 00 00 00 eb 0c a1 2c 4b 41 c0 e8 f7 bc de ff 09 c3 83
c4 10 89 d8 5b 5e 5f 5d c3 55 8b 40 18 89 e5 <c6> 00 cc 5d c3 55 8b
50 18 89 e5 8a 40 34 88 02 5d c3 a3 20 cb
Jun 5 12:26:55 dccpServer kernel: [ 1027.751797] EIP: [<c0320687>]
arch_arm_kprobe+0x6/0xb SS:ESP 0068:e5f74ea0
Jun 5 12:26:55 dccpServer kernel: [ 1027.751806] BUG: sleeping
function called from invalid context at kernel/rwsem.c:20
Jun 5 12:26:55 dccpServer kernel: [ 1027.751809] in_atomic():0,
irqs_disabled():1
Jun 5 12:26:55 dccpServer kernel: [ 1027.751812] INFO: lockdep is turned off.
Jun 5 12:26:55 dccpServer kernel: [ 1027.751814] irq event stamp: 4018
Jun 5 12:26:55 dccpServer kernel: [ 1027.751815] hardirqs last
enabled at (4017): [<c031fa9d>] _spin_unlock_irqrestore+0x36/0x59
Jun 5 12:26:55 dccpServer kernel: [ 1027.751821] hardirqs last
disabled at (4018): [<c031f77f>] _spin_lock_irqsave+0x12/0x4e
Jun 5 12:26:55 dccpServer kernel: [ 1027.751825] softirqs last
enabled at (4002): [<c011bef6>] __do_softirq+0xa3/0xa8
Jun 5 12:26:55 dccpServer kernel: [ 1027.751831] softirqs last
disabled at (3993): [<c0105daa>] do_softirq+0x5b/0xc9
Jun 5 12:26:55 dccpServer kernel: [ 1027.751836] [<c0104d52>]
show_trace_log_lvl+0x1a/0x2f
Jun 5 12:26:55 dccpServer kernel: [ 1027.751840] [<c0105845>]
show_trace+0x12/0x14
Jun 5 12:26:55 dccpServer kernel: [ 1027.751843] [<c01058cb>]
dump_stack+0x15/0x17
Jun 5 12:26:55 dccpServer kernel: [ 1027.751847] [<c0114420>]
__might_sleep+0xc7/0xcd
Jun 5 12:26:55 dccpServer kernel: [ 1027.751850] [<c0129d91>]
down_read+0x18/0x4b
Jun 5 12:26:55 dccpServer kernel: [ 1027.751854] [<c0139f71>]
acct_collect+0x3a/0x135
Jun 5 12:26:55 dccpServer kernel: [ 1027.751858] [<c011a4d5>]
do_exit+0x1b2/0x6b1
Jun 5 12:26:55 dccpServer kernel: [ 1027.751862] [<c0105321>] die+0x1da/0x200
Jun 5 12:26:55 dccpServer kernel: [ 1027.751866] [<c03213ab>]
do_page_fault+0x436/0x509
Jun 5 12:26:55 dccpServer kernel: [ 1027.751869] [<c031fd4a>]
error_code+0x6a/0x70
Jun 5 12:26:55 dccpServer kernel: [ 1027.751873] [<c0321921>]
__register_kprobe+0x23a/0x294
Jun 5 12:26:55 dccpServer kernel: [ 1027.751876] [<c0321994>]
register_jprobe+0x19/0x1b
Jun 5 12:26:55 dccpServer kernel: [ 1027.751880] [<f8a27076>]
dccpprobe_init+0x76/0xb4 [dccp_probe]
Jun 5 12:26:55 dccpServer kernel: [ 1027.751885] [<c0137d1f>]
sys_init_module+0x12d5/0x1415
Jun 5 12:26:55 dccpServer kernel: [ 1027.751890 ] [<c0103db2>]
sysenter_past_esp+0x5f/0x99
Jun 5 12:26:55 dccpServer kernel: [ 1027.751893] =======================

Let me know if you need anything else.

rgds,
Patrick.



--
Web: http://wand.net.nz/~iam4/
Blog: http://iansblog.jandi.co.nz
WAND Network Research Group


Attachments:
(No filename) (7.70 kB)
config-2.6.22-rc2final-dccp (52.18 kB)
Download all attachments

2007-06-06 22:56:26

by Chuck Ebbert

[permalink] [raw]
Subject: Re: [BUG] Fwd: segfault : modprobe dccp_probe/tcp_probe

On 06/06/2007 04:47 PM, Ian McDonald wrote:
> Hi there,
>
> We've seen a report of a problem with dccp_probe as shown below. The
> user has also verified that it occurs in tcp_probe as well. This is on
> Dave Miller's tree but that currently tracks Linus' tree quite
> closely. I do note that it is around 2.6.22-rc2 timeframe so there is
> a possibility fixes may have gone in since.
>

It faulted when it tried to write the breakpoint instruction into the
running kernel's executable code. Apparently the kernel code is now marked
read-only?

2007-06-06 23:12:43

by Ian McDonald

[permalink] [raw]
Subject: Re: [BUG] Fwd: segfault : modprobe dccp_probe/tcp_probe

On 6/7/07, Chuck Ebbert <[email protected]> wrote:
> On 06/06/2007 04:47 PM, Ian McDonald wrote:
> > Hi there,
> >
> > We've seen a report of a problem with dccp_probe as shown below. The
> > user has also verified that it occurs in tcp_probe as well. This is on
> > Dave Miller's tree but that currently tracks Linus' tree quite
> > closely. I do note that it is around 2.6.22-rc2 timeframe so there is
> > a possibility fixes may have gone in since.
> >
>
> It faulted when it tried to write the breakpoint instruction into the
> running kernel's executable code. Apparently the kernel code is now marked
> read-only?
>
>
Yes it would appear to be the case as user has CONFIG_DEBUG_RODATA
set. Patrick - can you turn this off and retest? It's under Kernel
Hacking, Write protect kernel read only data structures.

The list of commits that I see around this are at:
http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git&a=search&h=HEAD&st=commit&s=DEBUG_RODATA

I suspect it's probably one of the latter ones giving the timing.

I guess there are a couple of solutions here - either make kprobes
conflict with CONFIG_DEBUG_RODATA so you can do one or the other, or
look into more detail what access kprobes need.

Ian
--
Web: http://wand.net.nz/~iam4/
Blog: http://iansblog.jandi.co.nz
WAND Network Research Group

2007-06-07 04:22:12

by S. P. Prasanna

[permalink] [raw]
Subject: Re: [PATCH] Kprobes i386 fix for mark ro data

On Thu, Jun 07, 2007 at 11:12:32AM +1200, Ian McDonald wrote:
> On 6/7/07, Chuck Ebbert <[email protected]> wrote:
> >On 06/06/2007 04:47 PM, Ian McDonald wrote:
> >> Hi there,
> >>
> >> We've seen a report of a problem with dccp_probe as shown below. The
> >> user has also verified that it occurs in tcp_probe as well. This is on
> >> Dave Miller's tree but that currently tracks Linus' tree quite
> >> closely. I do note that it is around 2.6.22-rc2 timeframe so there is
> >> a possibility fixes may have gone in since.
> >>
> >
> >It faulted when it tried to write the breakpoint instruction into the
> >running kernel's executable code. Apparently the kernel code is now marked
> >read-only?
> >
> >
> Yes it would appear to be the case as user has CONFIG_DEBUG_RODATA
> set. Patrick - can you turn this off and retest? It's under Kernel
> Hacking, Write protect kernel read only data structures.
>
> The list of commits that I see around this are at:
> http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git&a=search&h=HEAD&st=commit&s=DEBUG_RODATA
>
> I suspect it's probably one of the latter ones giving the timing.
>
> I guess there are a couple of solutions here - either make kprobes
> conflict with CONFIG_DEBUG_RODATA so you can do one or the other, or
> look into more detail what access kprobes need.
>
> Ian

Ian,

Please find the fix as suggested by Andi Kleen
for the above stated problem.

Thanks
Prasanna


This patch fixes the problem of page protection introduced by
CONFIG_DEBUG_RODATA. CONFIG_DEBUG_RODATA marks the text pages as
read-only, hence kprobes is unable to insert breakpoints in the
kernel text. This patch overrides the page protection when adding
or removing a probe for the i386 architecture.

Signed-off-by: Prasanna S P<[email protected]>
Ack-ed-by: Jim Keniston <[email protected]>



arch/i386/kernel/kprobes.c | 26 ++++++++++++++++++++++++++
arch/i386/mm/init.c | 2 ++
include/asm-i386/kprobes.h | 12 ++++++++++++
include/asm-i386/pgtable.h | 2 ++
4 files changed, 42 insertions(+)

diff -puN arch/i386/kernel/kprobes.c~kprobes-mark-ro-data-fix-i386 arch/i386/kernel/kprobes.c
--- linux-2.6.22-rc2/arch/i386/kernel/kprobes.c~kprobes-mark-ro-data-fix-i386 2007-06-07 09:19:26.000000000 +0530
+++ linux-2.6.22-rc2-prasanna/arch/i386/kernel/kprobes.c 2007-06-07 09:19:26.000000000 +0530
@@ -169,16 +169,42 @@ int __kprobes arch_prepare_kprobe(struct

void __kprobes arch_arm_kprobe(struct kprobe *p)
{
+ unsigned long addr = (unsigned long) p->addr;
+ int page_readonly = 0;
+
+ if (kernel_readonly_text(addr)) {
+ page_readonly = 1;
+ change_page_attr(virt_to_page(addr), 1, PAGE_KERNEL_RWX);
+ global_flush_tlb();
+ }
+
*p->addr = BREAKPOINT_INSTRUCTION;
flush_icache_range((unsigned long) p->addr,
(unsigned long) p->addr + sizeof(kprobe_opcode_t));
+
+ if (page_readonly) {
+ change_page_attr(virt_to_page(addr), 1, PAGE_KERNEL_RX);
+ global_flush_tlb();
+ }
}

void __kprobes arch_disarm_kprobe(struct kprobe *p)
{
+ unsigned long addr = (unsigned long) p->addr;
+ int page_readonly = 0;
+
+ if (kernel_readonly_text(addr)) {
+ page_readonly = 1;
+ change_page_attr(virt_to_page(addr), 1, PAGE_KERNEL_RWX);
+ global_flush_tlb();
+ }
*p->addr = p->opcode;
flush_icache_range((unsigned long) p->addr,
(unsigned long) p->addr + sizeof(kprobe_opcode_t));
+ if (page_readonly) {
+ change_page_attr(virt_to_page(addr), 1, PAGE_KERNEL_RX);
+ global_flush_tlb();
+ }
}

void __kprobes arch_remove_kprobe(struct kprobe *p)
diff -puN include/asm-i386/kprobes.h~kprobes-mark-ro-data-fix-i386 include/asm-i386/kprobes.h
--- linux-2.6.22-rc2/include/asm-i386/kprobes.h~kprobes-mark-ro-data-fix-i386 2007-06-07 09:19:26.000000000 +0530
+++ linux-2.6.22-rc2-prasanna/include/asm-i386/kprobes.h 2007-06-07 09:19:26.000000000 +0530
@@ -26,6 +26,8 @@
*/
#include <linux/types.h>
#include <linux/ptrace.h>
+#include <linux/pfn.h>
+#include <asm-generic/sections.h>

#define __ARCH_WANT_KPROBES_INSN_SLOT

@@ -90,4 +92,14 @@ static inline void restore_interrupts(st

extern int kprobe_exceptions_notify(struct notifier_block *self,
unsigned long val, void *data);
+extern int kernel_text_is_ro;
+static inline int kernel_readonly_text(unsigned long address)
+{
+
+ if (kernel_text_is_ro && ((address >= PFN_ALIGN(_text))
+ && (address < PFN_ALIGN(_etext))))
+ return 1;
+
+ return 0;
+}
#endif /* _ASM_KPROBES_H */
diff -puN include/asm-i386/pgtable.h~kprobes-mark-ro-data-fix-i386 include/asm-i386/pgtable.h
--- linux-2.6.22-rc2/include/asm-i386/pgtable.h~kprobes-mark-ro-data-fix-i386 2007-06-07 09:19:26.000000000 +0530
+++ linux-2.6.22-rc2-prasanna/include/asm-i386/pgtable.h 2007-06-07 09:19:26.000000000 +0530
@@ -159,6 +159,7 @@ void paging_init(void);
extern unsigned long long __PAGE_KERNEL, __PAGE_KERNEL_EXEC;
#define __PAGE_KERNEL_RO (__PAGE_KERNEL & ~_PAGE_RW)
#define __PAGE_KERNEL_RX (__PAGE_KERNEL_EXEC & ~_PAGE_RW)
+#define __PAGE_KERNEL_RWX (__PAGE_KERNEL_EXEC | _PAGE_RW)
#define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD)
#define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
#define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
@@ -167,6 +168,7 @@ extern unsigned long long __PAGE_KERNEL,
#define PAGE_KERNEL_RO __pgprot(__PAGE_KERNEL_RO)
#define PAGE_KERNEL_EXEC __pgprot(__PAGE_KERNEL_EXEC)
#define PAGE_KERNEL_RX __pgprot(__PAGE_KERNEL_RX)
+#define PAGE_KERNEL_RWX __pgprot(__PAGE_KERNEL_RWX)
#define PAGE_KERNEL_NOCACHE __pgprot(__PAGE_KERNEL_NOCACHE)
#define PAGE_KERNEL_LARGE __pgprot(__PAGE_KERNEL_LARGE)
#define PAGE_KERNEL_LARGE_EXEC __pgprot(__PAGE_KERNEL_LARGE_EXEC)
diff -puN arch/i386/mm/init.c~kprobes-mark-ro-data-fix-i386 arch/i386/mm/init.c
--- linux-2.6.22-rc2/arch/i386/mm/init.c~kprobes-mark-ro-data-fix-i386 2007-06-07 09:19:26.000000000 +0530
+++ linux-2.6.22-rc2-prasanna/arch/i386/mm/init.c 2007-06-07 09:19:26.000000000 +0530
@@ -45,6 +45,7 @@
#include <asm/sections.h>
#include <asm/paravirt.h>

+int kernel_text_is_ro;
unsigned int __VMALLOC_RESERVE = 128 << 20;

DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
@@ -807,6 +808,7 @@ void mark_rodata_ro(void)
change_page_attr(virt_to_page(start),
size >> PAGE_SHIFT, PAGE_KERNEL_RX);
printk("Write protecting the kernel text: %luk\n", size >> 10);
+ kernel_text_is_ro = 1;
}

start += size;

_

2007-06-07 04:23:59

by S. P. Prasanna

[permalink] [raw]
Subject: Re: [PATCH] Kprobes x86_64 fix for mark ro data


This patch fixes the problem of page protection introduced by
CONFIG_DEBUG_RODATA for x86_64 architecture. As per Andi
Kleen's suggestion, the kernel text pages are marked writeable
only for a short duration to insert or remove the breakpoints.

Signed-off-by: Prasanna S P<[email protected]>
Ack-ed-by: Jim Keniston <[email protected]>


arch/x86_64/kernel/kprobes.c | 26 ++++++++++++++++++++++++++
arch/x86_64/mm/init.c | 6 +++++-
include/asm-x86_64/kprobes.h | 10 ++++++++++
3 files changed, 41 insertions(+), 1 deletion(-)

diff -puN arch/x86_64/kernel/kprobes.c~kprobes-mark-ro-data-fix-x86_64 arch/x86_64/kernel/kprobes.c
--- linux-2.6.22-rc2/arch/x86_64/kernel/kprobes.c~kprobes-mark-ro-data-fix-x86_64 2007-06-07 09:20:33.000000000 +0530
+++ linux-2.6.22-rc2-prasanna/arch/x86_64/kernel/kprobes.c 2007-06-07 09:20:33.000000000 +0530
@@ -209,16 +209,42 @@ static void __kprobes arch_copy_kprobe(s

void __kprobes arch_arm_kprobe(struct kprobe *p)
{
+ unsigned long addr = (unsigned long)p->addr;
+ int page_readonly = 0;
+
+ if (kernel_readonly_text(addr)) {
+ change_page_attr_addr(addr, 1, PAGE_KERNEL_EXEC);
+ global_flush_tlb();
+ page_readonly = 1;
+ }
*p->addr = BREAKPOINT_INSTRUCTION;
flush_icache_range((unsigned long) p->addr,
(unsigned long) p->addr + sizeof(kprobe_opcode_t));
+ if (page_readonly) {
+ change_page_attr_addr(addr, 1, PAGE_KERNEL_RO);
+ global_flush_tlb();
+ }
}

void __kprobes arch_disarm_kprobe(struct kprobe *p)
{
+ unsigned long addr = (unsigned long)p->addr;
+ int page_readonly = 0;
+
+ if (kernel_readonly_text(addr)) {
+ change_page_attr_addr(addr, 1, PAGE_KERNEL_EXEC);
+ global_flush_tlb();
+ page_readonly = 1;
+ }
+
*p->addr = p->opcode;
flush_icache_range((unsigned long) p->addr,
(unsigned long) p->addr + sizeof(kprobe_opcode_t));
+
+ if (page_readonly) {
+ change_page_attr_addr(addr, 1, PAGE_KERNEL_RO);
+ global_flush_tlb();
+ }
}

void __kprobes arch_remove_kprobe(struct kprobe *p)
diff -puN include/asm-x86_64/kprobes.h~kprobes-mark-ro-data-fix-x86_64 include/asm-x86_64/kprobes.h
--- linux-2.6.22-rc2/include/asm-x86_64/kprobes.h~kprobes-mark-ro-data-fix-x86_64 2007-06-07 09:20:33.000000000 +0530
+++ linux-2.6.22-rc2-prasanna/include/asm-x86_64/kprobes.h 2007-06-07 09:20:33.000000000 +0530
@@ -26,6 +26,7 @@
#include <linux/types.h>
#include <linux/ptrace.h>
#include <linux/percpu.h>
+#include <asm-generic/sections.h>

#define __ARCH_WANT_KPROBES_INSN_SLOT

@@ -88,4 +89,13 @@ extern int kprobe_handler(struct pt_regs

extern int kprobe_exceptions_notify(struct notifier_block *self,
unsigned long val, void *data);
+extern int kernel_text_is_ro;
+static inline int kernel_readonly_text(unsigned long address)
+{
+ if (kernel_text_is_ro && ((address >= (unsigned long)_stext)
+ && (address < (unsigned long) _etext)))
+ return 1;
+
+ return 0;
+}
#endif /* _ASM_KPROBES_H */
diff -puN arch/x86_64/mm/init.c~kprobes-mark-ro-data-fix-x86_64 arch/x86_64/mm/init.c
--- linux-2.6.22-rc2/arch/x86_64/mm/init.c~kprobes-mark-ro-data-fix-x86_64 2007-06-07 09:20:33.000000000 +0530
+++ linux-2.6.22-rc2-prasanna/arch/x86_64/mm/init.c 2007-06-07 09:20:33.000000000 +0530
@@ -48,6 +48,7 @@
#define Dprintk(x...)
#endif

+int kernel_text_is_ro;
const struct dma_mapping_ops* dma_ops;
EXPORT_SYMBOL(dma_ops);

@@ -598,10 +599,13 @@ void mark_rodata_ro(void)
{
unsigned long start = (unsigned long)_stext, end;

+ kernel_text_is_ro = 1;
#ifdef CONFIG_HOTPLUG_CPU
/* It must still be possible to apply SMP alternatives. */
- if (num_possible_cpus() > 1)
+ if (num_possible_cpus() > 1) {
start = (unsigned long)_etext;
+ kernel_text_is_ro = 0;
+ }
#endif
end = (unsigned long)__end_rodata;
start = (start + PAGE_SIZE - 1) & PAGE_MASK;

_
--
Prasanna S.P.
Linux Technology Center
India Software Labs, IBM Bangalore
Email: [email protected]
Ph: 91-80-41776329

2007-06-07 10:24:26

by Patrick Andrieux

[permalink] [raw]
Subject: Re: [BUG] Fwd: segfault : modprobe dccp_probe/tcp_probe

Hi Ian,

Not sure it's still useful after patch provide by Prasanna...
But I tried to turn off CONFIG_DEBUG_RODATA and both `tcp_probe' and
`dccp_probe' can be load properly.
I also ran iperf test (for dccp) and it works.

Patrick.

On 07/06/07, Ian McDonald <[email protected]> wrote:
> On 6/7/07, Chuck Ebbert <[email protected]> wrote:
> > On 06/06/2007 04:47 PM, Ian McDonald wrote:
> > > Hi there,
> > >
> > > We've seen a report of a problem with dccp_probe as shown below. The
> > > user has also verified that it occurs in tcp_probe as well. This is on
> > > Dave Miller's tree but that currently tracks Linus' tree quite
> > > closely. I do note that it is around 2.6.22-rc2 timeframe so there is
> > > a possibility fixes may have gone in since.
> > >
> >
> > It faulted when it tried to write the breakpoint instruction into the
> > running kernel's executable code. Apparently the kernel code is now marked
> > read-only?
> >
> >
> Yes it would appear to be the case as user has CONFIG_DEBUG_RODATA
> set. Patrick - can you turn this off and retest? It's under Kernel
> Hacking, Write protect kernel read only data structures.
>
> The list of commits that I see around this are at:
> http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git&a=search&h=HEAD&st=commit&s=DEBUG_RODATA
>
> I suspect it's probably one of the latter ones giving the timing.
>
> I guess there are a couple of solutions here - either make kprobes
> conflict with CONFIG_DEBUG_RODATA so you can do one or the other, or
> look into more detail what access kprobes need.
>
> Ian
> --
> Web: http://wand.net.nz/~iam4/
> Blog: http://iansblog.jandi.co.nz
> WAND Network Research Group
>

2007-06-10 06:24:25

by Ian McDonald

[permalink] [raw]
Subject: Re: [PATCH] Kprobes i386 fix for mark ro data

On 6/7/07, S. P. Prasanna <[email protected]> wrote:
> > >It faulted when it tried to write the breakpoint instruction into the
> > >running kernel's executable code. Apparently the kernel code is now marked
> > >read-only?
> > >
> > >
> > Yes it would appear to be the case as user has CONFIG_DEBUG_RODATA
> > set. Patrick - can you turn this off and retest? It's under Kernel
> > Hacking, Write protect kernel read only data structures.
> >
>
> Ian,
>
> Please find the fix as suggested by Andi Kleen
> for the above stated problem.
>
> Thanks
> Prasanna
>
>
I went to test the fix and first of all went to replicate the problem.
My build has CONFIG_DEBUG_RODATA set but the problem does not occur
without the patch. Should I be concerned about this and raise a bug
for that as I would think that means there is a problem that the read
only protection isn't working (this is off Linus' tree synced
tonight).

Patrick - can you test whether this patch fixes your problem? You said
disabling CONFIG_DEBUG_RODATA fixed your problem but can you try
re-enabling and testing this patch?

Ian
--
Web: http://wand.net.nz/~iam4/
Blog: http://iansblog.jandi.co.nz
WAND Network Research Group

2007-06-11 18:36:51

by Patrick Andrieux

[permalink] [raw]
Subject: Re: [PATCH] Kprobes i386 fix for mark ro data

Hi,

This patch fixed my problem. I re-enabled CONFIG_DEBUG_RODATA and I
don't have seg fault with or without your DCCP patches. Inserting
`dccp_probe` or `tcp_probe`module doesn't cause any troubles.

Patrick.


On 10/06/07, Ian McDonald <[email protected]> wrote:
> On 6/7/07, S. P. Prasanna <[email protected]> wrote:
> > > >It faulted when it tried to write the breakpoint instruction into the
> > > >running kernel's executable code. Apparently the kernel code is now marked
> > > >read-only?
> > > >
> > > >
> > > Yes it would appear to be the case as user has CONFIG_DEBUG_RODATA
> > > set. Patrick - can you turn this off and retest? It's under Kernel
> > > Hacking, Write protect kernel read only data structures.
> > >
> >
> > Ian,
> >
> > Please find the fix as suggested by Andi Kleen
> > for the above stated problem.
> >
> > Thanks
> > Prasanna
> >
> >
> I went to test the fix and first of all went to replicate the problem.
> My build has CONFIG_DEBUG_RODATA set but the problem does not occur
> without the patch. Should I be concerned about this and raise a bug
> for that as I would think that means there is a problem that the read
> only protection isn't working (this is off Linus' tree synced
> tonight).
>
> Patrick - can you test whether this patch fixes your problem? You said
> disabling CONFIG_DEBUG_RODATA fixed your problem but can you try
> re-enabling and testing this patch?
>
> Ian
> --
> Web: http://wand.net.nz/~iam4/
> Blog: http://iansblog.jandi.co.nz
> WAND Network Research Group
>