file operations table 질문

익명 사용자의 이미지

filep_open 함수를 통해서 파일을 열게되면,

struct file* 가 리턴됩니다.

그리고 file -> f_op 로 operation 테이블을 통해서 read나 write와 같은 함수들에 접근할 수 있습니다.

여기서 궁금한 점이 있는데요.

filep_open("1.txt")의 결과 값을 통한 operation table의 read와

filep_open("2.txt")의 결과 값을 통한 operation table의 read는 같은지 궁금합니다.

만약에 같다면.. 하나의 read만 후킹하면 모든 파일에 가능해지고

아닐 경우 특정 파일만 타겟지어서 진행할 것 같습니다.

만약에 같다면 모든 파일마다 고유한 operation table이 존재하는지....

궁금합니다.

12의 이미지

파일시스템이 제공하는 inode 에 대한 operation 입니다.
file.f_ops 를 바꾸면 그 파일에만 적용되지만 file.f_ops.read 를 바꾸면 그 파일 시스템에 있는 regular file 모두에 대해 적용됩니다.

질문올린사람입니다.의 이미지

먼저 답변에 감사드립니다.

실제로
pfile = filp_open(path, O_RDONLY, 0);
if(pfile == NULL){
return 0x11;
}

addr = pfile->f_op->iterate;

같은 코드를 통해서 루트 / 폴더와 /proc 폴더의 주소를 출력해보면 같은 주소였습니다.

하지만 제가 인터넷에서 돌아다니며 찾은 코드 중 많은 코드들이 각 파일마다 후킹해주고 있었습니다...

/*인터넷에서 퍼온 부분*/
o_root_readdir = get_readdir("/");
save_it(o_root_readdir,rooty_root_readdir);
jack_it(o_root_readdir);


o_proc_readdir = get_readdir("/proc");
save_it(o_proc_readdir,rooty_proc_readdir);
jack_it(o_proc_readdir);
/*--------------*/

위와 같이 한 이유가 뭘까요.. 그러면..

file.f_ops 질문의 이미지

답변을 받고 간단히 확인한느 코드로 돌려보았습니다.

[36980.736829] /home/nkk file_operation pointer :c1717f00
[36980.736835] /home file_operation pointer :c1717f00
[36980.736840] / file_operation pointer :c1717f00

돌려 본 결과 위와 같이 주소가모두 같게 나왔습니다.

printk("%s file_operation pointer :%p\n",path, pfile->f_op);
printk("/home file_operation pointer :%p\n", pfile2->f_op);
와 같은 형식으로 출력했습니다.
ㅠㅠ 헷갈립니다.

익명 사용자의 이미지

딱히 헷갈릴게 없는데... 혹시 포인터 아직 잘 모르시나요.

같은 파일시스템의 같은 종류의 inode 는 모두 f_ops 의 주소가 같습니다. 그러니 그 멤버인 .read 도 같죠.
빈 f_ops 를 만들고 기존의 file.f_ops 를 거기다 복사하시고 f_ops.read 를 본인 것으로 바꾼다음에 기존의 file.f_ops 를 변조된 f_ops 로 교체하세요.

익명 사용자의 이미지

아.. 다른 파일 시스템이나 다른 종류의 파일이라하더라도 f_ops 나 f_ops.read 가 같을 수 있습니다.
gereric file_operation 나 generic read 같은 것을 활용할 수도 있습니다.

익명 사용자의 이미지

아.. 다른 파일 시스템이나 다른 종류의 파일이라하더라도 f_ops 나 f_ops.read 가 같을 수 있습니다.
gereric file_operation 나 generic read 같은 것을 활용할 수도 있습니다.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.