Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Setting up the signal stack in the handle_segv.c. #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

JagadeeshPagadala
Copy link

Hi Kaiwan, I am your student from HPE Bangalore, thought of providing some improvement with your permission.
Signed-off-by: Jagadeesh Pagadala [email protected]

Copy link
Collaborator

@kaiwan kaiwan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Jagadeesh, thanks for your pull request..
I've made small comments in your function, pl address them first.
Also, you'd have to complete the patch by actually invoking this func in ch12/handle_segv.c.
Of course, first pl ensure you test it. Thanks.

Jagadeesh Pagadala added 2 commits November 25, 2019 14:19
@JagadeeshPagadala
Copy link
Author

Addressing the review comments.

Signed-off-by: Jagadeesh Pagadala <[email protected]>
@@ -197,9 +200,17 @@ int main(int argc, char **argv)
exit(1);
}

/*Setting up the alternate stack to properly handle the SIGSEGV*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
just fix code style as per Linux kernel style guidelines
Tip- use 'indent -linux <fname.c>' to do so ..

@kaiwan
Copy link
Collaborator

kaiwan commented Nov 26, 2019

Marking this PR as open again..

@kaiwan kaiwan reopened this Nov 26, 2019
Copy link
Collaborator

@kaiwan kaiwan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Jagadeesh,
It looks good as such, But...
When i run the original ver, the faulting addr dtl etc is all fine, but with the new ver using alt stack it's not:

Eg. run: w/ orig ver:
ch12 $ ./handle_segv u r
Attempting to read contents of arbitrary usermode va uptr = 0xdeadface:
handle_segv:
------------------- FATAL signal ---------------------------
myfault: received signal 11. errno=0
Cause/Origin: (si_code=1): SEGV_MAPERR: address not mapped to object
Faulting instr or address = 0xdeadface
--- Register Dump [x86_64] ---
RAX = 0x00000000deadface RBX = 0x0000000000000000 RCX = 0x0000000000000000
RDX = 0x0000000000000000 RSI = 0x000055bdcda50260 RDI = 0x0000000000000001
RBP = 0x00007ffc4093cdb0 R8 = 0x0000000000000000 R9 = 0x0000000000000000
R10 = 0x0000000000000000 R11 = 0x0000000000000246 R12 = 0x000055bdcd19fc50
R13 = 0x00007ffc4093ce90 R14 = 0x0000000000000000 R15 = 0x0000000000000000
RSP = 0x00007ffc4093cce0

RIP = 0x000055bdcd1a03cb EFLAGS = 0x0000000000010206
TRAP# = 14 ERROR = 04
CR2 = 0x00000000deadface

psiginfo helper: Segmentation fault (Address not mapped to object [0xdeadface])

With the new ver w/ alt stack:
ch12 $ ./handle_segv u r
Alt signal stack size = 8388608
Attempting to read contents of arbitrary usermode va uptr = 0xdeadface:
handle_segv:
------------------- FATAL signal ---------------------------
myfault: received signal 11. errno=4
Cause/Origin: (si_code=8): -none-
Faulting instr or address = 0x7ffe4eff0b30
--- Register Dump [x86_64] ---
RAX = 0x00000000deadface RBX = 0x0000000000000000 RCX = 0x0000000000000000
RDX = 0x0000000000000000 RSI = 0x000055a5d4e7a260 RDI = 0x0000000000000001
RBP = 0x00007ffe4eff0c40 R8 = 0x0000000000000000 R9 = 0x0000000000000000
R10 = 0x0000000000000000 R11 = 0x0000000000000246 R12 = 0x000055a5d2fe7ca0
R13 = 0x00007ffe4eff0d20 R14 = 0x0000000000000000 R15 = 0x0000000000000000
RSP = 0x00007ffe4eff0b70

RIP = 0x000055a5d2fe852e EFLAGS = 0x0000000000010202
TRAP# = 14 ERROR = 04
CR2 = 0x00000000deadface

psiginfo helper: Unknown signal 1685382480

? Unsure why... but we can't merge this until it's fixed and works correctly.

@kaiwan
Copy link
Collaborator

kaiwan commented Nov 29, 2019

Pl ignore the extra bold fonts from "RIP" onward...

@JagadeeshPagadala
Copy link
Author

It is working fine on my CentOS box, and even on seawolf.
Below is the output I am seeing,
Any inputs on if anything else going wrong ?
seawolf@seawolf-VirtualBox:~/Hands-on-System-Programming-with-Linux/ch12$ git log | head
commit 3f706cb
Author: Jagadeesh Pagadala [email protected]
Date: Fri Nov 29 13:43:21 2019 +0530

Setting signal stack size to default size based on 64bit/32bit.

Signed-off-by: Jagadeesh Pagadala <[email protected]>

commit 4af72d5
Merge: c509a26 46cc856
seawolf@seawolf-VirtualBox:~/Hands-on-System-Programming-with-Linux/ch12$ ./handle_segv u r
Alt signal stack size = 8388608
Attempting to read contents of arbitrary usermode va uptr = 0xdeadface:
handle_segv:
------------------- FATAL signal ---------------------------
myfault: received signal 11. errno=0
Cause/Origin: (si_code=1): SEGV_MAPERR: address not mapped to object
Faulting instr or address = 0xdeadface
--- Register Dump [x86_64] ---
RAX = 0x00000000deadface RBX = 0x0000000000000000 RCX = 0x0000000000000000
RDX = 0x0000000000000000 RSI = 0x0000561af42b6260 RDI = 0x0000000000000001
RBP = 0x00007fff5a513460 R8 = 0x0000000000000000 R9 = 0x0000000000000000
R10 = 0x0000000000000000 R11 = 0x0000000000000246 R12 = 0x0000561af22ccca0
R13 = 0x00007fff5a513540 R14 = 0x0000000000000000 R15 = 0x0000000000000000
RSP = 0x00007fff5a513390

RIP = 0x0000561af22cd510 EFLAGS = 0x0000000000010206
TRAP# = 14 ERROR = 04
CR2 = 0x00000000deadface

psiginfo helper: Segmentation fault (Address not mapped to object [0xdeadface])

Segmentation fault (core dumped)
seawolf@seawolf-VirtualBox:~/Hands-on-System-Programming-with-Linux/ch12$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants