Task란?
다소 검색을 해봤는데 그 의미가 모호한 것 같다.
태스크를 태스크라고도 하고, 스레드라고도하고 프로세스라고 표현한다고 하는데...
지금 공부하고 있는 시점에서는 크게 중요하지 않은 것 같다.
결국은 태스크는 작업 실행 단위를 이야기한다.
task_struct란?
결국 모든 태스크들은 task_struct 구조체를 통해 관리하게 된다.
태스크 또는 스레드가 생성되면 do_fork()라는 커널 함수를 거치면서 이 task_struct를 생성하는데,
이 때 권한이나 주소 등을 task_struct 구조체에 넣어두게 된다.
즉, fork(), vfork(), pthread_create() 등의 함수를 어플리케이션에서 실행하면 라이브러리에서 해당 함수를 찾아 실행하며,
라이브러리에서는 다시 clone(), vfork() 등의 시스템콜을 하며,
커널에서는 sys_clone(), sys_vfork(), sys_fork()를 실행하고
결론적으로 do_fork() 함수를 실행하게 되며, 해당 함수 내에서 task_struct를 생성한다.
task_struct의 구조
모두 다 설명하고 이해하려면 너무 많으니, 중요한 부분만 보자.
아래는 전체 코드이다.
cs.fsu.edu/~baker/opsys/examples/task_struct.html
https://www.cs.fsu.edu/~baker/opsys/examples/task_struct.html
www.cs.fsu.edu
struct mm_struct *mm
해당 부분이 위에서 이야기한 각 주소를 관리하는 영역이다.
이 구조체 내에서 stack, heap, bss, code 등의 영역을 관리한다.
아래 소스코드를 참고하자.
mm_types.h - include/linux/mm_types.h - Linux source code (v6.4.8) - Bootlin
mm_types.h - include/linux/mm_types.h - Linux source code (v6.4.8) - Bootlin
/* SPDX-License-Identifier: GPL-2.0 */ #ifndef _LINUX_MM_TYPES_H #define _LINUX_MM_TYPES_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef AT_V
elixir.bootlin.com
struct cred
권한을 관리하는 구조체로 kernel exploit에서 가장 중요한 부분이지 않나 싶다.
통상적으로 id가 0이면 root이며, kernel exploit에서는 이 부분을 0으로 만드는 것을 목표로 한다.
cred.h - include/linux/cred.h - Linux source code (v6.4.8) - Bootlin
cred.h - include/linux/cred.h - Linux source code (v6.4.8) - Bootlin
/* SPDX-License-Identifier: GPL-2.0-or-later */ /* Credentials management - see Documentation/security/credentials.rst * * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com) */ #ifndef _LINUX_CRED_H #defi
elixir.bootlin.com
'Kernel Exploit' 카테고리의 다른 글
| Kernel exploit - 모듈 프로그래밍 (0) | 2023.08.06 |
|---|---|
| Kernel exploit - 디바이스 드라이버 (0) | 2023.08.06 |
| Kernel exploit - 슬랩 할당자 (0) | 2023.08.06 |
| Kernel exploit - 커널이란 (0) | 2023.08.05 |
| Kernel exploit - 들어가며. (0) | 2023.08.05 |