Stack Debugging. Young W. Lim Thr. Young W. Lim Stack Debugging Thr 1 / 12

Similar documents
Stack Tutorial. Young W. Lim Sat. Young W. Lim Stack Tutorial Sat 1 / 15

Stack Debugging. Young W. Lim Sat. Young W. Lim Stack Debugging Sat 1 / 40

Stack Debugging. Young W. Lim Mon. Young W. Lim Stack Debugging Mon 1 / 63

Stack Debugging. Young W. Lim Tue. Young W. Lim Stack Debugging Tue 1 / 70

GDB Tutorial. Young W. Lim Thr. Young W. Lim GDB Tutorial Thr 1 / 24

GDB Tutorial. Young W. Lim Fri. Young W. Lim GDB Tutorial Fri 1 / 24

GDB Tutorial. Young W. Lim Tue. Young W. Lim GDB Tutorial Tue 1 / 32

Stack Debugging. Young W. Lim Mon. Young W. Lim Stack Debugging Mon 1 / 77

Stack Debugging. Young W. Lim Fri. Young W. Lim Stack Debugging Fri 1 / 79

Stack Debugging. Young W. Lim Wed. Young W. Lim Stack Debugging Wed 1 / 84

Procedure Calls. Young W. Lim Mon. Young W. Lim Procedure Calls Mon 1 / 29

Day05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14

Stack Debugging. Young W. Lim Mon. Young W. Lim Stack Debugging Mon 1 / 90

Procedure Calls. Young W. Lim Sat. Young W. Lim Procedure Calls Sat 1 / 27

Day02 A. Young W. Lim Sat. Young W. Lim Day02 A Sat 1 / 12

Day06 A. Young W. Lim Wed. Young W. Lim Day06 A Wed 1 / 26

Access. Young W. Lim Fri. Young W. Lim Access Fri 1 / 18

Access. Young W. Lim Sat. Young W. Lim Access Sat 1 / 19

Link 7. Dynamic Linking

Day08 A. Young W. Lim Mon. Young W. Lim Day08 A Mon 1 / 27

Link 7.A Static Linking

Day06 A. Young W. Lim Mon. Young W. Lim Day06 A Mon 1 / 16

Arrays. Young W. Lim Mon. Young W. Lim Arrays Mon 1 / 17

Link 2. Object Files

Link 3. Symbols. Young W. Lim Mon. Young W. Lim Link 3. Symbols Mon 1 / 42

Overview (1A) Young Won Lim 9/25/17

Arrays. Young W. Lim Wed. Young W. Lim Arrays Wed 1 / 19

Overview (1A) Young Won Lim 9/14/17

Link 4. Relocation. Young W. Lim Thr. Young W. Lim Link 4. Relocation Thr 1 / 26

Overview (1A) Young Won Lim 9/9/17

Link 4. Relocation. Young W. Lim Wed. Young W. Lim Link 4. Relocation Wed 1 / 22

Link 2. Object Files

Link 7. Static Linking

Link 8.A Dynamic Linking

Stack Debugging. Young W. Lim Young W. Lim Stack Debugging / 96

Day14 A. Young W. Lim Thr. Young W. Lim Day14 A Thr 1 / 14

Day21 A. Young W. Lim Wed. Young W. Lim Day21 A Wed 1 / 13

Control. Young W. Lim Mon. Young W. Lim Control Mon 1 / 16

HyperGeometric Distribution

Accessibility (1A) Young Won Lim 8/22/13

GAS Tutorial - 6. Expression

2. HW/SW Co-design. Young W. Lim Thr. Young W. Lim 2. HW/SW Co-design Thr 1 / 21

Day14 A. Young W. Lim Tue. Young W. Lim Day14 A Tue 1 / 15

GAS Tutorial - 4. Sections & Relocation

Link 8. Dynamic Linking

Algorithms Bubble Sort (1B) Young Won Lim 4/5/18

Logic Haskell Exercises

Simple C Program. Assembly Ouput. Using GCC to produce Assembly. Assembly produced by GCC is easy to recognize:

Function Overview (1A) Young Won Lim 10/23/17

Illustration of the problem

Class (1A) Young Won Lim 9/8/14

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm

ENCM 501 Winter 2017 Assignment 6 for the Week of February 27

Linux Capabilities & Set-UID Vulnerability

Memory Management. Fundamentally two related, but distinct, issues. Management of logical address space resource

A heap, a stack, a bottle and a rack. Johan Montelius HT2017

Processes. Johan Montelius KTH

Praktische Aspekte der Informatik

A process. the stack

Fall 2015 COMP Operating Systems. Lab #3

United States Naval Academy Electrical and Computer Engineering Department EC312-6 Week Midterm Spring 2016

Example 1. Young Won Lim 11/17/17

Programming the DMCC in C

Example 1 : using 1-d arrays. Young Won Lim 12/13/17

HW / SW Implementation Overview (0A) Young Won Lim 7/16/16

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

Example 2. Young Won Lim 11/24/17

Pointers (1A) Young Won Lim 1/9/18

Pointers (1A) Young Won Lim 1/5/18

CSC 591 Systems Attacks and Defenses Return-into-libc & ROP

Isolating and Locating Cause-Effect Chains. bug.c. What is the cause of this failure? What do we do now? Andreas Zeller

Example 3 : using a structure array. Young Won Lim 11/25/17

Process Migration. David Zuercher CS555 Distributed Systems

ECE 471 Embedded Systems Lecture 4

unsigned char memory[] STACK ¼ 0x xC of address space globals function KERNEL code local variables

518 Lecture Notes Week 3

Memory Management. a C view. Dr Alun Moon KF5010. Computer Science. Dr Alun Moon (Computer Science) Memory Management KF / 24

PROCESSES. Jo, Heeseung

Processes. Jo, Heeseung

Symbols, Compilation Units, and Pre-Processing

Operating systems and concurrency - B03

COL100 Lab 2. I semester Week 2, Open the web-browser and visit the page and visit the COL100 course page.

Preview. Process Control. What is process? Process identifier The fork() System Call File Sharing Race Condition. COSC350 System Software, Fall

Pointers (1A) Young Won Lim 1/14/18

CSC 1600 Unix Processes. Goals of This Lecture

On the effectiveness of Full-ASLR on 64-bit Linux

Pointers (1A) Young Won Lim 3/5/18

CS C Primer. Tyler Szepesi. January 16, 2013

Pointers (1A) Young Won Lim 11/1/17

Computer Systems Assignment 2: Fork and Threads Package

CS240: Programming in C

Example 3. Young Won Lim 11/22/17

Network Socket Programming - 1 BUPT/QMUL

CSci 4061 Introduction to Operating Systems. Processes in C/Unix

ECE264 Summer 2013 Exam 1, June 20, 2013

Problem Set 1: Unix Commands 1

CS241 Computer Organization Spring Data Alignment

Eclipse CDT Tutorial. Eclipse CDT Homepage: Tutorial written by: James D Aniello

Link Edits and Relocatable Code

Project 1 Notes and Demo

Transcription:

Stack Debugging Young W. Lim 2017-07-13 Thr Young W. Lim Stack Debugging 2017-07-13 Thr 1 / 12

Outline 1 Introduction References Compiling to IA32 Assembly Checking /proc/<pid>/maps file Young W. Lim Stack Debugging 2017-07-13 Thr 2 / 12

Based on "Self-service Linux: Mastering the Art of Problem Determination", Mark Wilding "Computer Architecture: A Programmer s Perspective", Bryant & O Hallaron I, the copyright holder of this work, hereby publish it under the following licenses: GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License. CC BY SA This file is licensed under the Creative Commons Attribution ShareAlike 3.0 Unported License. In short: you are free to share and make derivative works of the file under the conditions that you appropriately attribute it, and that you distribute it only under a license compatible with this one. Young W. Lim Stack Debugging 2017-07-13 Thr 3 / 12

preparation : for Linux Mint install packages lib32gcc1 lib32gcc-dbg gcc-multilib gcc -m32 t.c Young W. Lim Stack Debugging 2017-07-13 Thr 4 / 12

stack frame address range stack frame starts from 0xc0000000 stack bottom : 0xc0000000 stack address range 0xbfffe000 (low address) 0xc0000000 (high address) stack grows toward lower address from high address to low address from 0xc0000000 to 0xbfffe000 Young W. Lim Stack Debugging 2017-07-13 Thr 5 / 12

stack frame in the Linux Mint stack address range 0xbfffe000 (low address) 0xc0000000 (high address) 0x00002000 stack address range in the Linux Mint 0xfffa8000 (low address) 0xfffc9000 (high address) 0x00021000 Young W. Lim Stack Debugging 2017-07-13 Thr 6 / 12

code for displaying /proc/pid/maps local variables (stack variables) : stack_var local variable address : 0xfffc77e8 #include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> int main(void) { int stack_var = 5; char cmd[64]; printf("addr(stack_var) = 0x%p \n\n", &stack_var); sprintf(cmd, "cat /proc/%d/maps", getpid()); system(cmd); } return 0; Young W. Lim Stack Debugging 2017-07-13 Thr 7 / 12

/proc/<pid>/maps file result addr(stack_var) = 0xfffc77e8 08048000-08049000 r-xp 00000000 08:51 424080 /home/young/a.out 08049000-0804a000 r--p 00000000 08:51 424080 /home/young/a.out 0804a000-0804b000 rw-p 00001000 08:51 424080 /home/young/a.out 0876d000-0878e000 rw-p 00000000 00:00 0 [heap] f756a000-f756b000 rw-p 00000000 00:00 0 f756b000-f7718000 r-xp 00000000 08:51 1475199 /lib32/libc-2.23.so f7718000-f7719000 ---p 001ad000 08:51 1475199 /lib32/libc-2.23.so f7719000-f771b000 r--p 001ad000 08:51 1475199 /lib32/libc-2.23.so f771b000-f771c000 rw-p 001af000 08:51 1475199 /lib32/libc-2.23.so f771c000-f7720000 rw-p 00000000 00:00 0 f773d000-f773f000 r--p 00000000 00:00 0 [vvar] f773f000-f7741000 r-xp 00000000 00:00 0 [vdso] f7741000-f7763000 r-xp 00000000 08:51 1475178 /lib32/ld-2.23.so f7763000-f7764000 rw-p 00000000 00:00 0 f7764000-f7765000 r--p 00022000 08:51 1475178 /lib32/ld-2.23.so f7765000-f7766000 rw-p 00023000 08:51 1475178 /lib32/ld-2.23.so fffa8000-fffc9000 rw-p 00000000 00:00 0 [stack] Young W. Lim Stack Debugging 2017-07-13 Thr 8 / 12

checking /proc/<pid>/maps file #inclde <stdio.h> int main(void) { int stack_var = 5; char cmd[64]; printf("&stack_var = 0x%x\n", &stack_var); printf("&argc = 0x%x\n", &argc ); printf(" argv = 0x%x\n", argv ); printf(" environ = 0x%xn", environ ); printf(" argv[0] = 0x%x\n", argv[0] ); printf("*environ = 0x%x\n", *environ ); sprintf(cmd, "cat /proc/%d/maps", getpid()); system(cmd); return 0; } Young W. Lim Stack Debugging 2017-07-13 Thr 9 / 12

checking /proc/<pid>/maps results &argc = 0xffabaf80 argv = 0xffabb014 environ = 0xffabb01c argv[0] = 0xffabc382 *environ = 0xffabc38a 08048000-08049000 r-xp 00000000 08:51 424080 /home/young/a.out 08049000-0804a000 r--p 00000000 08:51 424080 /home/young/a.out 0804a000-0804b000 rw-p 00001000 08:51 424080 /home/young/a.out 095b9000-095da000 rw-p 00000000 00:00 0 [heap] f7589000-f758a000 rw-p 00000000 00:00 0 f758a000-f7737000 r-xp 00000000 08:51 1475199 /lib32/libc-2.23.so f7737000-f7738000 ---p 001ad000 08:51 1475199 /lib32/libc-2.23.so f7738000-f773a000 r--p 001ad000 08:51 1475199 /lib32/libc-2.23.so f773a000-f773b000 rw-p 001af000 08:51 1475199 /lib32/libc-2.23.so f773b000-f773f000 rw-p 00000000 00:00 0 f775c000-f775e000 r--p 00000000 00:00 0 [vvar] f775e000-f7760000 r-xp 00000000 00:00 0 [vdso] f7760000-f7782000 r-xp 00000000 08:51 1475178 /lib32/ld-2.23.so f7782000-f7783000 rw-p 00000000 00:00 0 f7783000-f7784000 r--p 00022000 08:51 1475178 /lib32/ld-2.23.so f7784000-f7785000 rw-p 00023000 08:51 1475178 /lib32/ld-2.23.so ffa9c000-ffabd000 rw-p 00000000 00:00 0 [stack] Young W. Lim Stack Debugging 2017-07-13 Thr 10 / 12

checking /proc/<pid>/maps file (3) [from] 0xbfffe000 &stack_var 0xbffff2dc --- stack top &argc 0xbffff2f0 argv 0xbffff334 environ 0xbffff33c argv[0] 0xbffff4d5 *environ 0xbffff4de (low address) [to] 0xc0000000 --- stack bottom (high address) Young W. Lim Stack Debugging 2017-07-13 Thr 11 / 12

checking /proc/<pid>/maps file (4) [to] 0xc0000000 stack bottom (high address) path name specified in exec() process environment variables argv strings argc aux vectors [from] 0xbfffe000 Young W. Lim Stack Debugging 2017-07-13 Thr 12 / 12