Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

LINUX: Run the command: readelf -SW hello Using this output and your output from

ID: 3598058 • Letter: L

Question

LINUX: Run the command: readelf -SW hello

Using this output and your output from the hello program what are the memory access rights for the .text, .rodata, .data, and .bss sections?

output for readelf -SW hello:

hello.c file:

#include <stdio.h>

#include <sys/types.h>

#include <unistd.h>

#include <stdlib.h>

char bye[] = "Goodbye world.";

int unused;

void numbers() {

int i;

for (i = 0; i < 10; ++i) {

printf("%d ", i);

}

}

int main(void) {

pid_t pid;

char mem[64];

puts("Hello rshe001!");

numbers();

pid = getpid();

sprintf(mem, "cat /proc/%d/maps", pid);

system(mem);

puts(bye);

return 0;

}

408 readelf -SW hello 409 There are 31 section headers, starting at offset 0xlb40: 411 Section Headers: 412 [Nr] Name Address off Size ES Flg Lk Inf Al NULL PROGBITS 415 416 2] note.ABI-tag NOTE 3] .note.gnu.build-id NOTE 4 000000000040027400027400002400 A 4 00000000004002980002980000|C00 A 5 8 00000000004002b8 0002b8 0000d8 18 A 6 1 8 nu.hash GNU HASH DYNSYM STRTAB VERSYM VERNEED RELA RELA PROGBITS PROGBITS PROGBITS PROGBITS PROGBITS PROGBITS 420 I 7] .gnu.version 00000000004003fe0003fe 00001202 A 5 2 421 8] .gnu.version_r VE 9] .rela.dyn [10] .rela.plt 0000000000400458 000458 0000a8 18 AI 5 24 8 0 427 [14].text 428 [15] .fini 429 [16] .rodata 430 [17] .eh frame hdrPROGBITS 00000000004008@c 008@c 003c A 4 181 .eh frame PROGBITS INIT_ARRAY FINI ARRAY PROGBITS DYNAMIC PROGBITS PROGBITS PROGBITS NOBITS PROGBITS STRTAB SYMTAB STRTAB 432 [19] .init array 433 [20] .fini array 434 435 [22] .dynamic 436 [23] .got 0000000000600ff8000ff8 00000808 WA 8 0 0000000000601050001050 00001f00 WA 8 438 [25] .data 439 [26] .bss 27] .comment 00000000000000000106f00003401 MS 1 441 [28] .shstrtab 442 [29] .symtab 443[30] .strtab 444 Key to Flags: 445 W (write), A (alloc),X (execute), M (merge), S (strings), (large) 446 I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown) 447 0 (extra oS processing required) o (OS specific), p (processor specific)

Explanation / Answer

ELF : Execuatble and Linkable Format.

Here from the data you gives Flag indicates the memory access permission :

W says it is writable, X says it is executable, A - says that the segment must be allocated memory.

.text : flg says AX ie., it needs to be allocated memory at adress memtioned and it is an executable.

.rodata : flag says A ie., it should be allocated memory and it is neither writable nor executable.

.data : flag says WA ie., it should be allocated memory and it is writable.

.bss : flag says WA ie., it should be allocated memory and it is writable.

/* hope this helps */

/* if any queries please comment */

/* thank you*/