커널 드라이버에서 어플리케이션의 함수의 호출이 가능할까요?

leboum의 이미지

어플리케이션

int callcb = 0;
static void helloCB() {
    printf("helloCB\n");
    callcb = 1;
}
 
void main() {
    dev = open( DEVICE_FILENAME, O_RDWR | O_NDELAY );   
    if (dev >= 0)
    {
        void *pf  = (void*)helloCB;    
        ret = ioctl(dev, HELLO_CB , pf );
        close(dev)        
    }
 
    while (1) {
        if (callcb) {
           break;
        }
    }
}

드라이버

long Test_ioctl ( struct file *filp, unsigned int cmd, unsigned long arg) {   
    if ( cmd == HELLO_CB ) {
        void *pf = (void *)arg;
        ((void(*)(void))pf)();
    }
}
 

안녕하세요.

간단한 테스트 코드입니다.
보시는거와 같이 커널 드라이버에서 어플리케이션의 함수를 호출 하는게 목적입니다.
메모리 영역 자체가 달라서 호출이 불가능할것으로 보이는데,
혹시 이것을 가능게 하는... 해결 할수 있는 방법이 있을까요??
아님 저 방법이 아닌 다른 방법이 있는지 궁금합니다.

감사합니다.

행인의 이미지

copy_from_user

.의 이미지

메모리 영역이 다른 것이 아닙니다. 커널 모드인 이상 어플리케이션의 페이지 테이블을
찾아서 cr3 를 바꾸는 등 이상한 짓들을 하면 어떻게든 접근은 할 수 있습니다.

아니면 애초에 해당 커널 영역 코드가 어플리케이션에서 시스템 콜을 호출해서
실행된 것이라던가, ioctl 등으로 호출되었을 경우 위와 같은 짓을 안해도 기본적으로
그 어플리케이션의 페이지 테이블을 갖고 있기 때문에 그냥 접근할 수 있습니다.

다만 여기서 문제가 되는건 SMEP 같은 커널 보호 기법이 적용되어 있을 경우,
커널 모드에서 유저 영역의 코드를 실행할 수 없습니다.

.의 이미지

위에 말이 좀 이상했는데 ioctl 도 어쨌거나 시스템 콜이라서 통틀어서 말하면
특정 어플리케이션에서 시스템 콜을 호출해서 커널 모드로 전환되었다면
그 어플리케이션의 페이지 테이블을 그대로 갖고 있습니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.