Re: linux segment

2012-11-02 Thread Tobias Boege
On Tue, 30 Oct 2012, Fan Yang wrote:
 2012/10/29 Mulyadi Santosa mulyadi.sant...@gmail.com
 
  Hi Fan...
 
  On Sun, Oct 28, 2012 at 9:02 PM, Fan Yang lljyang...@gmail.com wrote:
  
   [root@shell--box kernel_mod]# dmesg -c
   **
   cs 60 96
   ds 7b 123
   ss 68 104
   es 7b 123
   fs d8 216
   gs e0 224
   **
  
   The cs and ds in the kernel space is 60 and 7b. But the kernel define the
   KERNEL_CS as 60 and the KERNEL_DS as 7b.  Where am I wrong?
  
 
 
  you print CS and DS twice, once during init and once during exit of
  your kernel module. So, which one do you want to confirm?
 
  All in all, I have a guess that you see such number (DS belongs to
  user space in kernel module) because IIRC kernel module loading is
  done using syscall and with the help of modprobe helper.
 
  Thus, it is important to access user space during that stage, hence DS
  still using user space data segment.
 
 
  --
  regards,
 
  Mulyadi Santosa
  Freelance Linux trainer and consultant
 
  blog: the-hydra.blogspot.com
  training: mulyaditraining.blogspot.com
 
 
 Hi  Mulyadi Santosa
I get the same result during the kernel module init and exit. Then I try
 to add a syscall to print these registers, and nothing changed. It is
 strange.

 ___
 Kernelnewbies mailing list
 Kernelnewbies@kernelnewbies.org
 http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

(Weird, this is the third time, I have to send this. If anybody gets this
message multiple times, I apologise but my mail is not in the archives.)

If Mulyadi is right and we need DS to be USER_DS to access user space (I
really don't know, sorry, but maybe there is something in your uaccess.h?)
then your attempt to try with a syscall couldn't yield other values because
one trait of syscalls is that they can access user space.

This means you would get DS = USER_DS precisely _because_ you are in a
syscall. Module init and exit are, too, just some stack frames above one and
thus fall into this category as well.

But shouldn't it be possible to register a timer and then print the
segment registers? Timers are fired in softirq context and, hence, have no
connection to user space.

Regards,
Tobi


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: linux segment

2012-10-31 Thread Mulyadi Santosa
On Tue, Oct 30, 2012 at 7:44 AM, Fan Yang lljyang...@gmail.com wrote:
 Hi  Mulyadi Santosa
I get the same result during the kernel module init and exit. Then I try
 to add a syscall to print these registers, and nothing changed. It is
 strange.

I think you need to observe deeper, something change this.

BTW, are you running this inside a virtualization? and which kernel
version do you use?

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: linux segment

2012-10-29 Thread Mulyadi Santosa
Hi Fan...

On Sun, Oct 28, 2012 at 9:02 PM, Fan Yang lljyang...@gmail.com wrote:

 [root@shell--box kernel_mod]# dmesg -c
 **
 cs 60 96
 ds 7b 123
 ss 68 104
 es 7b 123
 fs d8 216
 gs e0 224
 **

 The cs and ds in the kernel space is 60 and 7b. But the kernel define the
 KERNEL_CS as 60 and the KERNEL_DS as 7b.  Where am I wrong?



you print CS and DS twice, once during init and once during exit of
your kernel module. So, which one do you want to confirm?

All in all, I have a guess that you see such number (DS belongs to
user space in kernel module) because IIRC kernel module loading is
done using syscall and with the help of modprobe helper.

Thus, it is important to access user space during that stage, hence DS
still using user space data segment.


-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: linux segment

2012-10-28 Thread Fan Yang
2012/10/27 Jun Hu duanshui...@hotmail.com

   Can you post out your codes ?

  *From:* Fan Yang lljyang...@gmail.com
 *Sent:* Wednesday, October 24, 2012 8:04 PM
 *To:* kernelnewbies@kernelnewbies.org
 *Subject:* linux segment

 Hi all:
 I print the cs ds and ss register in the user space, and it is same as
 the __USER_CS and __USER_DS which defined in kernel as 73 and 7b. In the
 kernel __KERNEL_CS and __KERNEL_DS defined as 60 and 68, but when I print
 this two value in my kernel module, I get 60 and 7b. Why ? It should be 60
 and 68, shouldn't it?



 --
 ___
 Kernelnewbies mailing list
 Kernelnewbies@kernelnewbies.org
 http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

 Hi Jun Hu
There is my code which run at the user space:

  1 #includestdio.h
  2 main()
  3 {
  4 unsigned long cs, ds, ss, es, fs, gs;
  5 asm volatile(movl %%CS,%0\n\t:=r(cs));
  6 asm volatile(movl %%DS,%0\n\t:=r(ds));
  7 asm volatile(movl %%SS,%0\n\t:=r(ss));
  8 asm volatile(movl %%ES,%0\n\t:=r(es));

  9 asm volatile(movl %%FS,%0\n\t:=r(fs));
 10 asm volatile(movl %%GS,%0\n\t:=r(gs));
 11 printf (**\n);
 12 printf (cs %lx\t%ld\n, cs, cs);
 13 printf (ds %lx\t%ld\n, ds, ds);
 14 printf (ss %lx\t%ld\n, ss, ss);
 15 printf (es %lx\t%ld\n, es, es);
 16 printf (fs %lx\t%ld\n, fs, fs);
 17 printf (gs %lx\t%ld\n, gs, gs);
 18 printf (**\n);
 19 }



and the result of the progress in my machine is


**
cs 73 115
ds 7b 123
ss 7b 123
es 7b 123
fs 0 0
gs 33 51
**


so, you can see the cs and ds register is 73 and 7b which are same as the
kernel defined.  And the code of the kernel module is


 1 #includelinux/init.h

  2 #includelinux/kernel.h
  3 #includelinux/module.h
  4
  5 static void __init print_init (void)
  6 {
  7 unsigned long cs, ds, ss, es, fs, gs,currenttime;
  8 asm volatile(movl %%CS,%0\n\t:=r(cs));
  9 asm volatile(movl %%DS,%0\n\t:=r(ds));
 10 asm volatile(movl %%SS,%0\n\t:=r(ss));
 11 asm volatile(movl %%ES,%0\n\t:=r(es));
 12 asm volatile(movl %%FS,%0\n\t:=r(fs));
 13 asm volatile(movl %%GS,%0\n\t:=r(gs));
 14 printk (**\n);
 15 printk (cs %lx\t%ld\n, cs, cs);
 16 printk (ds %lx\t%ld\n, ds, ds);
 17 printk (ss %lx\t%ld\n, ss, ss);
 18 printk (es %lx\t%ld\n, es, es);
 19 printk (fs %lx\t%ld\n, fs, fs);
 20 printk (gs %lx\t%ld\n, gs, gs);
 21 printk (**\n);
 22
 23 }
24
 25 static void __exit print_exit (void)
 26 {
 27 unsigned long cs, ds, ss;
 28 asm volatile(movl %%cs,%0\n\t:=r(cs));
 29 asm volatile(movl %%ds,%0\n\t:=r(ds));
 30 asm volatile(movl %%ss,%0\n\t:=r(ss));
 31
 32 printk (**\n);
 33 printk (cs %lx\t%ld\n, cs, cs);
 34 printk (ds %lx\t%ld\n, ds, ds);
 35 printk (ss %lx\t%ld\n, ss, ss);
 36 printk (**\n);
 37 printk (*bye***\n);
 38 }
 39
 40 module_init (print_init);
 41 module_exit (print_exit);

 42 MODULE_LICENSE (GPL);


the result of the running this module is

[root@shell--box kernel_mod]# dmesg -c
**
cs 60 96
ds 7b 123
ss 68 104
es 7b 123
fs d8 216
gs e0 224
**

The cs and ds in the kernel space is 60 and 7b. But the kernel define the
 KERNEL_CS as 60 and the KERNEL_DS as 7b.  Where am I wrong?


Thanks
Fan
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: linux segment

2012-10-28 Thread Fan Yang
2012/10/28 Fan Yang lljyang...@gmail.com



 2012/10/27 Jun Hu duanshui...@hotmail.com

   Can you post out your codes ?

  *From:* Fan Yang lljyang...@gmail.com
 *Sent:* Wednesday, October 24, 2012 8:04 PM
 *To:* kernelnewbies@kernelnewbies.org
 *Subject:* linux segment

 Hi all:
 I print the cs ds and ss register in the user space, and it is same
 as the __USER_CS and __USER_DS which defined in kernel as 73 and 7b. In the
 kernel __KERNEL_CS and __KERNEL_DS defined as 60 and 68, but when I print
 this two value in my kernel module, I get 60 and 7b. Why ? It should be 60
 and 68, shouldn't it?



 --
 ___
 Kernelnewbies mailing list
 Kernelnewbies@kernelnewbies.org
 http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

 Hi Jun Hu
 There is my code which run at the user space:

   1 #includestdio.h
   2 main()
   3 {
   4 unsigned long cs, ds, ss, es, fs, gs;
   5 asm volatile(movl %%CS,%0\n\t:=r(cs));
   6 asm volatile(movl %%DS,%0\n\t:=r(ds));
   7 asm volatile(movl %%SS,%0\n\t:=r(ss));
   8 asm volatile(movl %%ES,%0\n\t:=r(es));

   9 asm volatile(movl %%FS,%0\n\t:=r(fs));
  10 asm volatile(movl %%GS,%0\n\t:=r(gs));
  11 printf (**\n);
  12 printf (cs %lx\t%ld\n, cs, cs);
  13 printf (ds %lx\t%ld\n, ds, ds);
  14 printf (ss %lx\t%ld\n, ss, ss);
  15 printf (es %lx\t%ld\n, es, es);
  16 printf (fs %lx\t%ld\n, fs, fs);
  17 printf (gs %lx\t%ld\n, gs, gs);
  18 printf (**\n);
  19 }



 and the result of the progress in my machine is


 **
 cs 73 115
 ds 7b 123
 ss 7b 123
 es 7b 123
 fs 0 0
 gs 33 51
 **


 so, you can see the cs and ds register is 73 and 7b which are same as the
 kernel defined.  And the code of the kernel module is


  1 #includelinux/init.h

   2 #includelinux/kernel.h
   3 #includelinux/module.h
   4
   5 static void __init print_init (void)
   6 {
   7 unsigned long cs, ds, ss, es, fs, gs,currenttime;
   8 asm volatile(movl %%CS,%0\n\t:=r(cs));
   9 asm volatile(movl %%DS,%0\n\t:=r(ds));
  10 asm volatile(movl %%SS,%0\n\t:=r(ss));
  11 asm volatile(movl %%ES,%0\n\t:=r(es));
  12 asm volatile(movl %%FS,%0\n\t:=r(fs));
  13 asm volatile(movl %%GS,%0\n\t:=r(gs));
  14 printk (**\n);
  15 printk (cs %lx\t%ld\n, cs, cs);
  16 printk (ds %lx\t%ld\n, ds, ds);
  17 printk (ss %lx\t%ld\n, ss, ss);
  18 printk (es %lx\t%ld\n, es, es);
  19 printk (fs %lx\t%ld\n, fs, fs);
  20 printk (gs %lx\t%ld\n, gs, gs);
  21 printk (**\n);
  22
  23 }
 24
  25 static void __exit print_exit (void)
  26 {
  27 unsigned long cs, ds, ss;
  28 asm volatile(movl %%cs,%0\n\t:=r(cs));
  29 asm volatile(movl %%ds,%0\n\t:=r(ds));
  30 asm volatile(movl %%ss,%0\n\t:=r(ss));
  31
  32 printk (**\n);
  33 printk (cs %lx\t%ld\n, cs, cs);
  34 printk (ds %lx\t%ld\n, ds, ds);
  35 printk (ss %lx\t%ld\n, ss, ss);
  36 printk (**\n);
  37 printk (*bye***\n);
  38 }
  39
  40 module_init (print_init);
  41 module_exit (print_exit);

  42 MODULE_LICENSE (GPL);


 the result of the running this module is

 [root@shell--box kernel_mod]# dmesg -c
 **
 cs 60 96
 ds 7b 123
 ss 68 104
 es 7b 123
 fs d8 216
 gs e0 224
 **

 The cs and ds in the kernel space is 60 and 7b. But the kernel define the
  KERNEL_CS as 60 and the KERNEL_DS as 7b.  Where am I wrong?


 Thanks
 Fan


sorry, the kernel define the KERNEL_DS as 68, but I get 7b in my machine.
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: linux segment

2012-10-27 Thread Jun Hu
Can you post out your codes ?

From: Fan Yang 
Sent: Wednesday, October 24, 2012 8:04 PM
To: kernelnewbies@kernelnewbies.org 
Subject: linux segment

Hi all: 
I print the cs ds and ss register in the user space, and it is same as the 
__USER_CS and __USER_DS which defined in kernel as 73 and 7b. In the kernel 
__KERNEL_CS and __KERNEL_DS defined as 60 and 68, but when I print this two 
value in my kernel module, I get 60 and 7b. Why ? It should be 60 and 68, 
shouldn't it? 






___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: linux segment

2012-10-26 Thread Mulyadi Santosa
On Wed, Oct 24, 2012 at 7:04 PM, Fan Yang lljyang...@gmail.com wrote:
 Hi all:
 I print the cs ds and ss register in the user space, and it is same as
 the __USER_CS and __USER_DS which defined in kernel as 73 and 7b. In the
 kernel __KERNEL_CS and __KERNEL_DS defined as 60 and 68, but when I print
 this two value in my kernel module, I get 60 and 7b. Why ? It should be 60
 and 68, shouldn't it?

you're not manually switch the data segment, aren't you?

-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


linux segment

2012-10-24 Thread Fan Yang
Hi all:
I print the cs ds and ss register in the user space, and it is same as
the __USER_CS and __USER_DS which defined in kernel as 73 and 7b. In the
kernel __KERNEL_CS and __KERNEL_DS defined as 60 and 68, but when I print
this two value in my kernel module, I get 60 and 7b. Why ? It should be 60
and 68, shouldn't it?
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies