Re: hook SIGSEGV

2014-05-14 Thread Kristof Provost
On 2014-05-10 21:46:01 (+0800), net.study@gmail.com 
net.study@gmail.com wrote:
  I want to know is it possible to hook SIGSEGV to restart the
  thread which the signal is sent to,without restart the whole
  process? And record the place where has caused this signal?
 
Yes, as others have already pointed out, you can hook SIGSEGV like any
other signal.

You're not going to be able to save the process any more, but you can
still collect some useful information.

I've found it very useful to have a SIGSEGV (and SIGPIPE, SIGABRT,
SIGFPE, SIGILL) handler which logs a backtrace (look at 'man backtrace')
to syslog. Very useful for debugging on targets where core dumps are
impractical.

Others have also pointed out that it might no longer be safe to call
printf() or malloc() there. That's true, but usually it's OK, and if it
turns out that it wasn't ... Well, you were crashing anyway.

Regards,
Kristof

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


a question on nocache pool address which seems to have ended up as a nice comment?

2014-05-14 Thread Chan Kim
Hi,
I was analyzing arch/sparc/mm/srmmu.c (linux 3.3)
In our system, the pgd table sits at c800 and the entry for c8000 is at 
c8000320. (upper 8 bits is the index and *4 is the index address)
previously, I got srmmu_nocache_pool = c054. Does anybody know why 
__nocache_fix(0xc8320) is c0540320?
This is equivalent to saying that nocache region 0xc800 is mapped to 
0xc054 which is physical address 0x6054.
I'm confused here..
I guess the virtual address 0xc800 which is in nocache region is rebased to 
previously allocated nocache physcial address 0x6054 which is then 
equivalent to virtual address 0xc054. Having said that, it sounds perfectly 
correct.
another example of realizing something while asking.. Correct me if I'm wrong.
regards,
Chan
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Deleting a line from a file

2014-05-14 Thread Saket Sinha
Hi,

I have a file that has entries for different absolute path on
separate lines. eg:
/opt/new1
/opt/new2

I need to delete an entry from this file for a given path, for which I
am using sed.

sed -i 's#^/opt/new1.*$##g' file_entries.txt

However this is leaving blank line in between, which I don't want.

Can someone help me to do this without leaving blank lines in between.

Regards,
Saket Sinha

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


Re: Deleting a line from a file

2014-05-14 Thread Bernd Petrovitsch
Hi!

The original mail is off-topic as it has nothing to do wotj the Linux
kernel development as such, but:

On Mit, 2014-05-14 at 19:58 +0530, Saket Sinha wrote:
[...]
 I have a file that has entries for different absolute path on
 separate lines. eg:
 /opt/new1
 /opt/new2
 
 I need to delete an entry from this file for a given path, for which I
 am using sed.
 
 sed -i 's#^/opt/new1.*$##g' file_entries.txt
 
 However this is leaving blank line in between, which I don't want.
 
 Can someone help me to do this without leaving blank lines in between.

sed -i 's#^/opt/new1.*$#d' file_entries.txt

should do it 

Bernd
-- 
Bernd Petrovitsch  Email : be...@petrovitsch.priv.at
 LUGA : http://www.luga.at


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


Re: Deleting a line from a file

2014-05-14 Thread Valdis . Kletnieks
On Wed, 14 May 2014 16:34:20 +0200, Bernd Petrovitsch said:

 sed -i 's#^/opt/new1.*$#d' file_entries.txt

You don't even need the leading 's'.   Just   /pattern/d   is sufficient.

(And you can even do stuff like   /pat1/,/pat2/s/old/new/   which will
change 'old' to 'new', but only from a line that contains pat1 up to a
line that contains pat2, and *not* changing it before pat1 or after pat2)



pgpAcbxZ3MSYc.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Deleting a line from a file

2014-05-14 Thread Saket Sinha
Please find my response inline-

On Wed, May 14, 2014 at 8:04 PM, Bernd Petrovitsch
be...@petrovitsch.priv.at wrote:
 Hi!

 The original mail is off-topic as it has nothing to do wotj the Linux
 kernel development as such, but:


I wanted to isolate the problem hence did not give the full context.
Actually I have written a file-system utility which mounts my
filesystem on a specific path and update it in /etc/fstab. When I
umount it, I delete the path from the /etc/fstab.


I had earlier written a C function to do that  but it is corrupting the fstab.
 SO now I am trying to run the above sed command this way
 system(sed -i 's#^/opt/new1.*$##g' /etc/fstab).


The C function that was currupting the filesystem is listed below -


int removeEntryFromFSTAB(const char * fullPath, const char * fileName)
{
 FILE *tabFileOld = NULL;
 FILE *tabFileNew = NULL;
 struct mntent *m;
 char newFileName[PATH_MAX];
 int rc = -1;

 tabFileOld = setmntent( fileName, r ); // Open for writing now
 if (tabFileOld == NULL )
   goto end;

 tabFileNew = setmntent(newFileName, w);
 if (tabFileNew == NULL )
   goto end;

 while ((m = getmntent(tabFileOld)) != NULL)
 {
  if (tcscmp(MY_FS_TYPE, m-mnt_type) == 0)
  {
  if ((tcscmp(fullPath, m-mnt_dir) == 0))
 continue;
  }
  if (addmntent(tabFileNew, m) != 0)
   goto end;
 }
 endmntent(tabFileOld);
 endmntent(tabFileNew);

 tabFileNew = NULL;
 tabFileOld = NULL;


 rename(newFileName, fileName))
 rc = 0;

 end:
  if (tabFileNew != NULL)
  endmntent(tabFileNew);

  if (tabFileOld != NULL)
  endmntent(tabFileOld);

  sync();
  return rc;
  }

Kindly let me know, if you think there is a better way.

Regards,
Saket Sinha

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


Re: Deleting a line from a file

2014-05-14 Thread Valdis . Kletnieks
On Wed, 14 May 2014 21:27:06 +0530, Saket Sinha said:

  char newFileName[PATH_MAX];

  tabFileNew = setmntent(newFileName, w);

And what is the new file name? You have random trash on the stack here.
(Note that this is C 101 - if you can't debug this on your own, you
probably shouldn't be messing with filesystem code until you have more
C experience)




pgpgfLmgh_JZL.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Deleting a line from a file

2014-05-14 Thread Saket Sinha
Please find response inline.

On Wed, May 14, 2014 at 9:44 PM,  valdis.kletni...@vt.edu wrote:
 On Wed, 14 May 2014 21:27:06 +0530, Saket Sinha said:

  char newFileName[PATH_MAX];

  tabFileNew = setmntent(newFileName, w);

 And what is the new file name? You have random trash on the stack here.

int removeEntryFromFSTAB(const char * fullPath, const char * fileName);
I am sending /etc/fstab in fileName to this function and the path to
be deleted in fullPath


NOW
 char newFileName[PATH_MAX];
..
...
 rename(newFileName, fileName));


I am taking a new file, writing my entries to it and then replacing it
with original file. I don't find anything wrong with that

 (Note that this is C 101 - if you can't debug this on your own, you
 probably shouldn't be messing with filesystem code until you have more
 C experience)

Sorry but I haven't been able to debug that. I admit it.

Regards,
Saket Sinha

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


Re: Deleting a line from a file

2014-05-14 Thread Valdis . Kletnieks
On Wed, 14 May 2014 22:13:51 +0530, Saket Sinha said:

 I am sending /etc/fstab in fileName to this function and the path to
 be deleted in fullPath

OK.

  char newFileName[PATH_MAX];

This lives on your function call stack. As such, it contains whatever
was in that memory until you change it.  And you never change it.

 tabFileOld = setmntent( fileName, r ); // Open for writing now

The comment indicates there's some confusion going on. Not a good sign

 tabFileNew = setmntent(newFileName, w);
 if (tabFileNew == NULL )
   goto end;

This probably doesn't do what you think it does.  What value of 'newFileName'
is used to create the new file?  For bonus points, what guarantees that
it points to an object that's on the same filesystem as your old filename?

(This will actually fail to throw an error as long as newFileName[0] isn't
a '\0'.  But that's different from actually working properly)

And you *really* want to get this issue well-understood before hacking kernel
code, as the kernel doesn't do very much error checking.  You make this sort of
error in kernel code, you will crash the machine - if you're lucky.  If you're
unlucky, the system will silently corrupt entire filesystems on you to the
point where fsck won't help.  (Want *real* debugging fun?  Get your system
to a state where /boot fsck's just fine, but something has silently overwritten
several data blocks in /boot/vmlinuz or /lib/ld-linux.so.  *That* will keep
you busy for a while.. :)

  if (tcscmp(MY_FS_TYPE, m-mnt_type) == 0)

You want to use strncmp() or similar here.  And you want to learn why
you shouldn't be using tcscmp() (Hint: are either MY_FS_TYPE or m-mnt_type
allowed to be UTF-8 strings? :)

 rename(newFileName, fileName))
 rc = 0;

You probaby want to check the return code:

rc = rename(newFileName, fileName);
if (!rc) { perror() or something

as you're *very* likely to get EXDEV as an error due to previous code.

You're also missing error checking on every single endmntent() call - what
happens if one of those fails (which *can* happen)?

sync();

You don't want to do that.  You should have done an fsync() (except that's
technically wrong as you're mixing it with stdio and not setting it to
unbuffered) or a syncfs() instead.

return rc;

This fails to capture a number of potential errors.



pgpvij8kG0aVH.pgp
Description: PGP signature
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: hook SIGSEGV

2014-05-14 Thread Max Filippov
On Wed, May 14, 2014 at 4:14 PM, Kristof Provost kris...@sigsegv.be wrote:
 On 2014-05-10 21:46:01 (+0800), net.study@gmail.com 
 net.study@gmail.com wrote:
  I want to know is it possible to hook SIGSEGV to restart the
  thread which the signal is sent to,without restart the whole
  process? And record the place where has caused this signal?

 Yes, as others have already pointed out, you can hook SIGSEGV like any
 other signal.

 You're not going to be able to save the process any more, but you can
 still collect some useful information.

 I've found it very useful to have a SIGSEGV (and SIGPIPE, SIGABRT,
 SIGFPE, SIGILL) handler which logs a backtrace (look at 'man backtrace')
 to syslog. Very useful for debugging on targets where core dumps are
 impractical.

 Others have also pointed out that it might no longer be safe to call
 printf() or malloc() there. That's true, but usually it's OK, and if it
 turns out that it wasn't ... Well, you were crashing anyway.

Well, not anyway: you still should be able to take a longjmp out of the
signal handler to a safe place.

-- 
Thanks.
-- Max

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


Re: confused kernel compressed code link address

2014-05-14 Thread Chuck Huang
hi Arn Ks,

thx for your reply.

So there is no global variables during the decompress process of kernel.

best regards

2014-05-12 14:06 GMT+08:00 Arun KS getaru...@gmail.com:
 Hi Chuck Huang,

 On Thu, May 8, 2014 at 5:25 PM, Chuck Huang chuck.ker...@gmail.com wrote:
 Dear all,

 Now i am looking into kernel decompressed code, 
 arch/arm/boot/compressed/head.S

 As i objdump arch/arm/boot/compressed/vmlinux, the start section address is 
 0x0.

 vmlinux.S
 373789| Disassembly of section .text:
 373790|
 373791|  start:
 373792| #endif

 if the code run in 0x8000 (which is DDR base address), but the
 link address is zero, how it works ?

 The compressed/head.S code is position independent code. It can be
 loaded anywhere in RAM.
 There will not be reference to any labels directly. All the address
 references are done relative to PC.

 Thanks,
 Arun

 best regards

 ___
 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


packet drop

2014-05-14 Thread Varun Sharma
Hi All,

I am sending packet between two back to back connected machine.when I
use same network (192.168.7.x) packet reach upto NF_IP_LOCAL_IN
(IPTABLES INPUT) hook.It is accepted.

But when I spoof ip address network(192.168.8.x) it pass
NF_IP_PRE_ROUTING hook but dropped before NF_IP_LOCAL_IN hook.

case 1:

192.168.7.12 -- 192.168.7.19 Accepted.

case 2:

 192.168.8.25 -- 192.168.7.19   Dropped.

I didn't get why it dropped ? How network change effect on routing
inside kernel tcp/ip stack ?

Regards
Varun

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