Re: Help with git

2014-08-08 Thread Nuno Martins
On Fri, Aug 8, 2014 at 6:04 PM, Nick Krause  wrote:

> On Thu, Aug 7, 2014 at 11:13 PM, Nick Krause  wrote:
> > On Thu, Aug 7, 2014 at 11:05 PM,   wrote:
> >> On Thu, 07 Aug 2014 22:25:06 -0400, Nick Krause said:
> >>
> >>> 1. git clone linux-next
> >>
> >> Before you do the git add, you *really* want to create a branch for
> >> yourself to work on.
> >>
> >>> 2. git add file changed
> >>
> >> Because otherwise this will get dumped on one of 200+ linux-next
> branches
> >> and cause acute indigestion the next time you do a 'git remote update'.
> >
> >
> > That was stupid :(. Guess I known how to do it now.
> > Thanks Nick
>
>
> I am tried your idea and not working. Really weird, seems I am not
> using the correct commands.
> The commands I am using are
> 1.git branch next
> 2.git remote add -t master -f next
> git://git.kernel.org/pub/scm/linux/kernel/git/sfr/linux-next.git
>
> And that's it. I hit the git message of this,
>
> usage: git remote add []  
>
> -f, --fetch   fetch the remote branches
> --tagsimport all tags and associated objects when
> fetching
>   or do not fetch any tag at all (--no-tags)
> -t, --track   branch(es) to track
> -m, --master 
>   master branch
> --mirror[=]
>   set up remote as a mirror to push to or fetch
> from
> Nick
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>

I believe you didn't add a name for that remote yet.

Probably you need to give it a name to that new remote (eg. nextremotename)

2.git remote add -t master -f next nextremotename
git://git.kernel.org/pub/scm/linux/kernel/git/sfr/linux-next.git

Cheers,
-- 
Nuno Martins
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Determining 32bit or 64bit OS from a running kernel module

2013-10-23 Thread Nuno Martins
Hi Saket,

At code level you can check the size of a long. If you are in 32 bit it
will be 4 bytes, if you are in 64 bit it will be 8 bytes.

Probably there will be better ways and functions already with this test.

If you want to check it you just have to include the file that has those
defines and put your code under a #if .

Best regards,
Nuno Martins



On Wed, Oct 23, 2013 at 6:46 AM, Saket Sinha wrote:

> Hi,
>
> I want to write a kernel module which depends on the kernel type (32 or 64
> bit). There are some lines of code which I want to be included in the
> module if and only if the kernel is 32 bit and some lines of code which
> should be included if kernel is 64 bit.
>
> Is there anything like #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) for
> this case ?
>
> I know we have CONFIG_X86_64 and CONFIG_X86_32 for  x86 architecture but
> how do I exactly check it in my module code?
>
> Regards,
>
> Saket Sinha
>
>
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>


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


Re: How to hook the system call?

2011-11-23 Thread Nuno Martins
On Wed, Nov 23, 2011 at 6:05 PM, Geraint Yang  wrote:
> Hi,
> I have tried the LSM framework,but when I make my module , I got
> "waining:'register_security' undefined", then I check security/security.c
> and found out that register_security is not exported ! So if I want to use
> this function ,I must hack kernel by exporting and recompiling kernel which
> is allowed for me.
> So ...well, it seems that LSM doesn't work for module without modifying the
> kernel source.
>
>
>
> On Thu, Nov 24, 2011 at 12:59 AM, Alexandru Juncu 
> wrote:
>>
>> On Wed, Nov 23, 2011 at 6:50 PM, Geraint Yang 
>> wrote:
>> > Hi,
>> > Thank all of you for helping me with problem!
>> > I don't want to modify my kernel source so I am trying to learn to use
>> > LSM
>> > security hook even though it seems that it couldn't hook all the system
>> > calls, I think it should be enough for me.
>> > Thanks again!
>>
>> I know that AppArmor can hock syscalls like read, write and memory
>> mapping and can deny or accept them. I am not sure if you can make it
>> do something else when hocked, but I know it has a script-like
>> configuration, so maybe you can take some other actions.
>
>

If you can hook the system calls, you could try KProbes, is a dynamic
instrumentation, that is used in Linux Kernel.
You could use a JProbe to "capture" the function parameters of the
instrumented function.

If you have KProbes in your kernel, you can create a module to
instrument the syscall  that you want.
Maybe it can be a starting point for you ...

Other projects that use KProbes are DProbes and SystemTap, you can
also give it a look.

>
> --
> Geraint Yang
> Tsinghua University Department of Computer Science and Technology
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>

-- 
Nuno Martins

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


Re: Obtaining a list of open sockets from "struct task_struct"

2011-11-11 Thread Nuno Martins
On Fri, Nov 11, 2011 at 4:03 PM, Vimal  wrote:
> Hi all,

Hey,

>
> I am trying to understand more about kernel data structures and I
> would like to know how to obtain a list of TCP/UDP sockets, starting
> from a "struct task_struct" variable "task".
>
> So far, I have understood the following:  Please correct me if I am wrong! :)
>
> - An open file descriptor is represented by a "struct file *" in the
> tasks's file table: task->files.fdt.fd
> - The file tables are organised as a linked list
> - The file table contains a structure fd_array, that is an array of
> "struct file *", each representing an open file
>
> But, almost all operations in the TCP code start from a "struct sock".
>  Are the "struct file" and "struct sock" somehow connected?

If you are sure that that file descriptor is a socket then you can
cast to struct socket, the field "void * private_data"  in struct file
[1] .

But not all file descriptors are sockets so you have a way to be sure
that you are dealing with a socket, you have a macro

#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)

that macro is in [2] .



[1] http://lxr.linux.no/#linux+v3.1/include/linux/fs.h#L983
[2] http://lxr.linux.no/#liinux+v3.1/include/linux/stat.h#L30

And the struct socket has a field that is of type struct sock, so its direct.
The trick is that the private_data field is the socket structure, that
knows all about the network part.


>
> Thanks,
> --
> Vimal
>

Glad to help, i have searched all that because i had a project that i
needed to know which file descriptors were sockets, so i had to search
this information, i hope it's now a little be clear to you.

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



-- 
Nuno Martins

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


Re: profiling functions called in interrupt context

2011-09-20 Thread Nuno Martins
On Tue, Sep 20, 2011 at 5:59 AM, Amit Nagal  wrote:

> On Tue, Sep 20, 2011 at 10:25 AM, rohan puri 
> wrote:
> >
> >
> > On Tue, Sep 20, 2011 at 10:13 AM, Amit Nagal 
> wrote:
> >>
> >> On Tue, Sep 20, 2011 at 10:05 AM, rohan puri 
> >> wrote:
> >> >
> >> >
> >> > On Tue, Sep 20, 2011 at 9:44 AM, Amit Nagal 
> >> > wrote:
> >> >>
> >> >> Hi ,
> >> >>
> >> >> i want to measure time spend in a callback function called from
> >> >> interrupt context .
> >> >> since the time spend will be in us / ns , what kernel apis can i use
> >> >> to measure it ?
> >> >>
> >> >> also since i want to use it in interrupt context  , kernel time
> >> >> measurement apis should not sleep .
> >> >> i am using embedded arm target , and tools like OProfile  are not
> >> >> available .
> >> >>
> >> >> can i be guided which  kernel time measurement apis shall i use to
> >> >> measure time in a interrupt callback ?
> >> >>
> >> >> Regards
> >> >> Amit Nagal
> >> >
> >> > For this you can make use of ftrace.
> >> >
> >> > Refer link
> http://www.mjmwired.net/kernel/Documentation/trace/ftrace.txt
> >> >
> >> > Regards,
> >> > Rohan
> >> >
> >>
> >> Tools like ftrace are not available to me in my embedded arm target .
> >> So i want to use kernel apis to deal with time measurement in
> >> interrupt context .
> >>
> >> Regards
> >> Amit Nagal
> >
> > Hi Amit,
> >
> > I think ftrace can be enabled and used on arm arch.
> > Please Refer http://www.omappedia.org/wiki/Installing_and_Using_Ftrace
> >
> > Regards,
> > Rohan
> >
>
> Ok ,  thanks for the link . i will try the same .
>

Couldn't use ktimer, it says that is a high resolution timer inside the
kernel, you could combine ktimer with kretprobe (you assing a function prior
to the calling of your function and another when finished ). It is a
instrumentation method inside the kernel.




>
> Regards
> Amit Nagal
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>



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


Re: faster way to find task

2011-07-11 Thread Nuno Martins
On Mon, Jul 11, 2011 at 5:34 PM, loody  wrote:

> Hi all:
>
>
> 2011/7/12 loody 
>
>> Dear all:
>> Is there faster way to find a give name of task?
>> for example, I have a thread, named "test", is there faster way to get the
>> task struct  by passing "test" to some kernel api?
>>
>>
>> --
>> Regards,
>>
> I found a way as below:
> for_each_process(task) {
> printk(“%s[%d]\n”, task->comm, task->pid);
> }
>
> But it is time-consuming to do so if I periodically want to know whether
> "test" exist or not.
> is there better way to do so?
>
>
>
If you have the thread pid you could find it really fast. By name i don't
know any function that could help you with that.
You could search [1,2] for functions that could help you with that.
If you are invoking from the thread you want, inside the kernel you can get
the current variable that points to ther current process.


 [1]  http://lxr.linux.no/linux+v2.6.39/kernel/pid.c#L426
 [2] struct task_struct<http://lxr.linux.no/linux+v2.6.39/+code=task_struct>*
find_task_by_vpid<http://lxr.linux.no/linux+v2.6.39/+code=find_task_by_vpid>
(pid_t <http://lxr.linux.no/linux+v2.6.39/+code=pid_t>
vnr<http://lxr.linux.no/linux+v2.6.39/+code=vnr>
);

Have a good work.


> --
> Regards,
>
> _______
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>


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


Re: KGDB problem at first breakpoint

2011-05-18 Thread Nuno Martins
On Wed, May 18, 2011 at 12:23 PM, Prabhu nath  wrote:
> Dear All,
>        There is a problem with the KGDB at the very first break point after
> executing the gdb command "target remote /dev/ttyS0" from the host.
>        I have verbatim, followed the KGDB
> document http://kernel.org/pub/linux/kernel/people/jwessel/kdb/
> Problem Logs:
> -
> Details  of my hardware and system software:
> ---
> Host (Development machine):
>                       Intel Pentium IV Machine with Fedora Core 12
>                       Linux Version : 2.6.31.5-127.fc12.i686.PAE
>                       gdb version : GNU gdb (GDB) Fedora (7.0-3.fc12)
> Target:
>                  Intel Pentium IV Machine with Fedora Core 12
>                  Customized Linux Version :  2.6.38
> Host is connected to Target via a null modem cable
> Snapshot of .config of linux version 2.6.38 on the target
> # CONFIG_DEBUG_RODATA is not set
> CONFIG_HAVE_ARCH_KGDB=y
> CONFIG_FRAME_POINTER=y
> CONFIG_DEBUG_INFO=y
> CONFIG_KGDB=y
> CONFIG_KGDB_SERIAL_CONSOLE=y
> CONFIG_KGDB_LOW_LEVEL_TRAP=y
> Grub config on the target machine
> title Fedora (2.6.38)
>         root (hd0,0)
>         kernel /boot/vmlinuz-2.6.38 ro
> root=UUID=fb7800fb-cfe7-438d-bc7f-c153ba4353d1  LANG=en_US.UTF-8
> SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=usconsole=ttyS0,115200n8
> kgdboc=ttyS0 kgdbwait
>         initrd /boot/initrd-2.6.38.img
Do you have other serial line that you can connect to ? If you have
you could try to connect the console or the kgdboc to other serial
line.
This way you can have each on it's private serial line. I don't know
if it can multiplex the signal.

>
> On power on of the target, linux kernel boots and the logs are seen on the
> minicom console of the host and it will wait for the gdb on the host to
> connect. Here is the last 4 lines of the logs seen on the minicom
> Serial: 8250/16550 driver, 4 ports, IRQ sharing disabled
> serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
> 00:06: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
> kgdb: Registered I/O driver kgdboc.
> kgdb: Waiting for connection from remote gdb..
> --- Now I close the minicom console (Ctrl-A X) and start the gdb on the
> host. Here is the steps I follow.
> On the host machine:
>
> [root@localhost kgdb]# gdb vmlinux
> GNU gdb (GDB) Fedora (7.0-3.fc12)
> Copyright (C) 2009 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later
> <http://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
> and "show warranty" for details.
> This GDB was configured as "i686-redhat-linux-gnu".
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/gdb/bugs/>...
> Reading symbols from /root/kgdb/vmlinux...done.
> (gdb) set remotebaud 115200
> (gdb) set debug remote 1
> (gdb) target remote /dev/ttyS0
> Remote debugging using /dev/ttyS0
> Sending packet: $qSupported#37...Ack
> Packet received:
> Packet qSupported (supported-packets) is NOT supported
> Sending packet: $Hg0#df...Ack
> Packet received: OK
> Sending packet: $?#3f...Ack
> Packet received: S05
> Sending packet: $Hc-1#09...Ack
> Packet received: OK
> Sending packet: $qC#b4...Ack
> Packet received: QC01
> Sending packet: $qAttached#8f...Ack
> Packet received:
> Packet qAttached (query-attached) is NOT supported
> Sending packet: $qOffsets#4b...Ack
> Packet received:
> Sending packet: $g#67...Ack
> Packet received:
> 36000aba20d98bc06c3f86de783f86de803ac8dd803f86de885747c00202600068007b00c8dd7b0086de
> Sending packet: $mc0475788,1#a4...Ack
> Packet received: 0f
> Sending packet: $mc0475788,8#ab...Ack
> Packet received: 0faef889f6ff0d08
> Sending packet: $mc0475788,7#aa...Ack
> Packet received: 0faef889f6ff0d
> 0xc0475788 in ?? ()
> Sending packet: $qSymbol::#5b...Ack
> Packet received:
> Packet qSymbol (symbol-lookup) is NOT supported
> (gdb) s
> Cannot find bounds of current function
> (gdb)
>
> Observation:
>                      1. Ideally the kernel being debugged should break at
> legitimate address and the corresponding line number should
>                          be displayed instead of " 0xc0475788 in ?? ()".
>                      2. On inspecting section header in vmlinux executable,
> I found the .text section address range is from
>                          0xC100 to 0xC1326e58  and no section's contents
> associate with the address 0xC0475788.
>           

Re: how to detect a user who changed a particular file in Linux.

2011-05-17 Thread Nuno Martins
On Tue, May 17, 2011 at 11:31 AM, V.Ravikumar
 wrote:
>
>
> On Mon, May 16, 2011 at 7:45 PM, Greg KH  wrote:
>>
>> On Mon, May 16, 2011 at 03:02:10PM +0530, V.Ravikumar wrote:
>> >
>> > Hi all,
>> >
>> > (Note : I'm writing this mail to this kernel group as I did not find any
>> > suitable mechanism in application level for my below need).
>> >
>> > If a  file modified by some user then how can we detect that user who 
>> > modified
>> > it.
>> >
>> > Linux audit was not suitable for my need.
>>
>> Why not?  It should have showed you this exactly.
>>
>
> For my need, I have to asynchronously notify  if a given file was modified by 
> some user using some program.
>
> As per my understanding for audit , one has to update system specific audit 
> configuration files(say using some auditd related command line tools) with 
> given  file and it is not suitable for my requirement.
>
> Is there any other ways apart from using SystemTap and auditd command line 
> tools.
>
> Thanks for all your suggestions so far.

Have you considered using KProbes or tracepoints ?
For KProbes you do write some kernel module to monitor the function
you want. You have to be carefull not to try to monitor inlined
functions.
You could try to combine the use of KProbes with KThreads or
usermode-helper process.

It is just a thought.


>
> Regards,
> Ravikumar
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
--
Nuno Martins

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